torchchat icon indicating copy to clipboard operation
torchchat copied to clipboard

OpenAI API JSON formatted

Open vmpuri opened this issue 1 year ago • 2 comments

Implement JSON formatted responses using OpenAI API types for server completion requests. Rather than giving single tokens at a time, the server will respond with a JSON following the API dataclasses corresponding to OpenAI API types.

Testing: Server

python3 torchchat.py server stories15M   

Request (chunked)

curl http://127.0.0.1:5000/chat \
  -H "Content-Type: application/json" \
  -d '{
    "model": "stories15M",
    "stream": "true",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "Story about a dog."
      }
    ]

Request (synchronous)

curl http://127.0.0.1:5000/chat \
  -H "Content-Type: application/json" \
  -d '{
    "model": "stories15M",
    "stream": "false",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "Story about a dog."
      }
    ]

https://github.com/user-attachments/assets/1171db63-094b-4313-a1c6-76d042ceefca

vmpuri avatar Aug 01 '24 21:08 vmpuri

:link: Helpful Links

:test_tube: See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchchat/995

Note: Links to docs will display an error until the docs builds have been completed.

:white_check_mark: No Failures

As of commit 0d3a5c394a10f0e5e1a7d4590067fbd2083db4c9 with merge base a3bf37d0dbac56c8c747e0610c1e2403cd386dc6 (image): :green_heart: Looks good so far! There are no failures yet. :green_heart:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

pytorch-bot[bot] avatar Aug 01 '24 21:08 pytorch-bot[bot]

Can you add a video for non-chunked as well for record purposes

Jack-Khuu avatar Aug 01 '24 21:08 Jack-Khuu