kefu/lib/ERNIE-Bot-turbo_test.go

46 lines
1.7 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 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)
}