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: Client support chatdata #1343

Merged
merged 5 commits into from
Mar 28, 2024
Merged

feat: Client support chatdata #1343

merged 5 commits into from
Mar 28, 2024

Conversation

Aries-ckt
Copy link
Collaborator

@Aries-ckt Aries-ckt commented Mar 27, 2024

Description

Close #1328

  1. Add datasource api v2
  2. Client Support chatdata
  3. Add examples and docs

How Has This Been Tested?

1.python dbgpt/app/dbgpt_server.py
2. add datasource called dbgpt
image

Curl

DBGPT_API_KEY=dbgpt

curl -X POST "http://localhost:5000/api/v2/chat/completions" \
    -H "Authorization: Bearer $DBGPT_API_KEY" \
    -H "accept: application/json" \
    -H "Content-Type: application/json" \
    -d "{\"messages\":\"show spaces data limit 5\",\"model\":\"chatgpt_proxyllm\",\"chat_mode\":\"chat_data\",\"chat_param\":\"dbgpt\",\"stream\":false}"
{
    "id": "2bb80fdd-e47e-4083-8bc9-7ca66ee0931b",
    "object": "chat.completion",
    "created": 1711509733,
    "model": "chatgpt_proxyllm",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "The user wants to display information about knowledge spaces with a limit of 5 results.\\n<chart-view content=\"{\"type\": \"response_table\", \"sql\": \"SELECT * FROM knowledge_space LIMIT 5\", \"data\": [{\"id\": 5, \"name\": \"frfrw\", \"vector_type\": \"Chroma\", \"desc\": \"eee\", \"owner\": \"eee\", \"context\": null, \"gmt_created\": \"2024-01-02T13:29:52\", \"gmt_modified\": \"2024-01-02T13:29:52\", \"description\": null}, {\"id\": 7, \"name\": \"acc\", \"vector_type\": \"Chroma\", \"desc\": \"dede\", \"owner\": \"dede\", \"context\": null, \"gmt_created\": \"2024-01-02T13:47:01\", \"gmt_modified\": \"2024-01-02T13:47:01\", \"description\": null}, {\"id\": 8, \"name\": \"bcc\", \"vector_type\": \"Chroma\", \"desc\": \"dede\", \"owner\": \"dede\", \"context\": null, \"gmt_created\": \"2024-01-02T14:22:02\", \"gmt_modified\": \"2024-01-02T14:22:02\", \"description\": null}, {\"id\": 9, \"name\": \"dede\", \"vector_type\": \"Chroma\", \"desc\": \"dede\", \"owner\": \"dede\", \"context\": null, \"gmt_created\": \"2024-01-02T14:36:18\", \"gmt_modified\": \"2024-01-02T14:36:18\", \"description\": null}, {\"id\": 10, \"name\": \"qqq\", \"vector_type\": \"Chroma\", \"desc\": \"dede\", \"owner\": \"dede\", \"context\": null, \"gmt_created\": \"2024-01-02T14:40:56\", \"gmt_modified\": \"2024-01-02T14:40:56\", \"description\": null}]}\" />"
            },
            "finish_reason": null
        }
    ],
    "usage": {
        "prompt_tokens": 0,
        "total_tokens": 0,
        "completion_tokens": 0
    }
}

Python

from dbgpt.client import Client

DBGPT_API_KEY = "dbgpt"
DB_NAME="dbgpt"

client = Client(api_key=DBGPT_API_KEY)
res = client.chat(
    messages="show space datas limit 5", 
    model="chatgpt_proxyllm", 
    chat_mode="chat_data", 
    chat_param=DB_NAME
)

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 27, 2024
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+

(dbgpt_env) magic@B-4TMH9N3X-2120 DB-GPT % curl -X POST "http://localhost:5000/api/v2/chat/completions" \
    -H "Authorization: Bearer $DBGPT_API_KEY" \
    -H "accept: application/json" \
    -H "Content-Type: application/json" \
    -d "{\"messages\":\"query  user counts\",\"model\":\"proxyllm\",\"chat_mode\":\"chat_data\",\"chat_param\":\"dbgpt_test\",\"stream\":false}"

results

{"id":"13358aad-e2cc-43fc-8eb0-4a97f05f490c","object":"chat.completion","created":1711543056,"model":"proxyllm","choices":[{"index":0,"message":{"role":"assistant","content":"用户问题是查询用户数量,可以使用COUNT函数来统计用户表中的记录数。\\n<chart-view content=\"{\"type\": \"response_table\", \"sql\": \"SELECT COUNT(*) AS user_counts FROM user\", \"data\": [{\"user_counts\": 25}]}\" />"},"finish_reason":null}],"usage":{"prompt_tokens":0,"total_tokens":0,"completion_tokens":0}}%

Copy link
Collaborator

@fangyinc fangyinc left a comment

Choose a reason for hiding this comment

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

LGTM.

@fangyinc fangyinc merged commit dffd235 into main Mar 28, 2024
4 checks passed
@Aries-ckt Aries-ckt deleted the feat_client_db branch March 29, 2024 03:53
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.

Does version 0.5.2 support the Python SDK for chat_db?
3 participants
  翻译: