Documentation
¶
Overview ¶
Package docsgpt is a Go client for the DocsGPT chat API.
It talks to the OpenAI-compatible /v1/chat/completions endpoint of a DocsGPT server, with the streaming, tool-calling and conversation-id handling the DocsGPT extensions add on top.
client := docsgpt.NewClient("https://gptcloud.arc53.com", apiKey)
resp, err := client.Send(ctx, docsgpt.ChatRequest{
Messages: []docsgpt.Message{{Role: "user", Content: "What is DocsGPT?"}},
})
The import path ends in /sdk while the package is named docsgpt, so imports are written as:
import "github.com/arc53/DocsGPT-cli/sdk"
and the package is referred to as docsgpt.
This module is versioned independently of the docsgpt-cli command that lives in the same repository: its tags are prefixed, as in sdk/v0.1.0. While it is below v1 the API may still change.
Index ¶
- type APIError
- type ChatRequest
- type ChatResponse
- type Choice
- type Client
- func (c *Client) RunWithTools(ctx context.Context, messages []Message, tools []Tool, stream bool, ...) ([]Message, error)
- func (c *Client) Send(ctx context.Context, req ChatRequest) (*ChatResponse, error)
- func (c *Client) SendStream(ctx context.Context, req ChatRequest, onDelta StreamHandler) (*ChatResponse, error)
- type Delta
- type DocsGPTMeta
- type DocsGPTRequest
- type FunctionCall
- type Message
- type StreamHandler
- type Tool
- type ToolCall
- type ToolCallHandler
- type ToolFunction
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
// StatusCode is the HTTP status the server replied with.
StatusCode int
// Body is the raw response body, which usually carries the server's
// own error message.
Body string
}
APIError is returned when the server answers with a non-200 status. Callers that need to tell "the agent is missing" from "the key is wrong" from "the server is down" can inspect StatusCode rather than matching on a string.
type ChatRequest ¶
type ChatResponse ¶
type ChatResponse struct {
Choices []Choice `json:"choices"`
DocsGPT DocsGPTMeta `json:"docsgpt,omitempty"`
Usage *Usage `json:"usage,omitempty"`
}
type Client ¶
func (*Client) RunWithTools ¶
func (c *Client) RunWithTools( ctx context.Context, messages []Message, tools []Tool, stream bool, onDelta StreamHandler, 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 StreamHandler) (*ChatResponse, error)
SendStream performs a streaming chat completion request, calling onDelta for each chunk. It returns the accumulated final response.
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 StreamHandler ¶
StreamHandler is called once per SSE chunk as it arrives, with the chunk's delta and its finish_reason — the latter empty on every chunk but the last.
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 ¶
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"`
}