gpt

package
v0.23.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultChatStream           = false
	DefaultChatMaxTokens        = 4096
	DefaultChatFrequencyPenalty = 0
	DefaultChatPresencePenalty  = 0
	DefaultChatTemperature      = 1
	DefaultChatTopP             = 0.7
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatChoice added in v0.12.0

type ChatChoice struct {
	Message ChatMessage `json:"message"`
}

type ChatMessage added in v0.12.0

type ChatMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type ChatRequest added in v0.13.0

type ChatRequest struct {
	Model            string        `json:"model"`
	Messages         []ChatMessage `json:"messages"`
	Stream           bool          `json:"stream"`
	MaxTokens        int64         `json:"max_tokens"`
	FrequencyPenalty float64       `json:"frequency_penalty"`
	PresencePenalty  float64       `json:"presence_penalty"`
	Temperature      float64       `json:"temperature"`
	TopP             float64       `json:"top_p"`
}

type ChatResponse added in v0.12.0

type ChatResponse struct {
	Id      string       `json:"id"`
	Choices []ChatChoice `json:"choices"`
}

type Config

type Config struct {
	Provider string
	Api      string
	Model    string
	Key      string
}

func DefaultConfig

func DefaultConfig() *Config

type DoubaoChat added in v0.12.0

type DoubaoChat struct {
	Api   string
	Model string
	Key   string
}

func (*DoubaoChat) Chat added in v0.13.0

func (c *DoubaoChat) Chat(_ context.Context, request *ChatRequest) (ChatResponse, error)

func (*DoubaoChat) Deinit added in v0.12.0

func (c *DoubaoChat) Deinit(_ context.Context) error

func (*DoubaoChat) Init added in v0.12.0

func (c *DoubaoChat) Init(_ context.Context) error

type DoubaoChatChoice added in v0.13.0

type DoubaoChatChoice struct {
	Index        int                `json:"index"`
	FinishReason string             `json:"finish_reason"`
	Message      DoubaoChatMessage  `json:"message"`
	Logprobs     DoubaoChatLogprobs `json:"logprobs"`
}

type DoubaoChatFunction added in v0.13.0

type DoubaoChatFunction struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

type DoubaoChatLogprobs added in v0.13.0

type DoubaoChatLogprobs struct {
	Content []DoubaoChatTokenLogprob `json:"content"`
}

type DoubaoChatMessage added in v0.13.0

type DoubaoChatMessage struct {
	Role      string               `json:"role"`
	Content   string               `json:"content"`
	ToolCalls []DoubaoChatToolCall `json:"tool_calls"`
}

type DoubaoChatPromptTokensDetails added in v0.13.0

type DoubaoChatPromptTokensDetails struct {
	CachedTokens int `json:"cached_tokens"`
}

type DoubaoChatResponse added in v0.13.0

type DoubaoChatResponse struct {
	Id      string             `json:"id"`
	Model   string             `json:"model"`
	Created int64              `json:"created"`
	Object  string             `json:"object"`
	Choices []DoubaoChatChoice `json:"choices"`
	Usage   DoubaoChatUsage    `json:"usage"`
}

type DoubaoChatTokenLogprob added in v0.13.0

type DoubaoChatTokenLogprob struct {
	Token       string                 `json:"token"`
	Bytes       []int                  `json:"bytes"`
	Logprob     float64                `json:"logprob"`
	TopLogprobs []DoubaoChatTopLogprob `json:"top_logprobs"`
}

type DoubaoChatToolCall added in v0.13.0

type DoubaoChatToolCall struct {
	Id       string             `json:"id"`
	Type     string             `json:"type"`
	Function DoubaoChatFunction `json:"function"`
}

type DoubaoChatTopLogprob added in v0.13.0

type DoubaoChatTopLogprob struct {
	Token   string  `json:"token"`
	Bytes   []int   `json:"bytes"`
	Logprob float64 `json:"logprob"`
}

type DoubaoChatUsage added in v0.13.0

type DoubaoChatUsage struct {
	PromptTokens        int                           `json:"prompt_tokens"`
	CompletionTokens    int                           `json:"completion_tokens"`
	TotalTokens         int                           `json:"total_tokens"`
	PromptTokensDetails DoubaoChatPromptTokensDetails `json:"prompt_tokens_details"`
}

type Gpt

type Gpt interface {
	Init(context.Context) error
	Deinit(context.Context) error
	Chat(context.Context, *ChatRequest) (ChatResponse, error)
}

func New

func New(_ context.Context, cfg *Config) Gpt

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL