ai/plugin.go
2024-09-09 00:01:35 +08:00

56 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package ai
import (
"apigo.cc/ai/agent"
"apigo.cc/ai/ai"
"apigo.cc/apigo/plugin"
"github.com/ssgo/u"
)
func init() {
plugin.Register(plugin.Plugin{
Id: "apigo.cc/apigo/ai",
Name: "",
Objects: map[string]interface{}{
"getAgent": func(name string) agent.Agent {
return ai.GetAgent(name)
},
"messages": func() *ai.MessagesMaker {
return ai.Messages()
},
},
ConfigSample: `zhipu: # 代理名称
apiKey: xxxx # API密钥
ai01: # 自定义名称
apiKey: xxxx # API密钥
endpoint: https://xxxx # 可以指定一个接入点(例如代理)
agent: zhipu # 当名称不是代理ID时需指定
chatConfig # 默认的模型配置
model: GLM-4V # 模型名称
maxTokens: 1000 # 最大Token数
temperature: 0.8 # 生成文本时使用的随机性参数
topP: 0.7 # 生成文本时使用的随机性参数
tools: # 工具列表
codeInterpreter: # 代码解释器(不需要指定值)
webSearch: # 联网搜索(不需要指定值)
`,
Init: func(config map[string]interface{}) {
for agentName, conf1 := range config {
conf := ai.AgentConfig{}
u.Convert(conf1, &conf)
agent.CreateAgent(agentName, conf.Agent, agent.APIConfig{
Endpoint: conf.Endpoint,
ApiKey: conf.Endpoint,
DefaultChatModelConfig: agent.ChatModelConfig{
Model: conf.ChatConfig.Model,
MaxTokens: conf.ChatConfig.MaxTokens,
Temperature: conf.ChatConfig.Temperature,
TopP: conf.ChatConfig.TopP,
Tools: conf.ChatConfig.Tools,
},
})
}
},
})
}