mp_common

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: Apache-2.0 Imports: 12 Imported by: ? 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

View Source
const (
	TagChat          string = "CHAT"
	TagEmbedding     string = "Embedding"
	TagRerank        string = "Rerank"
	TagGui           string = "GUI"
	TagOcr           string = "OCR"
	TagPdfParser     string = "文档解析"
	TagVisionSupport string = "图文问答"
	TagToolCall      string = "工具调用"
)

Variables

This section is empty.

Functions

func Embeddings added in v0.1.5

func Embeddings(ctx context.Context, provider, apiKey, url string, req map[string]interface{}, headers ...Header) ([]byte, error)

func Gui added in v0.2.1

func Gui(ctx context.Context, provider, apiKey, url string, req *GuiReq, headers ...Header) ([]byte, error)

func Ocr added in v0.1.5

func Ocr(ctx *gin.Context, provider, apiKey, url string, req *OcrReq, headers ...Header) ([]byte, error)

func PdfParser added in v0.2.3

func PdfParser(ctx *gin.Context, provider, apiKey, url string, req *PdfParserReq, headers ...Header) ([]byte, error)

func Rerank added in v0.1.5

func Rerank(ctx context.Context, provider, apiKey, url string, req map[string]interface{}, headers ...Header) ([]byte, error)

Types

type Document added in v0.1.3

type Document struct {
	Text string `json:"text"`
}

type EmbeddingData added in v0.1.3

type EmbeddingData struct {
	Object    string    `json:"object"`
	Embedding []float64 `json:"embedding" validate:"required,min=1"`
	Index     int       `json:"index"`
}

type EmbeddingReq added in v0.1.3

type EmbeddingReq struct {
	Model          string   `json:"model" validate:"required"`
	Input          []string `json:"input" validate:"required"`
	EncodingFormat *string  `json:"encoding_format,omitempty"`
}

func (*EmbeddingReq) Check added in v0.1.3

func (req *EmbeddingReq) Check() error

func (*EmbeddingReq) Data added in v0.1.5

func (req *EmbeddingReq) Data() (map[string]interface{}, error)

type EmbeddingResp added in v0.1.3

type EmbeddingResp struct {
	Id      *string         `json:"id,omitempty"`
	Model   string          `json:"model" validate:"required"`
	Object  *string         `json:"object,omitempty"`
	Data    []EmbeddingData `json:"data" validate:"required,dive"`
	Usage   Usage           `json:"usage"`
	Created *int            `json:"created,omitempty"`
}

type ExtraBody added in v0.2.3

type ExtraBody struct {
	ApiOption string `json:"api_option"` // 选择指定功能。 1)math:拍照答题;2)ocr:多模态OCR;3)general:通用场景。   默认会根据prompt进行意图判断
}

type FCType added in v0.1.4

type FCType string
const (
	FCTypeFunctionCall FCType = "functionCall"
	FCTypeNoSupport    FCType = "noSupport"
	FCTypeToolCall     FCType = "toolCall"
)

type FunctionCall added in v0.1.4

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

type GuiContent added in v0.2.1

type GuiContent struct {
	Description string `json:"description" validate:"required"`
	Operation   string `json:"operation" validate:"required"`
	Action      string `json:"action" validate:"required"`
	Box         []int  `json:"box"`
	Value       string `json:"value"`
	Sensitivity string `json:"sensitivity"`
}

type GuiReq added in v0.2.1

type GuiReq struct {
	Algo                    string   `json:"algo,omitempty"`                                     // 算法名称,默认gui_agent_v1
	Platform                string   `json:"platform" validate:"required"`                       // 平台信息,移动端填写Mobile, Windows端填写WIN,Mac端填写MAC
	CurrentScreenshotXml    string   `json:"current_screenshot_xml,omitempty"`                   // 屏幕布局导出的xml文件
	CurrentScreenshot       string   `json:"current_screenshot" validate:"required"`             // 当前屏幕截图,Base64编码的图像字符串
	CurrentScreenshotWidth  int      `json:"current_screenshot_width" validate:"required,gt=0"`  // 当前屏幕截图的宽度
	CurrentScreenshotHeight int      `json:"current_screenshot_height" validate:"required,gt=0"` // 当前屏幕截图的高度
	Task                    string   `json:"task" validate:"required"`                           //当前用户任务
	History                 []string `json:"history"`                                            //当前任务的历史返回结果,历次返回结果中的content字段
}

func (*GuiReq) Check added in v0.2.1

func (req *GuiReq) Check() error

func (*GuiReq) Data added in v0.2.1

func (req *GuiReq) Data() (map[string]interface{}, error)

type GuiResp added in v0.2.1

type GuiResp struct {
	Code    int        `json:"code"`
	Message string     `json:"message" validate:"required"`
	Content GuiContent `json:"content" validate:"required"`
	Usage   Usage      `json:"usage" validate:"required"`
}
type Header struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type IEmbeddingReq

type IEmbeddingReq interface {
	Data() map[string]interface{}
}

func NewEmbeddingReq

func NewEmbeddingReq(data map[string]interface{}) IEmbeddingReq

type IEmbeddingResp

type IEmbeddingResp interface {
	String() string
	Data() (map[string]interface{}, bool)
	ConvertResp() (*EmbeddingResp, bool)
}

func NewEmbeddingResp

func NewEmbeddingResp(raw string) IEmbeddingResp

type IGuiReq added in v0.2.1

type IGuiReq interface {
	Data() *GuiReq
}

func NewGuiReq added in v0.2.1

func NewGuiReq(data *GuiReq) IGuiReq

type IGuiResp added in v0.2.1

type IGuiResp interface {
	String() string
	Data() (interface{}, bool)
	ConvertResp() (*GuiResp, bool)
}

func NewGuiResp added in v0.2.1

func NewGuiResp(raw string) IGuiResp

type ILLMReq

type ILLMReq interface {
	Stream() bool
	Data() map[string]interface{}
	OpenAIReq() (*LLMReq, bool)
}

func NewLLMReq

func NewLLMReq(data map[string]interface{}) ILLMReq

type ILLMResp

type ILLMResp interface {
	String() string
	Data() (map[string]interface{}, bool)
	ConvertResp() (*LLMResp, bool)
}

func ChatCompletions added in v0.1.5

func ChatCompletions(ctx context.Context, provider, apiKey, url string, req ILLMReq, respConverter func(bool, string) ILLMResp, headers ...Header) (ILLMResp, <-chan ILLMResp, error)

func NewLLMResp

func NewLLMResp(stream bool, raw string) ILLMResp

type IOcrReq added in v0.1.5

type IOcrReq interface {
	Data() *OcrReq
}

func NewOcrReq added in v0.1.5

func NewOcrReq(data *OcrReq) IOcrReq

type IOcrResp added in v0.1.5

type IOcrResp interface {
	String() string
	Data() (interface{}, bool)
	ConvertResp() (*OcrResp, bool)
}

func NewOcrResp added in v0.1.5

func NewOcrResp(raw string) IOcrResp

type IPdfParserReq added in v0.2.3

type IPdfParserReq interface {
	Data() *PdfParserReq
}

func NewPdfParserReq added in v0.2.3

func NewPdfParserReq(data *PdfParserReq) IPdfParserReq

type IPdfParserResp added in v0.2.3

type IPdfParserResp interface {
	String() string
	Data() (interface{}, bool)
	ConvertResp() (*PdfParserResp, bool)
}

func NewPdfParserResp added in v0.2.3

func NewPdfParserResp(raw string) IPdfParserResp

type IRerankReq

type IRerankReq interface {
	Data() map[string]interface{}
}

func NewRerankReq

func NewRerankReq(data map[string]interface{}) IRerankReq

type IRerankResp

type IRerankResp interface {
	String() string
	Data() (interface{}, bool)
	ConvertResp() (*RerankResp, bool)
}

func NewRerankResp

func NewRerankResp(raw string) IRerankResp

type LLMReq added in v0.1.4

type LLMReq struct {
	// general
	Model          string                `json:"model" validate:"required"`
	Messages       []OpenAIReqMsg        `json:"messages" validate:"required"`
	Stream         *bool                 `json:"stream,omitempty"`
	MaxTokens      *int                  `json:"max_tokens,omitempty"`
	Stop           *string               `json:"stop,omitempty"`
	ResponseFormat *OpenAIResponseFormat `json:"response_format,omitempty"`
	Temperature    *float64              `json:"temperature,omitempty"`
	Tools          []OpenAITool          `json:"tools,omitempty"`

	// custom
	Thinking            *Thinking      `json:"thinking,omitempty"` // 控制模型是否开启深度思考模式。
	EnableThinking      *bool          `json:"enable_thinking,omitempty"`
	MaxCompletionTokens *int           `json:"max_completion_tokens,omitempty"` // 控制模型输出的最大长度[0,64k]
	LogitBias           map[string]int `json:"logit_bias,omitempty"`            // 调整指定 token 在模型输出内容中出现的概率
	ToolChoice          interface{}    `json:"tool_choice,omitempty"`           // 强制指定工具调用的策略
	TopP                *float64       `json:"top_p,omitempty"`
	TopK                *int           `json:"top_k,omitempty"`
	MinP                *float64       `json:"min_p,omitempty"`
	ParallelToolCalls   *bool          `json:"parallel_tool_calls,omitempty"` // 是否开启并行工具调用
	StreamOptions       *StreamOptions `json:"stream_options,omitempty"`      //当启用流式输出时,可通过将本参数设置为{"include_usage": true},在输出的最后一行显示所使用的Token数。

	PresencePenalty   *float64 `json:"presence_penalty,omitempty"`   // 控制模型生成文本时的内容重复度
	FrequencyPenalty  *float64 `json:"frequency_penalty,omitempty"`  // 频率惩罚系数
	RepetitionPenalty *float64 `json:"repetition_penalty,omitempty"` // 模型生成时连续序列中的重复度

	Seed           *int  `json:"seed,omitempty"`         // 种子
	Logprobs       *bool `json:"logprobs,omitempty"`     // 是否返回输出 Token 的对数概率
	TopLogprobs    *int  `json:"top_logprobs,omitempty"` // 指定在每一步生成时,返回模型最大概率的候选 Token 个数
	N              *int  `json:"n,omitempty"`
	ThinkingBudget *int  `json:"thinking_budget,omitempty"` // 思考过程的最大长度,只在enable_thinking为true时生效

	WebSearch *WebSearch `json:"web_search,omitempty"` //搜索增强
	User      *string    `json:"user,omitempty"`
	// Yuanjing
	DoSample  *bool      `json:"do_sample,omitempty"`
	ExtraBody *ExtraBody `json:"extra_body,omitempty"` // 扩展参数
}

func (*LLMReq) Check added in v0.1.4

func (req *LLMReq) Check() error

func (*LLMReq) Data added in v0.1.5

func (req *LLMReq) Data() (map[string]interface{}, error)

type LLMResp added in v0.1.4

type LLMResp struct {
	ID                string             `json:"id"`                               // 唯一标识
	Object            string             `json:"object"`                           // 固定为 "chat.completion"
	Created           int                `json:"created"`                          // 时间戳(秒)
	Model             string             `json:"model" validate:"required"`        // 使用的模型
	Choices           []OpenAIRespChoice `json:"choices" validate:"required,dive"` // 生成结果列表
	Usage             OpenAIRespUsage    `json:"usage"`                            // token 使用统计
	ServiceTier       *string            `json:"service_tier"`                     // (火山)指定是否使用TPM保障包。生效对象为购买了保障包推理接入点
	SystemFingerprint *string            `json:"system_fingerprint"`
	Code              *int               `json:"code,omitempty"`
	ImgId             *string            `json:"img_id,omitempty"` // 视觉模型返回图片id
}

type MsgRole added in v0.1.4

type MsgRole string
const (
	MsgRoleSystem    MsgRole = "system"
	MsgRoleUser      MsgRole = "user"
	MsgRoleAssistant MsgRole = "assistant"
	MsgRoleFunction  MsgRole = "tool"
)

type OcrData added in v0.1.5

type OcrData struct {
	PageNum []int  `json:"page_num" validate:"required,min=1"`
	Type    string `json:"type" validate:"required"`
	Text    string `json:"text"`
	Length  int    `json:"length"`
}

type OcrReq added in v0.1.5

type OcrReq struct {
	Files *multipart.FileHeader `form:"file" json:"file" validate:"required"`
}

func (*OcrReq) Check added in v0.1.5

func (req *OcrReq) Check() error

func (*OcrReq) Data added in v0.1.5

func (req *OcrReq) Data() (map[string]interface{}, error)

type OcrResp added in v0.1.5

type OcrResp struct {
	Code      int       `json:"code"`
	Message   string    `json:"message" validate:"required"`
	Version   string    `json:"version"`
	TimeStamp string    `json:"timestamp"`
	Id        string    `json:"id"`
	TimeCost  float64   `json:"time_cost"`
	OcrData   []OcrData `json:"data" validate:"required,dive"`
}

type OpenAIFunction added in v0.1.4

type OpenAIFunction struct {
	Name        string                    `json:"name" validate:"required"`
	Description string                    `json:"description,omitempty"`
	Parameters  *OpenAIFunctionParameters `json:"parameters,omitempty"`
}

type OpenAIFunctionParameters added in v0.1.4

type OpenAIFunctionParameters struct {
	Type       string                                      `json:"type"`
	Properties map[string]OpenAIFunctionParametersProperty `json:"properties"`
	Required   []string                                    `json:"required"`
}

type OpenAIFunctionParametersProperty added in v0.1.4

type OpenAIFunctionParametersProperty struct {
	Description string `json:"description"`
	Type        string `json:"type"`
}

type OpenAIMsg

type OpenAIMsg struct {
	Role             MsgRole       `json:"role"` // "system" | "user" | "assistant" | "function(已弃用)"
	Content          string        `json:"content"`
	ToolCallId       *string       `json:"tool_call_id,omitempty"`
	ReasoningContent *string       `json:"reasoning_content,omitempty"`
	Name             *string       `json:"name,omitempty"`
	FunctionCall     *FunctionCall `json:"function_call,omitempty"`
	ToolCalls        []*ToolCall   `json:"tool_calls,omitempty"`
}

type OpenAIReqMsg added in v0.2.3

type OpenAIReqMsg struct {
	Role             MsgRole       `json:"role"` // "system" | "user" | "assistant" | "function(已弃用)"
	Content          interface{}   `json:"content"`
	ToolCallId       *string       `json:"tool_call_id,omitempty"`
	ReasoningContent *string       `json:"reasoning_content,omitempty"`
	Name             *string       `json:"name,omitempty"`
	FunctionCall     *FunctionCall `json:"function_call,omitempty"`
	ToolCalls        []*ToolCall   `json:"tool_calls,omitempty"`
}

type OpenAIRespChoice

type OpenAIRespChoice struct {
	Index        int         `json:"index"`             // 选项索引
	Message      *OpenAIMsg  `json:"message,omitempty"` // 非流式生成的消息
	Delta        *OpenAIMsg  `json:"delta,omitempty"`   // 流式生成的消息
	FinishReason string      `json:"finish_reason"`     // 停止原因
	Logprobs     interface{} `json:"logprobs"`
}

OpenAIRespChoice 结构体表示单个生成选项

type OpenAIRespChoiceMsg

type OpenAIRespChoiceMsg struct {
	Content string `json:"content"`
	Role    string `json:"role"`
}

type OpenAIRespUsage

type OpenAIRespUsage struct {
	CompletionTokens int `json:"completion_tokens"` // 输出 token 数
	PromptTokens     int `json:"prompt_tokens"`     // 输入 token 数
	TotalTokens      int `json:"total_tokens"`      // 总 token 数
}

OpenAIRespUsage 结构体表示 token 消耗

type OpenAIResponseFormat

type OpenAIResponseFormat struct {
	Type string `json:"type"` // "text" | "json"
}

type OpenAITool added in v0.1.4

type OpenAITool struct {
	Type     ToolType        `json:"type" validate:"required"`
	Function *OpenAIFunction `json:"function" validate:"required"`
}

type PdfParserReq added in v0.2.3

type PdfParserReq struct {
	Files    *multipart.FileHeader `form:"file" json:"file" validate:"required"`
	FileName string                `form:"file_name" json:"file_name" validate:"required"`
}

func (*PdfParserReq) Check added in v0.2.3

func (req *PdfParserReq) Check() error

func (*PdfParserReq) Data added in v0.2.3

func (req *PdfParserReq) Data() (map[string]interface{}, error)

type PdfParserResp added in v0.2.3

type PdfParserResp struct {
	Code    string `json:"code" validate:"required"`
	Content string `json:"content" validate:"required"`
	Message string `json:"message" validate:"required"`
	Status  string `json:"status"`
	TraceId string `json:"trace_id"`
}

type RerankReq added in v0.1.3

type RerankReq struct {
	Documents       []string `json:"documents" validate:"required"`
	Model           string   `json:"model" validate:"required"`
	Query           string   `json:"query" validate:"required"`
	ReturnDocuments *bool    `json:"return_documents,omitempty"`
	TopN            *int     `json:"top_n,omitempty"`
}

func (*RerankReq) Check added in v0.1.3

func (req *RerankReq) Check() error

func (*RerankReq) Data added in v0.1.5

func (req *RerankReq) Data() (map[string]interface{}, error)

type RerankResp added in v0.1.3

type RerankResp struct {
	Results   []Result `json:"results" validate:"required,dive"`
	Model     string   `json:"model"`
	Object    *string  `json:"object,omitempty"`
	Usage     Usage    `json:"usage"`
	RequestId *string  `json:"request_id,omitempty"`
}

type Result added in v0.1.3

type Result struct {
	Index          int       `json:"index"`
	Document       *Document `json:"document,omitempty"`
	RelevanceScore float64   `json:"relevance_score" validate:"required"`
}

type StreamOptions added in v0.1.4

type StreamOptions struct {
	IncludeUsage      *bool `json:"include_usage,omitempty"`
	ChunkIncludeUsage *bool `json:"chunk_include_usage,omitempty"`
}

type Tag added in v0.2.3

type Tag struct {
	Text string `json:"text"`
}

func GetTagsByContentSize added in v0.2.3

func GetTagsByContentSize(size *int) []Tag

func GetTagsByFunctionCall added in v0.2.3

func GetTagsByFunctionCall(fcType string) []Tag

type Thinking added in v0.1.4

type Thinking struct {
	Type string `json:"type" default:"enabled"`
}

type ToolCall added in v0.1.4

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

type ToolType added in v0.1.4

type ToolType string
const (
	ToolTypeFunction ToolType = "function"
)

type Usage added in v0.1.3

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

type VSType added in v0.2.3

type VSType string
const (
	VSTypeSupport   VSType = "support"
	VSTypeNoSupport VSType = "noSupport"
)

type WebSearch added in v0.1.4

type WebSearch struct {
	Enable         *bool `json:"enable,omitempty"`
	EnableCitation *bool `json:"enable_citation,omitempty"`
	EnableTrace    *bool `json:"enable_trace,omitempty"`
	EnableStatus   *bool `json:"enable_status,omitempty"`
}

Jump to

Keyboard shortcuts

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