api

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UserFromContext = staffio.UserFromContext
	ContextWithUser = staffio.ContextWithUser
)

vars from staffio

Functions

func GetOAuthTokenFromCookie

func GetOAuthTokenFromCookie(ctx context.Context, r *http.Request) string

GetOAuthTokenFromCookie 从 cookie 获取 token(当前实现) tokenCN 需要与 handle_user.go 中的保持一致

func InitChannels added in v0.3.0

func InitChannels(r chi.Router, preset *aigc.Preset, sto stores.Storage, llmClient llm.Client, toolreg *tools.Registry) error

InitChannels initializes channel adapters from preset configuration.

func OAuthTokenMiddleware

func OAuthTokenMiddleware(getToken GetOAuthTokenFunc) func(http.Handler) http.Handler

OAuthTokenMiddleware 创建中间件,将 cookie 中的 token 注入 context

func StopChannels added in v0.3.0

func StopChannels()

StopChannels stops all channel adapters.

Types

type ChatMessage

type ChatMessage struct {
	ID    string `json:"id,omitempty"`
	Delta string `json:"delta,omitempty"`
	Text  string `json:"text,omitempty"`
	Think string `json:"think,omitempty"`
	Role  string `json:"role,omitempty"`
	Name  string `json:"name,omitempty"`

	// For Role=assistant prompts this may be set to the tool calls generated by the model, such as function calls.
	ToolCalls []map[string]any `json:"tool_calls,omitempty"`

	// For Role=tool prompts this should be set to the ID given in the assistant's prior request to call a tool.
	ToolCallID string `json:"tool_call_id,omitempty"`

	FinishReason string `json:"finishReason,omitempty"`

	ConversationID string `json:"csid,omitempty"`

	Title string `json:"title,omitempty"`
}

for response to client

type ChatRequest

type ChatRequest struct {
	Prompt          string `json:"prompt"`
	ConversationID  string `json:"csid"`
	ParentMessageID string `json:"pmid"` // TODO: rename to PreviousMessageID
	Regenerate      bool   `json:"regen"`
	Stream          bool   `json:"stream"`

	MCPs []string `json:"mcps,omitempty"`

	// deprecated: for github.com/Chanzhaoyu/chatgpt-web only
	Options struct {
		ConversationId string `json:"conversationId,omitempty"`
	} `json:"options,omitempty"`
}

func (*ChatRequest) GetConversionID

func (z *ChatRequest) GetConversionID() string

type Command added in v0.3.0

type Command struct {
	Name    string
	Aliases []string
	Desc    string
	Action  func(ctx context.Context, msg *channel.Message) (bool, error)
}

func DetectCommand added in v0.3.0

func DetectCommand(content string) Command

type Done

type Done = resp.Done

type Failure

type Failure = resp.Failure

type GetOAuthTokenFunc

type GetOAuthTokenFunc func(ctx context.Context, r *http.Request) string

GetOAuthTokenFunc 用于获取 OAuth token 的函数类型 将来可能从 Redis/DB 获取,当前从 cookie 获取

type M

type M = render.M

type O2User added in v0.3.0

type O2User = staffio.O2User

type ResultData

type ResultData = resp.ResultData

type ResultID

type ResultID = resp.ResultID

type SummaryRequest

type SummaryRequest struct {
	Tips string `json:"tips,omitempty"`
	Text string `json:"text"`
}

SummaryRequest 摘要请求

type ToolExecutor added in v0.3.0

type ToolExecutor struct {
	// contains filtered or unexported fields
}

ToolExecutor 封装工具调用循环逻辑

func NewToolExecutor added in v0.3.0

func NewToolExecutor(toolreg *tools.Registry) *ToolExecutor

NewToolExecutor 创建 ToolExecutor

func (*ToolExecutor) ExecuteToolCallLoop added in v0.3.0

func (e *ToolExecutor) ExecuteToolCallLoop(
	ctx context.Context,
	messages []llm.Message,
	tools []llm.ToolDefinition,
	exec chatExecutor,
) (string, []llm.ToolCall, *llm.Usage, error)

ExecuteToolCallLoop 执行工具调用循环,直到无 tool calls

type User

type User = staffio.User

Jump to

Keyboard shortcuts

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