-
Notifications
You must be signed in to change notification settings - Fork 527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Add Spark llm support for plugins/ai-proxy #1139
Conversation
因为你是用 sparkAuthKey 和 sparkAuthSecret 来设置 Authorization Header 的,没有用到 apiTokens。 |
// Copied from request_helper::insertContextMessage | ||
fileMessage := chatMessage{ | ||
Role: roleSystem, | ||
Content: content, | ||
} | ||
var firstNonSystemMessageIndex int | ||
for i, message := range request.Messages { | ||
if message.Role != roleSystem { | ||
firstNonSystemMessageIndex = i | ||
break | ||
} | ||
} | ||
if firstNonSystemMessageIndex == 0 { | ||
request.Messages = append([]chatMessage{fileMessage}, request.Messages...) | ||
} else { | ||
request.Messages = append(request.Messages[:firstNonSystemMessageIndex], append([]chatMessage{fileMessage}, request.Messages[firstNonSystemMessageIndex:]...)...) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里为什么要拷贝 insertContextMessage 函数里的内容,而不是直接调用 insertContextMessage 函数呢?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
因为我看insertContextMessage
的参数要求是chatCompletionRequest
,而不是我自定义的sparkRequest
。我的理解是chatCompletionRequest
是属于OpenAI
协议的请求对象吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
抱歉,似乎没能成功添加system prompt
这个问题似乎是星火的Lite
模型没有利用到system prompt
,我刚试出来openai
和spark
两种协议下Lite
模型都没有变成system prompt
中设置的角色,改为Max
模型就成功变了。之前没发现这个可能是Max的回答被缓存再利用了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
光从回答的内容看不出 system role是不是成功设置了,就算是使用 max,有时候回答也看不出来。
curl -i -k -X POST 'https://spark-api-open.xf-yun.com/v1/chat/completions' \
--header 'Authorization: Bearer <APIKEY>:<APISECERT>' \
--header 'Content-Type: application/json' \
--data '{
"model":"generalv3.5",
"messages": [
{
"role": "system",
"content": "你是一名专业的翻译!"
},
{
"role": "user",
"content": "你是谁?"
}
]
}'
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 588
Connection: keep-alive
Access-Control-Allow-Origin: *
Cache-Control: no-cache
Date: Fri, 26 Jul 2024 00:42:58 GMT
X-Kong-Upstream-Latency: 6252
X-Kong-Proxy-Latency: 1
Via: kong/1.3.0
{"code":0,"message":"Success","sid":"cha000c7216@dx190ec7d9771b8f2532","choices":[{"message":{"role":"assistant","content":"您好,我是讯飞星火认知大模型,由科大讯飞构建。\n作为一款先进的认知智能大模型,我的设计宗旨在于模仿人类的认知过程,以便更自然地与人交流、解决问题,并在各种领域内提供智能支持。我的能力覆盖了从语言理解到复杂问题解答的广泛范围,旨在帮助用户高效完成各类任务。"},"index":0}],"usage":{"prompt_tokens":8,"completion_tokens":76,"total_tokens":84}}%
我重新修改了一下,移除了spark的authKey和authSecret。但我在本地如果不重新 |
@cr7258 非常感谢您的耐心review!根据您的建议我进行了修改
除此之外,虽然是否返回调用的模型名是大模型厂商应该做的,我还是根据用户的 |
这个我觉得可以不用处理,因为星火的原始响应里面没有包含 model 信息,所以我们只能根据用户设置的 model参数来设置响应的 model。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐉 LGTM
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1139 +/- ##
==========================================
+ Coverage 35.91% 36.03% +0.12%
==========================================
Files 69 69
Lines 11576 9483 -2093
==========================================
- Hits 4157 3417 -740
+ Misses 7104 5750 -1354
- Partials 315 316 +1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Ⅰ. Describe what this PR did
Support SparkLLM ai model, api documentation: https://www.xfyun.cn/doc/spark/HTTP%E8%B0%83%E7%94%A8%E6%96%87%E6%A1%A3.html
Ⅱ. Does this pull request fix one issue?
fixes #949
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
go mod tidy tinygo build -o plugin.wasm -scheduler=none -target=wasi -gc=custom -tags="custommalloc nottinygc_finalizer" ./main.go sudo docker compose up
回复
回复
envoy.yaml
的provider
下添加"protocol":"original"
,然后重新运行build.sh
。注意model
要为星火认知大模型的真实名称,模型名称参考https://www.xfyun.cn/doc/spark/HTTP%E8%B0%83%E7%94%A8%E6%96%87%E6%A1%A3.html#_3-%E8%AF%B7%E6%B1%82%E8%AF%B4%E6%98%8E)回复
回复
Ⅴ. Special notes for reviews
我有一些问题:
envoy.yaml
中没有放入真实可用的key和secret,如果有需要的话,我可以重新修改这个pr的文本内容。system prompt
。编程中用到了通义灵码的代码优化建议