Skip to content
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 gemini embeddings (text-embedding-004,embedding-001) #1475

Merged
merged 2 commits into from
May 28, 2024

Conversation

mxdlzg
Copy link
Contributor

@mxdlzg mxdlzg commented May 28, 2024

close #1313
close #868

我已确认该 PR 已自测通过,相关截图如下:
(此处放上测试通过的截图,如果不涉及前端改动或从 UI 上无法看出,请放终端启动成功的截图)

[SYS] 2024/05/28 - 14:34:52 | One API v0.0.0 started 
[SYS] 2024/05/28 - 14:34:52 | using MySQL as database 
[SYS] 2024/05/28 - 14:34:52 | database migration started 
[SYS] 2024/05/28 - 14:34:52 | database migrated 
[SYS] 2024/05/28 - 14:34:52 | REDIS_CONN_STRING not set, Redis is not enabled 
[SYS] 2024/05/28 - 14:34:52 | using theme berry 
[SYS] 2024/05/28 - 14:34:52 | initializing token encoders 
[SYS] 2024/05/28 - 14:34:57 | token encoders initialized 
[SYS] 2024/05/28 - 14:35:50 | model ratio not found: text-embedding-004 
[INFO] 2024/05/28 - 14:35:50 | 202405281435508260323702375031 | user 1 has enough quota 499999972164332, trusted and no need to pre-consume 
[GIN] 2024/05/28 - 14:35:50 | 202405281435508260323702375031 | 200 |  426.223764ms | ip |    POST /v1/embeddings
[INFO] 2024/05/28 - 14:35:50 | 202405281435508260323702375031 | record consume log: userId=1, channelId=4, promptTokens=0, completionTokens=0, modelName=text-embedding-004, tokenName=FastChat, quota=0, content=模型倍率 30.00,分组倍率 1.00,补全倍率 1.00 
[SYS] 2024/05/28 - 14:36:07 | model ratio not found: text-embedding-004 
[INFO] 2024/05/28 - 14:36:07 | 2024052814360737548440985902243 | user 1 has enough quota 499999972164332, trusted and no need to pre-consume 
[GIN] 2024/05/28 - 14:36:07 | 2024052814360737548440985902243 | 200 |  353.767544ms | ip |    POST /v1/embeddings
[INFO] 2024/05/28 - 14:36:07 | 2024052814360737548440985902243 | record consume log: userId=1, channelId=4, promptTokens=0, completionTokens=0, modelName=text-embedding-004, tokenName=FastChat, quota=0, content=模型倍率 30.00,分组倍率 1.00,补全倍率 1.00

模型名字在测试时有映射(google-text-embedding-004->text-embedding-004)
多条:
image
单条:
image

@mxdlzg mxdlzg marked this pull request as ready for review May 28, 2024 06:48
@songquanpeng songquanpeng merged commit 9321427 into songquanpeng:main May 28, 2024
@songquanpeng
Copy link
Owner

Thx~

sunls24 pushed a commit to sunls24/one-api that referenced this pull request Jun 22, 2024
…ongquanpeng#1475)

* Refactor Gemini Adaptor to Support Embeddings

* Add new models to ModelList

(cherry picked from commit 9321427)
@yoursbest
Copy link

@mxdlzg , @songquanpeng 你们好,

感谢提供gemini embedding的adaptor!

我发现一个问题,

  • 直接通过curl访问one-api可以完美进行embedding
  • 如果通过第三方工具或者langchain包来调用会失败,例如:
from langchain_openai import OpenAIEmbeddings


embeddings_model = OpenAIEmbeddings(
    openai_api_base=openai_api_base,
    openai_api_key=openai_api_key,
    model="text-embedding-004",
)

embeddings = embeddings_model.embed_query('hello')

出现错误 BadRequestError: Error code: 400 - {'error': {'message': '* BatchEmbedContentsRequest.requests: requests must not be empty\n (request id: 2024062618344384827435121138789)', 'type': '', 'param': '', 'code': 400}}

这个问题不知是否可以解决,谢谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants