Documentation
¶
Overview ¶
Copyright 2024 The OpenAgent Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func AddPrices(price1 float64, price2 float64) float64
- func CalculateOpenAIModelPrice(model string, modelResult *ModelResult, lang string) error
- func ChatCompletionRequest(model string, messages []openai.ChatCompletionMessage, temperature float32, ...) openai.ChatCompletionRequest
- func GenaiRawMessagesToMessages(question string, history []*RawMessage) []*genai.Content
- func GetOpenAiClientFromToken(authToken string) openai.Client
- func GetOpenAiMaxTokens(model string) int
- func GetTokenSize(model string, prompt string) (int, error)
- func IsVisionModel(subType string) bool
- func NewiFlytekModelProvider(subType string, secretKey string, temperature float32) (*iFlytekModelProvider, error)
- func OpenaiNumTokensFromMessages(messages []openai.ChatCompletionMessage, model string) (int, error)
- func OpenaiRawMessagesToGptVisionMessages(messages []*RawMessage) ([]openai.ChatCompletionMessage, error)
- func OpenaiRawMessagesToMessages(messages []*RawMessage) []openai.ChatCompletionMessage
- func RefinePrice(price float64) float64
- type AgentInfo
- type AgentMessages
- type AlibabacloudModelProvider
- type AmazonBedrockModelProvider
- type BaichuanModelProvider
- type BaiduCloudModelProvider
- type ChatGLMModelProvider
- type ChatMessage
- type ClaudeModelProvider
- type CohereModelProvider
- type DeepSeekProvider
- type DummyModelProvider
- type GeminiModelProvider
- type GitHubModelProvider
- type GrokModelProvider
- type HuggingFaceModelProvider
- type LocalModelProvider
- type MiniMaxModelProvider
- type MistralModelProvider
- type ModelProvider
- type ModelResult
- type MoonshotModelProvider
- type OpenAiModelProvider
- type OpenRouterModelProvider
- type RawMessage
- type SearchResult
- type SiliconFlowProvider
- type StepFunModelProvider
- type TencentCloudClient
- type ToolCall
- type ToolCallResponse
- type VolcengineModelProvider
- type WriterModelProvider
- type YiProvider
Constants ¶
const DryRunPrefix = "$OpenAgentDryRun$"
DryRunPrefix is a special prefix that triggers model providers to estimate token count and price without actually calling the AI model APIs.
Variables ¶
var CohereDefaultTemperature float64 = 0.75
https://docs.cohere.com/docs/command-beta#whats-the-context-window-on-the-command-models
Functions ¶
func CalculateOpenAIModelPrice ¶
func CalculateOpenAIModelPrice(model string, modelResult *ModelResult, lang string) error
func ChatCompletionRequest ¶
func ChatCompletionRequest(model string, messages []openai.ChatCompletionMessage, temperature float32, topP float32, frequencyPenalty float32, presencePenalty float32) openai.ChatCompletionRequest
func GenaiRawMessagesToMessages ¶
func GenaiRawMessagesToMessages(question string, history []*RawMessage) []*genai.Content
func GetOpenAiMaxTokens ¶
GetOpenAiMaxTokens returns the max tokens for a given OpenAI model.
func IsVisionModel ¶
func NewiFlytekModelProvider ¶
func OpenaiNumTokensFromMessages ¶
func OpenaiNumTokensFromMessages(messages []openai.ChatCompletionMessage, model string) (int, error)
https://github.com/pkoukk/tiktoken-go?tab=readme-ov-file#counting-tokens-for-chat-api-calls https://github.com/sashabaranov/go-openai/pull/223#issuecomment-1608689882
func OpenaiRawMessagesToGptVisionMessages ¶
func OpenaiRawMessagesToGptVisionMessages(messages []*RawMessage) ([]openai.ChatCompletionMessage, error)
func OpenaiRawMessagesToMessages ¶
func OpenaiRawMessagesToMessages(messages []*RawMessage) []openai.ChatCompletionMessage
func RefinePrice ¶
Types ¶
type AgentInfo ¶
type AgentInfo struct {
AgentClients *agent.AgentClients
AgentMessages *AgentMessages
}
type AgentMessages ¶
type AgentMessages struct {
Messages []*RawMessage
ToolCalls any
}
type AlibabacloudModelProvider ¶
type AlibabacloudModelProvider struct {
// contains filtered or unexported fields
}
func (*AlibabacloudModelProvider) GetPricing ¶
func (p *AlibabacloudModelProvider) GetPricing() string
func (*AlibabacloudModelProvider) QueryText ¶
func (p *AlibabacloudModelProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type AmazonBedrockModelProvider ¶
type AmazonBedrockModelProvider struct {
// contains filtered or unexported fields
}
func NewAmazonBedrockModelProvider ¶
func NewAmazonBedrockModelProvider(subType string, secretKey string, temperature float64) (*AmazonBedrockModelProvider, error)
func (AmazonBedrockModelProvider) GetPricing ¶
func (a AmazonBedrockModelProvider) GetPricing() string
func (*AmazonBedrockModelProvider) QueryText ¶
func (p *AmazonBedrockModelProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type BaichuanModelProvider ¶
type BaichuanModelProvider struct {
// contains filtered or unexported fields
}
func (*BaichuanModelProvider) GetPricing ¶
func (p *BaichuanModelProvider) GetPricing() string
func (*BaichuanModelProvider) QueryText ¶
func (p *BaichuanModelProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type BaiduCloudModelProvider ¶
type BaiduCloudModelProvider struct {
// contains filtered or unexported fields
}
func (*BaiduCloudModelProvider) GetPricing ¶
func (p *BaiduCloudModelProvider) GetPricing() string
func (*BaiduCloudModelProvider) QueryText ¶
func (p *BaiduCloudModelProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type ChatGLMModelProvider ¶
type ChatGLMModelProvider struct {
// contains filtered or unexported fields
}
func NewChatGLMModelProvider ¶
func NewChatGLMModelProvider(subType string, clientSecret string) (*ChatGLMModelProvider, error)
func (*ChatGLMModelProvider) GetPricing ¶
func (c *ChatGLMModelProvider) GetPricing() string
func (*ChatGLMModelProvider) QueryText ¶
func (p *ChatGLMModelProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type ChatMessage ¶
type ClaudeModelProvider ¶
type ClaudeModelProvider struct {
// contains filtered or unexported fields
}
func NewClaudeModelProvider ¶
func (*ClaudeModelProvider) GetPricing ¶
func (p *ClaudeModelProvider) GetPricing() string
func (*ClaudeModelProvider) QueryText ¶
func (p *ClaudeModelProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type CohereModelProvider ¶
type CohereModelProvider struct {
// contains filtered or unexported fields
}
func NewCohereModelProvider ¶
func NewCohereModelProvider(subType string, secretKey string) (*CohereModelProvider, error)
func (*CohereModelProvider) GetPricing ¶
func (c *CohereModelProvider) GetPricing() string
GetPricing returns the pricing of the model https://cohere.com/pricing
func (*CohereModelProvider) QueryText ¶
func (p *CohereModelProvider) QueryText(message string, writer io.Writer, chat_history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type DeepSeekProvider ¶
type DeepSeekProvider struct {
// contains filtered or unexported fields
}
func NewDeepSeekProvider ¶
func (*DeepSeekProvider) GetPricing ¶
func (p *DeepSeekProvider) GetPricing() string
func (*DeepSeekProvider) QueryText ¶
func (p *DeepSeekProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type DummyModelProvider ¶
type DummyModelProvider struct {
// contains filtered or unexported fields
}
func NewDummyModelProvider ¶
func NewDummyModelProvider(subType string) (*DummyModelProvider, error)
func (*DummyModelProvider) GetPricing ¶
func (c *DummyModelProvider) GetPricing() string
func (*DummyModelProvider) QueryText ¶
func (p *DummyModelProvider) QueryText(message string, writer io.Writer, chat_history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type GeminiModelProvider ¶
type GeminiModelProvider struct {
// contains filtered or unexported fields
}
func NewGeminiModelProvider ¶
func (*GeminiModelProvider) GetPricing ¶
func (p *GeminiModelProvider) GetPricing() string
func (*GeminiModelProvider) QueryText ¶
func (p *GeminiModelProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type GitHubModelProvider ¶
type GitHubModelProvider struct {
*LocalModelProvider
}
func (*GitHubModelProvider) GetPricing ¶
func (p *GitHubModelProvider) GetPricing() string
type GrokModelProvider ¶
type GrokModelProvider struct {
// contains filtered or unexported fields
}
func NewGrokModelProvider ¶
func (*GrokModelProvider) GetPricing ¶
func (p *GrokModelProvider) GetPricing() string
func (*GrokModelProvider) QueryText ¶
func (p *GrokModelProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type HuggingFaceModelProvider ¶
type HuggingFaceModelProvider struct {
// contains filtered or unexported fields
}
func NewHuggingFaceModelProvider ¶
func NewHuggingFaceModelProvider(subType string, secretKey string, temperature float32) (*HuggingFaceModelProvider, error)
func (*HuggingFaceModelProvider) GetPricing ¶
func (p *HuggingFaceModelProvider) GetPricing() string
func (*HuggingFaceModelProvider) QueryText ¶
func (p *HuggingFaceModelProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type LocalModelProvider ¶
type LocalModelProvider struct {
// contains filtered or unexported fields
}
func NewAzureModelProvider ¶
func NewLocalModelProvider ¶
func NewLocalModelProvider(typ string, subType string, secretKey string, temperature float32, topP float32, frequencyPenalty float32, presencePenalty float32, providerUrl string, compatibleProvider string, inputPricePerThousandTokens float64, outputPricePerThousandTokens float64, Currency string) (*LocalModelProvider, error)
func (*LocalModelProvider) CalculatePrice ¶
func (p *LocalModelProvider) CalculatePrice(modelResult *ModelResult, lang string) error
func (*LocalModelProvider) GetPricing ¶
func (p *LocalModelProvider) GetPricing() string
func (*LocalModelProvider) QueryText ¶
func (p *LocalModelProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type MiniMaxModelProvider ¶
type MiniMaxModelProvider struct {
// contains filtered or unexported fields
}
func NewMiniMaxModelProvider ¶
func (*MiniMaxModelProvider) GetPricing ¶
func (p *MiniMaxModelProvider) GetPricing() string
func (*MiniMaxModelProvider) QueryText ¶
func (p *MiniMaxModelProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type MistralModelProvider ¶
type MistralModelProvider struct {
// contains filtered or unexported fields
}
func NewMistralProvider ¶
func NewMistralProvider(apiKey, modelName string) (*MistralModelProvider, error)
func (*MistralModelProvider) GetPricing ¶
func (c *MistralModelProvider) GetPricing() string
func (*MistralModelProvider) QueryText ¶
func (c *MistralModelProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type ModelProvider ¶
type ModelProvider interface {
GetPricing() string
QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
}
func GetModelProvider ¶
func GetModelProvider(typ string, subType string, clientId string, clientSecret string, userKey string, temperature float32, topP float32, topK int, frequencyPenalty float32, presencePenalty float32, providerUrl string, apiVersion string, compatibleProvider string, inputPricePerThousandTokens float64, outputPricePerThousandTokens float64, Currency string, enableThinking bool) (ModelProvider, error)
type ModelResult ¶
type ModelResult struct {
PromptTokenCount int
ResponseTokenCount int
TotalTokenCount int
ImageCount int
TotalPrice float64
Currency string
}
func QueryTextWithTools ¶
func QueryTextWithTools(p ModelProvider, question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type MoonshotModelProvider ¶
type MoonshotModelProvider struct {
// contains filtered or unexported fields
}
func (*MoonshotModelProvider) GetPricing ¶
func (p *MoonshotModelProvider) GetPricing() string
func (*MoonshotModelProvider) QueryText ¶
func (p *MoonshotModelProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type OpenAiModelProvider ¶
type OpenAiModelProvider struct {
// contains filtered or unexported fields
}
func NewOpenAiModelProvider ¶
func (*OpenAiModelProvider) GetPricing ¶
func (p *OpenAiModelProvider) GetPricing() string
func (*OpenAiModelProvider) QueryText ¶
func (p *OpenAiModelProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type OpenRouterModelProvider ¶
type OpenRouterModelProvider struct {
// contains filtered or unexported fields
}
func (*OpenRouterModelProvider) GetPricing ¶
func (p *OpenRouterModelProvider) GetPricing() string
func (*OpenRouterModelProvider) QueryText ¶
func (p *OpenRouterModelProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type RawMessage ¶
type RawMessage struct {
Text string
Author string
TextTokenCount int
ToolCall openai.ToolCall
ToolCallID string
}
func OpenaiGenerateMessages ¶
func OpenaiGenerateMessages(prompt string, question string, recentMessages []*RawMessage, knowledgeMessages []*RawMessage, model string, maxTokens int, lang string) ([]*RawMessage, error)
type SearchResult ¶
type SiliconFlowProvider ¶
type SiliconFlowProvider struct {
// contains filtered or unexported fields
}
func NewSiliconFlowProvider ¶
func (*SiliconFlowProvider) GetPricing ¶
func (p *SiliconFlowProvider) GetPricing() string
func (*SiliconFlowProvider) QueryText ¶
func (p *SiliconFlowProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type StepFunModelProvider ¶
type StepFunModelProvider struct {
// contains filtered or unexported fields
}
func NewStepFunModelProvider ¶
func (*StepFunModelProvider) GetPricing ¶
func (p *StepFunModelProvider) GetPricing() string
func (*StepFunModelProvider) QueryText ¶
func (p *StepFunModelProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type TencentCloudClient ¶
type TencentCloudClient struct {
// contains filtered or unexported fields
}
func NewTencentCloudProvider ¶
func NewTencentCloudProvider(secretKey, endpoint, subType string, temperature, topP float32) (*TencentCloudClient, error)
func (*TencentCloudClient) GetPricing ¶
func (c *TencentCloudClient) GetPricing() string
func (*TencentCloudClient) QueryText ¶
func (c *TencentCloudClient) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type ToolCall ¶
type ToolCall struct {
Name string `json:"name"`
Arguments string `json:"arguments"`
Content string `json:"content"`
}
func GetToolCallsFromWriter ¶
type ToolCallResponse ¶
type VolcengineModelProvider ¶
type VolcengineModelProvider struct {
// contains filtered or unexported fields
}
func (*VolcengineModelProvider) GetPricing ¶
func (p *VolcengineModelProvider) GetPricing() string
func (*VolcengineModelProvider) QueryText ¶
func (p *VolcengineModelProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type WriterModelProvider ¶
type WriterModelProvider struct {
// contains filtered or unexported fields
}
func NewWriterModelProvider ¶
func (*WriterModelProvider) GetPricing ¶
func (p *WriterModelProvider) GetPricing() string
func (*WriterModelProvider) QueryText ¶
func (p *WriterModelProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
type YiProvider ¶
type YiProvider struct {
// contains filtered or unexported fields
}
func NewYiProvider ¶
func (*YiProvider) GetPricing ¶
func (p *YiProvider) GetPricing() string
func (*YiProvider) QueryText ¶
func (p *YiProvider) QueryText(question string, writer io.Writer, history []*RawMessage, prompt string, knowledgeMessages []*RawMessage, agentInfo *AgentInfo, lang string) (*ModelResult, error)
Source Files
¶
- alibabacloud.go
- amazon_bedrock.go
- azure_openai.go
- baichuan.go
- baiducloud.go
- chatglm.go
- claude.go
- cohere.go
- context_length_util.go
- deepseek.go
- dummy.go
- gemini.go
- gemini_util.go
- github.go
- grok.go
- huggingface.go
- iflytek.go
- local.go
- local_gptvision.go
- mcp.go
- minimax.go
- mistral.go
- moonshot.go
- openai.go
- openai_util.go
- openrouter.go
- provider.go
- silicon_flow.go
- stepfun.go
- tencentcloud.go
- util.go
- volcengine.go
- writer.go
- yi.go