Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateAuthToken(accessKey string, secretKey string, expiresIn time.Duration) (string, error)
- type APIError
- type AuthToken
- type ChatCompletionMessage
- type ChatCompletionRequest
- type ChatCompletionResponse
- type ChatCompletionResponseChoices
- type ChatCompletionResponseData
- type ChatCompletionResponseError
- type ChatCompletionStream
- type Client
- type ClientConfig
- type ErrorResponse
- type JwtClaims
- type RequestError
- type Usage
Constants ¶
View Source
const ( ChatMessageRoleUser = "user" ChatMessageRoleAssistant = "assistant" ModelNovaPtcXlV1 = "nova-ptc-xl-v1" ModelNovaPtcSV2 = "nova-ptc-s-v2" ModelNovaPtcXsV1 = "nova-ptc-xs-v1" )
Variables ¶
View Source
var ( ErrChatCompletionInvalidModel = errors.New("this model is not supported with this method, please use CreateCompletion client method instead") //nolint:lll ErrChatCompletionStreamNotSupported = errors.New("streaming is not supported with this method, please use CreateChatCompletionStream") //nolint:lll )
Functions ¶
Types ¶
type APIError ¶
type APIError struct { Err struct { Code int `json:"code,omitempty"` Message string `json:"message"` Details []any `json:"details"` } `json:"error"` }
APIError provides error information returned by the API.
func (*APIError) UnmarshalJSON ¶
type ChatCompletionMessage ¶
type ChatCompletionRequest ¶
type ChatCompletionRequest struct { Model string `json:"model"` Messages []ChatCompletionMessage `json:"messages"` N int `json:"n,omitempty"` // 生成回复数量,响应参数中的index即为回复序号(在使用某些模型时不支持传入该参数,详情请参考模型清单) https://platform.sensenova.cn/#/doc?path=/model.md MaxNewTokens int `json:"max_new_tokens,omitempty"` RepetitionPenalty float32 `json:"repetition_penalty,omitempty"` Temperature float32 `json:"temperature,omitempty"` TopP float32 `json:"top_p,omitempty"` Stream bool `json:"stream,omitempty"` User string `json:"user,omitempty"` }
ChatCompletionRequest represents a request structure for chat completion API.
type ChatCompletionResponse ¶
type ChatCompletionResponse struct { Data ChatCompletionResponseData `json:"data"` Error ChatCompletionResponseError `json:"error"` }
ChatCompletionResponse represents a response structure for chat completion API.
type ChatCompletionStream ¶
type ChatCompletionStream struct {
// contains filtered or unexported fields
}
ChatCompletionStream
func (ChatCompletionStream) Recv ¶
func (stream ChatCompletionStream) Recv() (response ChatCompletionResponse, err error)
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClientWithConfig ¶
func NewClientWithConfig(config ClientConfig) *Client
NewClientWithConfig creates new Sense Nova API client for specified config.
func (*Client) CreateChatCompletion ¶
func (c *Client) CreateChatCompletion( ctx context.Context, request ChatCompletionRequest, args ...any, ) (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, args ...any, ) (stream *ChatCompletionStream, err error)
CreateChatCompletionStream — API call to create a chat completion w/ streaming support.
type ClientConfig ¶
type ClientConfig struct { BaseURL string HTTPClient *http.Client EmptyMessagesLimit uint // 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 RequestError ¶
RequestError provides informations about generic request errors.
func (*RequestError) Error ¶
func (e *RequestError) Error() string
func (*RequestError) Unwrap ¶
func (e *RequestError) Unwrap() error
Click to show internal directories.
Click to hide internal directories.