Documentation
¶
Index ¶
- type APIError
- type APIErrorDetails
- type Client
- func (c *Client) CreateMessageRequest(ctx context.Context, request MessagesRequest) (*MessageResponse, error)
- func (c *Client) CreateMessageRequestStream(ctx context.Context, request MessagesRequest) (*StreamReader, error)
- func (c *Client) SetApiUrl(apiUrl string)
- func (c *Client) SetApiVersion(apiVersion string)
- func (c *Client) SetProxy(proxyUrl string) error
- type Message
- type MessageContent
- type MessageContentType
- type MessageMetadata
- type MessageResponse
- type MessageResponseUsage
- type MessageRole
- type MessagesRequest
- type StreamReader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct { Type string `json:"type"` ErrorDetails APIErrorDetails `json:"error"` }
type APIErrorDetails ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) CreateMessageRequest ¶
func (c *Client) CreateMessageRequest(ctx context.Context, request MessagesRequest) (*MessageResponse, error)
CreateMessageRequest - API call to create message
func (*Client) CreateMessageRequestStream ¶
func (c *Client) CreateMessageRequestStream(ctx context.Context, request MessagesRequest) (*StreamReader, error)
func (*Client) SetApiVersion ¶
type Message ¶
type Message struct { Role string `json:"role"` Content []*MessageContent `json:"content"` }
type MessageContent ¶
type MessageContent struct { Type string `json:"type"` Text string `json:"text,omitempty"` Source *MessageContentType `json:"source,omitempty"` }
type MessageContentType ¶
type MessageMetadata ¶
type MessageMetadata struct {
UserId string `json:"user_id,omitempty"`
}
type MessageResponse ¶
type MessageResponse struct { Id string `json:"id"` Type string `json:"type"` Role string `json:"role"` Model string `json:"model"` Content []*MessageContent `json:"content"` StopReason string `json:"stop_reason"` StopSequences string `json:"stop_sequences"` Usage *MessageResponseUsage `json:"usage"` }
type MessageResponseUsage ¶
type MessageRole ¶
type MessageRole string
const ( User MessageRole = "user" Assistant MessageRole = "assistant" )
type MessagesRequest ¶
type MessagesRequest struct { Model string `json:"model"` Messages []*Message `json:"messages"` System string `json:"system,omitempty"` MaxTokens int `json:"max_tokens"` Metadata *MessageMetadata `json:"metadata,omitempty"` StopSequences []string `json:"stop_sequences,omitempty"` Stream bool `json:"stream,omitempty"` Temperature float32 `json:"temperature,omitempty"` TopP float32 `json:"top_p,omitempty"` TopK int32 `json:"top_k,omitempty"` }
func NewMessageRequest ¶
func NewMessageRequest(model string, maxTokens int) *MessagesRequest
func (*MessagesRequest) AddImageMessage ¶
func (m *MessagesRequest) AddImageMessage(role MessageRole, image []byte, imageMediaType string, caption string)
func (*MessagesRequest) AddSystemMessage ¶
func (m *MessagesRequest) AddSystemMessage(text string)
func (*MessagesRequest) AddTextMessage ¶
func (m *MessagesRequest) AddTextMessage(role MessageRole, text string)
func (*MessagesRequest) ClearMessages ¶
func (m *MessagesRequest) ClearMessages()
type StreamReader ¶
type StreamReader struct {
// contains filtered or unexported fields
}
func NewStreamReader ¶
func NewStreamReader(reader io.Reader) *StreamReader
func (*StreamReader) ReadMessage ¶
func (s *StreamReader) ReadMessage(accumulateResponse bool) (string, error)
ReadMessage reads a single line from the stream. Skips any lines that do not start with "data:" When it receives message with type content_block_stop, it stops reading the stream.
Click to show internal directories.
Click to hide internal directories.