dgopenai

package module
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateJsonObject

func GenerateJsonObject[T any](ctx *dgctx.DgContext, tgcReq *TemplateGenerateContentRequest) (*T, error)

func InitPlatformClients

func InitPlatformClients(timeout time.Duration, clientConfigs ...*PlatformClientConfig)

func StreamChat

func StreamChat(ctx *dgctx.DgContext, chatReq *ChatRequest) (chan *GenerateContentResponse, error)

func StreamGenerateContent

func StreamGenerateContent(ctx *dgctx.DgContext, tgcReq *TemplateGenerateContentRequest) (chan *GenerateContentResponse, error)

Types

type ChatMessage

type ChatMessage struct {
	Id             int64                `json:"id" remark:"消息ID"`
	Role           string               `json:"role" remark:"角色"`
	Content        string               `json:"content" remark:"生成内容"`
	ResponseFormat string               `json:"responseFormat" remark:"响应格式"`
	FunctionCall   *openai.FunctionCall `json:"functionCall" remark:"函数调用"`
	FinishReason   string               `json:"finishReason" remark:"结束原因"`
	RequestId      string               `json:"requestId" remark:"请求ID"`
}

type ChatMessageProvider

type ChatMessageProvider interface {
	FindChatMessages(ctx *dgctx.DgContext, sessionId int64) ([]*ChatMessage, error)
	SaveChatMessages(ctx *dgctx.DgContext, sessionId int64, messages []*ChatMessage) error
}
var MyChatMessageProvider ChatMessageProvider

type ChatRequest

type ChatRequest struct {
	SessionId    int64                    `json:"sessionId" binding:"required" remark:"会话ID"`
	Content      string                   `json:"content" remark:"聊天内容"`
	MultiContent []openai.ChatMessagePart `json:"multiContent" remark:"多轮对话内容"`
	Params       map[string]any           `json:"params" remark:"参数"`
	RequestId    string                   `json:"requestId" remark:"请求ID"`
}

type ChatResponse

type ChatResponse struct {
	Messages []*ChatMessage `json:"messages" remark:"消息列表"`
}

func Chat

func Chat(ctx *dgctx.DgContext, chatReq *ChatRequest) (*ChatResponse, error)

type ChatSessionProvider

type ChatSessionProvider interface {
	GetTemplateNameBySessionId(ctx *dgctx.DgContext, sessionId int64) (string, error)
}
var MyChatSessionProvider ChatSessionProvider

type ChatTemplateGenerateContentRequest

type ChatTemplateGenerateContentRequest struct {
	SessionId      int64                    `json:"sessionId" binding:"required" remark:"会话ID"`
	TemplateName   string                   `json:"templateName" remark:"模板名称"`
	TemplateParams map[string]any           `json:"templateParams" remark:"模板参数"`
	MultiContent   []openai.ChatMessagePart `json:"multiContent" remark:"多轮对话内容"`
	BizParams      map[string]any           `json:"bizParams" remark:"业务参数"`
	RequestId      string                   `json:"requestId" remark:"请求ID"`
}

type FunctionCallProvider

type FunctionCallProvider interface {
	Call(ctx *dgctx.DgContext, functionCall *openai.FunctionCall, bizParams map[string]any) (string, error)
}
var MyFunctionCallProvider FunctionCallProvider

type GenerateContentRequest

type GenerateContentRequest struct {
	PlatformModels []*PlatformModelPair `json:"platformModels" remark:"平台模型列表"`
	EnableThinking bool                 `json:"enableThinking" remark:"是否启用思考模式"`
	TryTimes       int                  `json:"tryTimes" remark:"尝试次数"`
	RequestId      string               `json:"requestId" remark:"请求ID"`

	Messages         []openai.ChatCompletionMessage       `json:"messages" remark:"消息列表"`
	MaxTokens        int                                  `json:"maxTokens" remark:"最大token数"`
	Temperature      float32                              `json:"temperature" remark:"温度"`
	FrequencyPenalty float32                              `json:"frequencyPenalty" remark:"频率惩罚"`
	ResponseFormat   *openai.ChatCompletionResponseFormat `json:"responseFormat" remark:"响应格式"`
	Tools            []openai.Tool                        `json:"tools" remark:"工具列表"`
}

type GenerateContentResponse

type GenerateContentResponse struct {
	Platform       string               `json:"platform" remark:"平台"`
	Model          string               `json:"model" remark:"模型"`
	Content        string               `json:"content" remark:"生成内容"`
	ResponseFormat string               `json:"responseFormat" remark:"响应格式"`
	RequestId      string               `json:"requestId" remark:"请求ID"`
	Usage          *openai.Usage        `json:"usage" remark:"使用量"`
	FunctionCall   *openai.FunctionCall `json:"functionCall" remark:"函数调用"`
	FinishReason   string               `json:"finishReason" remark:"结束原因"`
}

type GenerateContentResponseProvider

type GenerateContentResponseProvider interface {
	SaveGenerateContentResponse(ctx *dgctx.DgContext, templateName string, gcReq *GenerateContentRequest, gcResp *GenerateContentResponse,
		bizParams map[string]any, retry int, cost time.Duration, err error) error
	SaveChatGenerateContentResponse(ctx *dgctx.DgContext, templateName string, gcReq *GenerateContentRequest, gcResp *GenerateContentResponse,
		bizParams map[string]any, sessionId, messageId int64, retry int, cost time.Duration, err error) error
}
var MyAigcResponseProvider GenerateContentResponseProvider

type GenerateContentTemplateProvider

type GenerateContentTemplateProvider interface {
	GetGenerateContentRequest(ctx *dgctx.DgContext, templateName string, templateParams map[string]any, multiContent []openai.ChatMessagePart) (*GenerateContentRequest, error)
	GetChatGenerateContentRequest(ctx *dgctx.DgContext, templateName string) (*GenerateContentRequest, error)
}
var MyAigcTemplateProvider GenerateContentTemplateProvider

type PlatformClientConfig

type PlatformClientConfig struct {
	Platform  string `json:"platform" remark:"平台"`
	BaseUrl   string `json:"baseUrl" remark:"基本url"`
	AuthToken string `json:"authToken" remark:"认证token"`
}

type PlatformModelPair

type PlatformModelPair struct {
	Platform string `json:"platform" remark:"平台"`
	Model    string `json:"model" remark:"模型"`
}

type TemplateGenerateContentRequest

type TemplateGenerateContentRequest struct {
	TemplateName   string                   `json:"templateName" remark:"模板名称"`
	TemplateParams map[string]any           `json:"templateParams" remark:"模板参数"`
	MultiContent   []openai.ChatMessagePart `json:"multiContent" remark:"多轮对话内容"`
	BizParams      map[string]any           `json:"bizParams" remark:"业务参数"`
	RequestId      string                   `json:"requestId" remark:"请求ID"`
}

Jump to

Keyboard shortcuts

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