llm_old/README.md

137 lines
2.0 KiB
Markdown
Raw Normal View History

2024-10-02 14:09:54 +08:00
# AI大模型低代码工具
## 命令行工具
### Install
```shell
go install apigo.cc/ai/llm/llm-cli@latest
```
### Usage
```shell
llm-cli -h | help show usage
llm-cli -e | export export ai.ts file for develop
llm-cli test.js run test.js, if not specified, run ai.js
llm-cli -w | watch test.js run test.js, if .js files changed will be reloaded
```
### Sample
#### test.js
```javascript
2024-10-12 14:37:11 +08:00
import {zhipu} from 'apigo.cc/ai/llm'
import console from 'apigo.cc/gojs/console'
2024-10-02 14:09:54 +08:00
function main(...args) {
let r = zhipu.fastAsk((args.length>0?args[0]:'你好', r => {
console.print(r)
})
console.println()
return r
}
```
#### run sample
```shell
llm-cli test.js "你好"
```
### Configure
#### env.yml
```yaml
llm:
openai:
default:
apiKey: ...
aurze:
apiKey: ...
endpoint: ...
zhipu:
default:
apiKey: ...
```
#### encrypt apiKey
install sskey
```shell
go install github.com/ssgo/tool/sskey@latest
sskey -e 'your apiKey'
```
copy url base64 format encrypted apiKey into llm.yml or env.yml
2024-10-12 14:37:11 +08:00
## 将 [llm](https://apigo.cc/ai/llm) 和 [低代码](https://apigo.cc/gojs) 集成到应用
2024-10-02 14:09:54 +08:00
### Install
```shell
2024-10-12 14:37:11 +08:00
go get -u apigo.cc/gojs
2024-10-02 14:09:54 +08:00
go get -u apigo.cc/ai/llm
```
### Usage
```go
package main
import (
_ "apigo.cc/ai/llm"
2024-10-12 14:37:11 +08:00
"apigo.cc/gojs"
_ "apigo.cc/gojs/console"
2024-10-02 14:09:54 +08:00
)
func main() {
result, err := gojs.Run(`return llm.zhipu.fastAsk('你好', console.print)`, "")
if err != nil {
fmt.Println(err.Error())
} else if result != nil {
fmt.Println(result)
}
}
```
## 调用 Go API
### Install
```shell
go get -u apigo.cc/ai/llm
```
### Usage
```go
package main
import (
"apigo.cc/ai/llm/llm"
"fmt"
)
func main() {
zhipu := llm.Get("zhipu")
r, usage, err := zhipu.FastAsk(llm.Messages().User().Text("你是什么模型").Make(), func(text string) {
fmt.Print(text)
})
if err != nil {
fmt.Println(err)
} else {
fmt.Println()
fmt.Println("result:", r)
fmt.Println("usage:", usage)
}
}
```