-
Notifications
You must be signed in to change notification settings - Fork 378
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: support claude ai model #969
base: main
Are you sure you want to change the base?
Conversation
此外,请解决冲突并同步更新 README.md。 |
Anthropic Claude AI 的 API 模型和 OpenAI 的好像不太一样。请确认能否适配。 |
@CH3CHO
2.处理 Claude 的响应格式,保持和 OpenAI 输出一样的格式和字段,例如: {
"id": "cmpl-e5ca873642ca4f5d8b178c1742f9a8e8",
"object": "chat.completion",
"created": 1872961,
"model": "moonshot-v1-128k",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "文案内容是关于一个名为“xxxx”的支付平台..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 11,
"completion_tokens": 498,
"total_tokens": 509
}
} |
我这边开发百度文心一言的时候,是参考的这个项目,有需要的话也可以参考下,https://github.com/songquanpeng/one-api/tree/91b80ae87945ed1a77b3507dd277ee9cdddaa0b4/relay/adaptor |
@hanxiantao 感谢,我研究一下 |
Signed-off-by: chengzw <chengzw258@163.com>
@CH3CHO PR 已经根据重新要求调整好了,请继续 review。测试的内容我更新在 PR 的描述里了 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #969 +/- ##
==========================================
- Coverage 35.97% 35.93% -0.04%
==========================================
Files 69 69
Lines 11514 11536 +22
==========================================
+ Hits 4142 4146 +4
- Misses 7056 7074 +18
Partials 316 316 |
使用 OpenAI 非流式请求协议的相应格式是不是有点问题?看上去前面都没有 data: 前缀。 能参考下面两篇文档的内容用 NextChat 或者 LobeChat 测一下对接情况吗? |
| `version` | string | 必填 | - | Claude 服务的 API 版本 | | ||
| 名称 | 数据类型 | 填写要求 | 默认值 | 描述 | | ||
|-----------|--------|------|-----|----------------------------------| | ||
| `version` | string | 可选 | - | Claude 服务的 API 版本,默认为 2023-06-01 | |
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.
这个字段建议在命名里就说明是 Anthropic Claude 用的。
Ⅰ. Describe what this PR did
Support calude ai model. Claude API documentation: https://docs.anthropic.com/en/api/messages
Ⅱ. Does this pull request fix one issue?
fixes #946
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
docker-compose.yaml
envoy.yaml
使用 OpenAI 协议
非流式请求
流式请求
stop
stop 接受一个 string 数组,当生成的内容遇到该词时,停止生成。(在 claude 中是 stop_sequence)
使用 Claude 协议
Claude Streaming 文档:https://docs.anthropic.com/en/api/messages-streaming#streaming-with-sdks
非流式请求
流式请求
stop_sequence
Ⅴ. Special notes for reviews