Documentation
¶
Index ¶
- type ChatCompletionRequest
- type ChatCompletionResponse
- type ChatCompletionStreamResponse
- type Client
- func (c *Client) CreateChatCompletion(ctx context.Context, req ChatCompletionRequest) (string, error)
- func (c *Client) CreateChatCompletionStream(ctx context.Context, req ChatCompletionRequest) (*StreamReader, error)
- func (c *Client) CreateChatCompletionStreamWithMarkdown(ctx context.Context, req ChatCompletionRequest, w io.Writer, ...) error
- type ClientOption
- type Message
- type StreamOptions
- type StreamReader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChatCompletionRequest ¶
type ChatCompletionRequest struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
Temperature float32 `json:"temperature,omitempty"`
ReasoningEffort string `json:"reasoning_effort,omitempty"`
Stream bool `json:"stream,omitempty"`
}
ChatCompletionRequest represents a chat completion request
type ChatCompletionResponse ¶
type ChatCompletionResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []struct {
Index int `json:"index"`
Message Message `json:"message"`
FinishReason string `json:"finish_reason"`
} `json:"choices"`
Usage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
} `json:"usage"`
}
ChatCompletionResponse represents the API response for non-streaming requests
type ChatCompletionStreamResponse ¶
type ChatCompletionStreamResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []struct {
Index int `json:"index"`
Delta struct {
Role string `json:"role,omitempty"`
Content string `json:"content,omitempty"`
} `json:"delta"`
FinishReason *string `json:"finish_reason"`
} `json:"choices"`
}
ChatCompletionStreamResponse represents a streaming chunk response
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client handles OpenAI API requests
func NewClient ¶
func NewClient(apiKey string, opts ...ClientOption) *Client
NewClient creates a new OpenAI client
func (*Client) CreateChatCompletion ¶
func (c *Client) CreateChatCompletion( ctx context.Context, req ChatCompletionRequest, ) (string, error)
CreateChatCompletion sends a non-streaming chat completion request
func (*Client) CreateChatCompletionStream ¶
func (c *Client) CreateChatCompletionStream( ctx context.Context, req ChatCompletionRequest, ) (*StreamReader, error)
CreateChatCompletionStream sends a streaming chat completion request
func (*Client) CreateChatCompletionStreamWithMarkdown ¶ added in v0.0.2
func (c *Client) CreateChatCompletionStreamWithMarkdown( ctx context.Context, req ChatCompletionRequest, w io.Writer, opts StreamOptions, ) error
CreateChatCompletionStreamWithMarkdown sends a streaming chat completion request and renders the output incrementally as markdown using the StreamMarkdown function
type ClientOption ¶
type ClientOption func(*Client)
ClientOption is a functional option for configuring the Client
func WithHTTPClient ¶
func WithHTTPClient(httpClient *http.Client) ClientOption
WithHTTPClient sets a custom HTTP client
type StreamOptions ¶ added in v0.0.3
type StreamOptions = markdown.StreamOptions
StreamOptions configures markdown streaming output for CreateChatCompletionStreamWithMarkdown.
type StreamReader ¶
type StreamReader struct {
// contains filtered or unexported fields
}
StreamReader provides access to streaming chat completion responses
func (*StreamReader) Recv ¶
func (s *StreamReader) Recv() (ChatCompletionStreamResponse, error)
Recv reads the next chunk from the stream