api

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatRequest

type ChatRequest struct {
	Model          string          `json:"model,omitempty"`
	Messages       []Message       `json:"messages"`
	Stream         bool            `json:"stream"`
	Tools          []Tool          `json:"tools,omitempty"`
	ConversationID string          `json:"conversation_id,omitempty"`
	DocsGPT        *DocsGPTRequest `json:"docsgpt,omitempty"`
}

type ChatResponse

type ChatResponse struct {
	Choices []Choice    `json:"choices"`
	DocsGPT DocsGPTMeta `json:"docsgpt,omitempty"`
	Usage   *Usage      `json:"usage,omitempty"`
}

type Choice

type Choice struct {
	Delta        Delta  `json:"delta,omitempty"`
	Message      Delta  `json:"message,omitempty"`
	FinishReason string `json:"finish_reason,omitempty"`
}

type Client

type Client struct {
	BaseURL    string
	APIKey     string
	HTTPClient *http.Client
}

func NewClient

func NewClient(baseURL, apiKey string) *Client

func (*Client) RunWithTools

func (c *Client) RunWithTools(
	ctx context.Context,
	messages []Message,
	tools []Tool,
	stream bool,
	onDelta func(Delta, string),
	onToolCall ToolCallHandler,
) ([]Message, error)

RunWithTools sends a chat request and handles tool call loops. When the model returns tool_calls, onToolCall is invoked for each one, and results are sent back in a continuation request. This repeats until the model returns finish_reason "stop" (or non-tool_calls).

func (*Client) Send

func (c *Client) Send(ctx context.Context, req ChatRequest) (*ChatResponse, error)

Send performs a non-streaming chat completion request.

func (*Client) SendStream

func (c *Client) SendStream(ctx context.Context, req ChatRequest, onDelta func(Delta, string)) (*ChatResponse, error)

SendStream performs a streaming chat completion request. onDelta is called for each SSE chunk with the delta and finish_reason. Returns the accumulated final response.

type Delta

type Delta struct {
	Role             string     `json:"role,omitempty"`
	Content          string     `json:"content,omitempty"`
	ReasoningContent string     `json:"reasoning_content,omitempty"`
	ToolCalls        []ToolCall `json:"tool_calls,omitempty"`
}

type DocsGPTMeta

type DocsGPTMeta struct {
	ConversationID string          `json:"conversation_id,omitempty"`
	Sources        json.RawMessage `json:"sources,omitempty"`
	ToolCalls      json.RawMessage `json:"tool_calls,omitempty"`
}

DocsGPTMeta is the response-side "docsgpt" extension object. Sources and ToolCalls stay raw so a surprising shape can never fail the whole response decode (which would drop an otherwise valid answer).

type DocsGPTRequest

type DocsGPTRequest struct {
	Attachments []string `json:"attachments,omitempty"`
}

DocsGPTRequest is the request-side "docsgpt" extension object. It currently carries server-side attachment ids for the /v1 endpoint.

type FunctionCall

type FunctionCall struct {
	Name      string `json:"name,omitempty"`
	Arguments string `json:"arguments,omitempty"`
}

type Message

type Message struct {
	Role       string     `json:"role"`
	Content    string     `json:"content,omitempty"`
	ToolCalls  []ToolCall `json:"tool_calls,omitempty"`
	ToolCallID string     `json:"tool_call_id,omitempty"`
}

type Tool

type Tool struct {
	Type     string       `json:"type"`
	Function ToolFunction `json:"function"`
}

type ToolCall

type ToolCall struct {
	Index    int          `json:"index,omitempty"`
	ID       string       `json:"id,omitempty"`
	Type     string       `json:"type,omitempty"`
	Function FunctionCall `json:"function"`
}

type ToolCallHandler

type ToolCallHandler func(tc ToolCall) string

ToolCallHandler is called when the model requests a tool call. It receives the tool call and should return the result string.

type ToolFunction

type ToolFunction struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	Parameters  json.RawMessage `json:"parameters"`
}

type Usage

type Usage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

Usage mirrors the OpenAI usage object returned by /v1/chat/completions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL