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: APIServer supports embeddings #1256

Merged
merged 5 commits into from
Mar 5, 2024

Conversation

fangyinc
Copy link
Collaborator

@fangyinc fangyinc commented Mar 5, 2024

Description

API Server adds embedding API compatible with OpenAI embeddings

Others:

  • Support load documents with multi-threadeds
  • New OpenAPIEmbeddings

How Has This Been Tested?

Test embeddings API

  1. Start DB-GPT's API Server according OpenAI SDK Calls Local Multi-model

  2. Test with cURL

curl http://127.0.0.1:8100/api/v1/embeddings \
-H "Authorization: Bearer EMPTY" \
-H "Content-Type: application/json" \
-d '{
    "model": "text2vec",
    "input": "Hello world!"
}'

Test OpenAPIEmbeddings

  from dbgpt.rag.embedding import OpenAPIEmbeddings

  openai_embeddings = OpenAPIEmbeddings(
      api_url="http://localhost:8100/api/v1/embeddings",
      api_key="EMPTY",
      model_name="text2vec",
  )
  texts = ["Hello, world!", "How are you?"]
  openai_embeddings.embed_documents(texts)

Snapshots:

Include snapshots for easier review.

Checklist:

  • My code follows the style guidelines of this project
  • I have already rebased the commits and make the commit message conform to the project standard.
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • Any dependent changes have been merged and published in downstream modules

@github-actions github-actions bot added the enhancement New feature or request label Mar 5, 2024
@Aries-ckt
Copy link
Collaborator

Aries-ckt commented Mar 5, 2024

Test embeddings API

How to usage?

# 1. at first start controller 
dbgpt start controller

# 2. second start embedding model worker
dbgpt start worker --model_name text2vec \
--model_path /app/models/text2vec-large-chinese \
--worker_type text2vec \
--port 8003 \
--controller_addr http://127.0.0.1:8000

# 3. start apiserver 
dbgpt start apiserver --controller_addr http://127.0.0.1:8000 --api_keys EMPTY

# 4. test
curl http://127.0.0.1:8100/api/v1/embeddings \
-H "Authorization: Bearer EMPTY" \
-H "Content-Type: application/json" \
-d '{
    "model": "text2vec",
    "input": "Hello world!"
}'

image

Copy link
Collaborator

@csunny csunny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+, test good

image

Copy link
Collaborator

@Aries-ckt Aries-ckt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Aries-ckt Aries-ckt merged commit 74ec8e5 into eosphoros-ai:main Mar 5, 2024
3 checks passed
@fangyinc fangyinc mentioned this pull request Mar 6, 2024
6 tasks
csunny pushed a commit that referenced this pull request Mar 7, 2024
Hopshine pushed a commit to Hopshine/DB-GPT that referenced this pull request Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants