Documentation ¶
Index ¶
- Constants
- func ResponseToError(resp *httpx.Response) error
- type ChatCompletionsFinishReason
- type ChatCompletionsMessage
- type ChatCompletionsMessageRole
- type ChatCompletionsModelID
- type ChatCompletionsRequest
- type ChatCompletionsResponse
- type ChatCompletionsResponseChoices
- type ChatCompletionsResponseUsage
- type ChatCompletionsStreamResponse
- type ChatCompletionsStreamResponseReceive
- type Client
- type CommonAPIResponse
- type CommonAPIResponseError
- type CommonResponse
- type Config
- type FileContentResponse
- type FilesBatchDeleteRequest
- type FilesBatchDeleteResponse
- type FilesDeleteResponse
- type FilesInfoResponse
- type FilesListRequest
- type FilesListResponse
- type FilesListResponseData
- type FilesPurpose
- type FilesUploadBytesRequest
- type FilesUploadBytesResponse
- type FilesUploadRequest
- type FilesUploadResponse
- type IChat
- type IChatCompletionsBuilder
- type IFiles
- type IModels
- type ITokenizers
- type IUsers
- type ListModelResponseData
- type ListModelsRequest
- type ListModelsResponse
- type ListModelsResponseDataPermission
- type Option
- type TokenizersEstimateTokenCountRequest
- type TokenizersEstimateTokenCountResponse
- type TokenizersEstimateTokenCountResponseData
- type UsersBalanceResponse
- type UsersBalanceResponseData
Constants ¶
View Source
const DefaultHost = "https://api.moonshot.cn"
Variables ¶
This section is empty.
Functions ¶
func ResponseToError ¶ added in v0.4.1
ResponseToError bind and return error from response
Types ¶
type ChatCompletionsFinishReason ¶
type ChatCompletionsFinishReason string
const ( FinishReasonStop ChatCompletionsFinishReason = "stop" FinishReasonLength ChatCompletionsFinishReason = "length" )
func (ChatCompletionsFinishReason) String ¶ added in v0.4.0
func (c ChatCompletionsFinishReason) String() string
type ChatCompletionsMessage ¶
type ChatCompletionsMessage struct { Role ChatCompletionsMessageRole `json:"role"` Content string `json:"content"` }
type ChatCompletionsMessageRole ¶
type ChatCompletionsMessageRole string
const ( RoleSystem ChatCompletionsMessageRole = "system" RoleUser ChatCompletionsMessageRole = "user" RoleAssistant ChatCompletionsMessageRole = "assistant" )
func (ChatCompletionsMessageRole) String ¶ added in v0.4.0
func (c ChatCompletionsMessageRole) String() string
type ChatCompletionsModelID ¶
type ChatCompletionsModelID string
const ( ModelMoonshotV18K ChatCompletionsModelID = "moonshot-v1-8k" ModelMoonshotV132K ChatCompletionsModelID = "moonshot-v1-32k" ModelMoonshotV1128K ChatCompletionsModelID = "moonshot-v1-128k" )
func (ChatCompletionsModelID) String ¶ added in v0.4.0
func (c ChatCompletionsModelID) String() string
type ChatCompletionsRequest ¶
type ChatCompletionsRequest struct { Messages []*ChatCompletionsMessage `json:"messages"` Model ChatCompletionsModelID `json:"model"` MaxTokens int `json:"max_tokens"` Temperature float64 `json:"temperature"` TopP float64 `json:"top_p"` N int `json:"n"` PresencePenalty float64 `json:"presence_penalty"` FrequencyPenalty float64 `json:"frequency_penalty"` Stop []string `json:"stop"` Stream bool `json:"stream"` }
type ChatCompletionsResponse ¶
type ChatCompletionsResponse struct { ID string `json:"id"` Object string `json:"object"` Created int `json:"created"` Model string `json:"model"` Choices []*ChatCompletionsResponseChoices `json:"choices"` Usage *ChatCompletionsResponseUsage `json:"usage"` }
type ChatCompletionsResponseChoices ¶
type ChatCompletionsResponseChoices struct { Index int `json:"index"` // return with no stream Message *ChatCompletionsMessage `json:"message,omitempty"` // return With stream Delta *ChatCompletionsMessage `json:"delta,omitempty"` FinishReason ChatCompletionsFinishReason `json:"finish_reason"` }
type ChatCompletionsStreamResponse ¶
type ChatCompletionsStreamResponse struct {
// contains filtered or unexported fields
}
func (*ChatCompletionsStreamResponse) Receive ¶ added in v0.2.0
func (c *ChatCompletionsStreamResponse) Receive() <-chan *ChatCompletionsStreamResponseReceive
Receive returns a channel to receive messages from the stream
type ChatCompletionsStreamResponseReceive ¶
type ChatCompletionsStreamResponseReceive struct { ChatCompletionsResponse // contains filtered or unexported fields }
func (*ChatCompletionsStreamResponseReceive) GetMessage ¶
func (c *ChatCompletionsStreamResponseReceive) GetMessage() (*ChatCompletionsMessage, error)
GetMessage returns the message from the stream
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClientWithConfig ¶
NewClientWithConfig creates a new client with a custom configuration
func (*Client) HTTPClient ¶
HTTPClient returns a new http client
func (*Client) Tokenizers ¶
func (c *Client) Tokenizers() ITokenizers
Tokenizers returns a new tokenizers controller
type CommonAPIResponse ¶
type CommonAPIResponse struct {
Error *CommonAPIResponseError `json:"error,omitempty"`
}
type CommonAPIResponseError ¶
type CommonResponse ¶
type CommonResponse struct { Code int `json:"code,omitempty"` Error string `json:"error,omitempty"` Message string `json:"message,omitempty"` Method string `json:"method,omitempty"` Scode string `json:"scode,omitempty"` Status bool `json:"status,omitempty"` UA string `json:"ua,omitempty"` URL string `json:"url,omitempty"` }
type FileContentResponse ¶
type FilesBatchDeleteRequest ¶ added in v0.3.0
type FilesBatchDeleteRequest struct {
FileIDList []string `json:"file_ids"`
}
type FilesBatchDeleteResponse ¶ added in v0.3.0
type FilesBatchDeleteResponse struct { RespList []*FilesDeleteResponse `json:"resp_list"` ErrorList []error `json:"error_list"` }
type FilesDeleteResponse ¶
type FilesInfoResponse ¶
type FilesListRequest ¶
type FilesListRequest struct { }
type FilesListResponse ¶
type FilesListResponse struct { Object string `json:"object"` Data []*FilesListResponseData `json:"data"` }
type FilesListResponseData ¶
type FilesPurpose ¶
type FilesPurpose string
const (
FilePurposeExtract FilesPurpose = "file-extract"
)
func (FilesPurpose) String ¶
func (f FilesPurpose) String() string
type FilesUploadBytesRequest ¶
type FilesUploadBytesRequest struct { Name string Bytes []byte Purpose FilesPurpose }
type FilesUploadRequest ¶
type FilesUploadRequest struct { Name string Path string Purpose FilesPurpose }
type FilesUploadResponse ¶
type IChat ¶ added in v0.3.0
type IChat interface { Completions(ctx context.Context, req *ChatCompletionsRequest) (*ChatCompletionsResponse, error) CompletionsStream(ctx context.Context, req *ChatCompletionsRequest) (*ChatCompletionsStreamResponse, error) }
type IChatCompletionsBuilder ¶ added in v0.4.1
type IChatCompletionsBuilder interface { AddUserContent(content string) IChatCompletionsBuilder AddSystemContent(content string) IChatCompletionsBuilder AddAssistantContent(content string) IChatCompletionsBuilder AddPrompt(prompt string) IChatCompletionsBuilder AddMessage(message *ChatCompletionsMessage) IChatCompletionsBuilder SetModel(model ChatCompletionsModelID) IChatCompletionsBuilder SetTemperature(temperature float64) IChatCompletionsBuilder SetStream(enable bool) IChatCompletionsBuilder SetMaxTokens(num int) IChatCompletionsBuilder SetTopP(num float64) IChatCompletionsBuilder SetN(num int) IChatCompletionsBuilder SetPresencePenalty(num float64) IChatCompletionsBuilder SetFrequencyPenalty(num float64) IChatCompletionsBuilder SetStop(stop []string) IChatCompletionsBuilder ToRequest() *ChatCompletionsRequest }
func NewChatCompletionsBuilder ¶ added in v0.4.1
func NewChatCompletionsBuilder(req ...ChatCompletionsRequest) IChatCompletionsBuilder
NewChatCompletionsBuilder creates a new chat completions builder, or with the given request
type IFiles ¶ added in v0.3.0
type IFiles interface { Upload(ctx context.Context, req *FilesUploadRequest) (resp *FilesUploadResponse, err error) UploadBytes(ctx context.Context, req *FilesUploadBytesRequest) (resp *FilesUploadBytesResponse, err error) List(ctx context.Context) (res *FilesListResponse, err error) Delete(ctx context.Context, fileID string) (resp *FilesDeleteResponse, err error) BatchDelete(ctx context.Context, req *FilesBatchDeleteRequest) (resp *FilesBatchDeleteResponse, err error) Info(ctx context.Context, fileID string) (resp *FilesInfoResponse, err error) Content(ctx context.Context, fileID string) (resp *FileContentResponse, err error) }
type IModels ¶ added in v0.3.0
type IModels interface {
List(ctx context.Context) (*ListModelsResponse, error)
}
type ITokenizers ¶ added in v0.3.0
type ITokenizers interface {
EstimateTokenCount(ctx context.Context, req *TokenizersEstimateTokenCountRequest) (resp *TokenizersEstimateTokenCountResponse, err error)
}
type IUsers ¶ added in v0.4.0
type IUsers interface {
Balance(ctx context.Context) (*UsersBalanceResponse, error)
}
type ListModelResponseData ¶
type ListModelsRequest ¶
type ListModelsRequest struct { }
type ListModelsResponse ¶
type ListModelsResponse struct { CommonResponse Object string `json:"object"` Data []*ListModelResponseData `json:"data"` }
type ListModelsResponseDataPermission ¶
type ListModelsResponseDataPermission struct { Created int `json:"created"` ID string `json:"id"` Object string `json:"object"` AllowCreateEngine bool `json:"allow_create_engine"` AllowSampling bool `json:"allow_sampling"` AllowLogprobs bool `json:"allow_logprobs"` AllowSearchIndices bool `json:"allow_search_indices"` AllowView bool `json:"allow_view"` AllowFineTuning bool `json:"allow_fine_tuning"` Organization string `json:"organization"` Group string `json:"group"` IsBlocking bool `json:"is_blocking"` }
type TokenizersEstimateTokenCountRequest ¶
type TokenizersEstimateTokenCountRequest struct { Model ChatCompletionsModelID `json:"model"` Messages []*ChatCompletionsMessage `json:"messages"` }
type TokenizersEstimateTokenCountResponse ¶
type TokenizersEstimateTokenCountResponse struct { CommonResponse Data *TokenizersEstimateTokenCountResponseData `json:"data"` }
type TokenizersEstimateTokenCountResponseData ¶
type TokenizersEstimateTokenCountResponseData struct {
TotalTokens int `json:"total_tokens"`
}
type UsersBalanceResponse ¶ added in v0.4.0
type UsersBalanceResponse struct { Code int `json:"code"` Data *UsersBalanceResponseData `json:"data"` Scode string `json:"scode"` Status bool `json:"status"` }
type UsersBalanceResponseData ¶ added in v0.4.0
type UsersBalanceResponseData struct { // AvailableBalance including cash balance and voucher balance. When it is less than or equal to 0, the user cannot call the completions API AvailableBalance float64 `json:"available_balance"` // VoucherBalance will not be negative VoucherBalance float64 `json:"voucher_balance"` // CashBalance may be negative, which means that the user owes the cost. When it is negative, the AvailableBalance can be the amount of VoucherBalance CashBalance float64 `json:"cash_balance"` }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.