Documentation ¶
Overview ¶
@Author xiaozhaofu 2023/8/15 11:02:00
Index ¶
- Constants
- func GenerateToken(apiKey string, duration time.Duration) (string, error)
- type APIError
- type ChatCompletion
- type ChatCompletionChoice
- type ChatCompletionMessage
- type ChatCompletionRequest
- type ChatCompletionResponse
- type ChatCompletionStreamChoice
- type ChatCompletionStreamChoiceDelta
- type ChatglmCompletionResponse
- type Client
- type ClientConfig
- type ErrorResponse
- type Event
- type GlmChatCompletionStream
- type GlmChatCompletionStreamResponse
- type GlmMeta
- type RequestError
- type StreamReaderInterface
- type Usage
- type ZpClaims
Constants ¶
View Source
const ( ChatMessageRoleSystem = "system" ChatMessageRoleUser = "user" ChatMessageRoleAssistant = "assistant" )
Chat message role defined by the OpenAI API.
View Source
const (
DEFULTTIMES = 12
)
View Source
const (
Turbo = "chatglm_turbo"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type APIError ¶
type APIError struct { Code any `json:"code,omitempty"` Message string `json:"message"` Param *string `json:"param,omitempty"` Type string `json:"type"` HTTPStatusCode int `json:"-"` }
APIError provides error information returned by the OpenAI API. InnerError struct is only valid for Azure OpenAI Service.
func (*APIError) UnmarshalJSON ¶
type ChatCompletion ¶ added in v1.0.2
type ChatCompletion[T ChatCompletionRequest] interface { CreateChatCompletionStream(ctx context.Context, request T) (stream *GlmChatCompletionStream, err error) CreateChatCompletion(ctx context.Context, request T) (response ChatCompletionResponse, err error) // contains filtered or unexported methods }
func NewClient ¶
func NewClient(authToken string) ChatCompletion[ChatCompletionRequest]
func NewClientWithConfig ¶
func NewClientWithConfig(config ClientConfig) ChatCompletion[ChatCompletionRequest]
type ChatCompletionChoice ¶
type ChatCompletionChoice struct {
Message ChatCompletionMessage `json:"message"`
}
type ChatCompletionMessage ¶
type ChatCompletionRequest ¶
type ChatCompletionRequest struct { Model string `json:"model"` // 模型 Messages []ChatCompletionMessage `json:"prompt"` // prompt Temperature float32 `json:"temperature,omitempty"` TopP float32 `json:"top_p,omitempty"` // 智谱 SSE接口调用时,用于控制每次返回内容方式是增量还是全量,不提供此参数时默认为增量返回 - true 为增量返回 - false 为全量返回 Incremental bool `json:"incremental"` }
ChatCompletionRequest 请求模型参数.
type ChatCompletionResponse ¶
type ChatCompletionResponse struct { ID string `json:"id"` Object string `json:"object,omitempty"` Created int64 `json:"created"` Model string `json:"model"` Choices []ChatCompletionChoice `json:"choices"` Usage Usage `json:"usage,omitempty"` }
ChatCompletionResponse represents a response structure for chat completion API.
type ChatCompletionStreamChoice ¶
type ChatCompletionStreamChoice struct {
Delta ChatCompletionStreamChoiceDelta `json:"delta"`
}
type ChatglmCompletionResponse ¶
type ChatglmCompletionResponse struct { Code int `json:"code"` Msg string `json:"msg"` Data struct { RequestID string `json:"request_id"` TaskID string `json:"task_id"` TaskStatus string `json:"task_status"` Choices []ChatCompletionMessage `json:"choices"` Usage struct { TotalTokens int `json:"total_tokens"` } `json:"usage"` } `json:"data"` Success bool `json:"success"` }
ChatglmCompletionResponse Api文本返回.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) CreateChatCompletion ¶
func (c *Client) CreateChatCompletion( ctx context.Context, request ChatCompletionRequest, ) (response ChatCompletionResponse, err error)
CreateChatCompletion — API call to Create a completion for the chat message.
func (*Client) CreateChatCompletionStream ¶
func (c *Client) CreateChatCompletionStream( ctx context.Context, request ChatCompletionRequest, ) (*GlmChatCompletionStream, error)
type ClientConfig ¶
type ClientConfig struct { BaseURL string HTTPClient *http.Client // contains filtered or unexported fields }
ClientConfig is a configuration of a client.
func DefaultConfig ¶
func DefaultConfig(authToken string) ClientConfig
func (ClientConfig) String ¶
func (ClientConfig) String() string
type ErrorResponse ¶
type ErrorResponse struct {
Error *APIError `json:"error,omitempty"`
}
type GlmChatCompletionStream ¶
type GlmChatCompletionStream struct {
// contains filtered or unexported fields
}
type GlmChatCompletionStreamResponse ¶ added in v1.0.2
type GlmChatCompletionStreamResponse struct { ID string `json:"id"` Event string `json:"event"` Choices []ChatCompletionStreamChoice `json:"choices"` Meta GlmMeta `json:"meta"` }
type RequestError ¶
RequestError provides informations about generic request errors.
func (*RequestError) Error ¶
func (e *RequestError) Error() string
func (*RequestError) Unwrap ¶
func (e *RequestError) Unwrap() error
type StreamReaderInterface ¶ added in v1.0.2
type StreamReaderInterface[T streamable] interface { Recv() (response T, err error) Close() // contains filtered or unexported methods }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.