just test

This commit is contained in:
STARAI\Star 2024-09-09 00:01:35 +08:00
commit 939b185d14
7 changed files with 155 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
.*
!.gitignore
go.sum
/build
/node_modules
/package.json

9
LICENSE Normal file
View File

@ -0,0 +1,9 @@
MIT License
Copyright (c) 2024 apigo
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

17
go.mod Normal file
View File

@ -0,0 +1,17 @@
module ai
go 1.22
toolchain go1.22.4
require (
apigo.cc/ai/agent v0.0.1
apigo.cc/ai/ai v0.0.1
apigo.cc/apigo/plugin v1.0.2
github.com/ssgo/u v1.7.7
)
require (
github.com/ssgo/config v1.7.7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

55
plugin.go Normal file
View File

@ -0,0 +1,55 @@
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,
},
})
}
},
})
}

24
tests/go.mod Normal file
View File

@ -0,0 +1,24 @@
module tests
go 1.22
toolchain go1.22.4
replace current-plugin v0.0.0 => ../
require (
apigo.cc/apigo/gojs v0.0.10
current-plugin v0.0.0
github.com/ssgo/u v1.7.7
)
require (
apigo.cc/ai/agent v0.0.1 // indirect
apigo.cc/ai/ai v0.0.1 // indirect
apigo.cc/apigo/plugin v1.0.2 // indirect
apigo.cc/apigo/quickjs-go v0.4.12 // indirect
github.com/ssgo/config v1.7.7 // indirect
github.com/ssgo/log v1.7.7 // indirect
github.com/ssgo/standard v1.7.7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

27
tests/plugin_test.go Normal file
View File

@ -0,0 +1,27 @@
package ai_test
import (
"apigo.cc/apigo/gojs"
_ "current-plugin"
"fmt"
"github.com/ssgo/u"
"os"
"strings"
"testing"
)
func TestPlugin(t *testing.T) {
if files, err := os.ReadDir("."); err == nil {
for _, f := range files {
if !f.IsDir() && strings.HasSuffix(f.Name(), "_test.js") {
testName := f.Name()[0 : len(f.Name())-8]
r, err := gojs.RunFile(f.Name(), nil)
if err != nil || r != true {
t.Fatal("test "+testName+" failed", r, err)
} else {
fmt.Println(u.Green("test "+testName), u.BGreen("OK"))
}
}
}
}
}

17
tests/plugin_test.js Normal file
View File

@ -0,0 +1,17 @@
import console from 'console'
import ai from 'ai'
// ai.set('aaa', 111)
// let aaa = ai.get('aaa')
// if (aaa !== 111) return 'set value error'
//
// try {
// ai.get('bbb')
// return 'no exception when getting non-existent key'
// } catch (ex){
// logger.error(ex.message, {stack:ex.stack})
// }
// logger.info('aaa')
// ai.remove('bbb')
//
return true