docsgpt

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 8 Imported by: 1 module, 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

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

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.

func (*APIError) Error

func (e *APIError) Error() string

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 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 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 StreamHandler

type StreamHandler func(delta Delta, finishReason string)

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

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