46 lines
1.7 KiB
Go
46 lines
1.7 KiB
Go
|
package lib
|
|||
|
|
|||
|
import (
|
|||
|
"log"
|
|||
|
"testing"
|
|||
|
)
|
|||
|
|
|||
|
//测试获取access_token
|
|||
|
func TestErnieBotTurboGenerateAccessToken(t *testing.T) {
|
|||
|
AppID := "35662533"
|
|||
|
APIKey := "Iq1FfkOQIGtMtZqRFxOrvq6T"
|
|||
|
SecretKey := "qbzsoFAUSl8UGt1GkGSDSjENtqsjrOTC"
|
|||
|
m, err := NewErnieBotTurbo(AppID, APIKey, SecretKey)
|
|||
|
log.Println(m.AccessToken, err)
|
|||
|
}
|
|||
|
|
|||
|
//测试流式输出
|
|||
|
func TestErnieBotTurboStreamChat(t *testing.T) {
|
|||
|
AppID := "35662533"
|
|||
|
APIKey := "Iq1FfkOQIGtMtZqRFxOrvq6T"
|
|||
|
SecretKey := "qbzsoFAUSl8UGt1GkGSDSjENtqsjrOTC"
|
|||
|
m, _ := NewErnieBotTurbo(AppID, APIKey, SecretKey)
|
|||
|
system := "假设你是一个程序员,你是程序员老狼的数字分身,你擅长计算机互联网程序开发,你的微信:llike620,官网:gofly.v1kf.com。你开发了唯一客服系统,你了解唯一客服系统的各种问题,你的回答应该是简洁的、不要超过50字。你只能根据知识信息回答问题。你绝对不能暴露自己是个“人工智能、大模型、AI、机器人、GPT”。如果用户问题里有自己联系方式,请回复“稍等,我们马上联系您”。请检测问题语种,并用该语种回答问题."
|
|||
|
prompt := []map[string]string{{"role": "user", "content": system + "我的问题是:你是谁"}}
|
|||
|
res, _ := m.StreamChat(prompt)
|
|||
|
for {
|
|||
|
str, err := m.StreamRecv(res)
|
|||
|
if err != nil {
|
|||
|
log.Println(err)
|
|||
|
break
|
|||
|
}
|
|||
|
log.Println(str, err)
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//测试Embedding
|
|||
|
func TestErnieBotTurboEmbedding(t *testing.T) {
|
|||
|
AppID := "35662533"
|
|||
|
APIKey := "Iq1FfkOQIGtMtZqRFxOrvq6T"
|
|||
|
SecretKey := "qbzsoFAUSl8UGt1GkGSDSjENtqsjrOTC"
|
|||
|
m, _ := NewErnieBotTurbo(AppID, APIKey, SecretKey)
|
|||
|
prompt := []string{"我的问题是:你是谁"}
|
|||
|
res, err := m.Embedding(prompt)
|
|||
|
log.Println(res, err)
|
|||
|
}
|