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

OpenAI API JSON formatted #995

Merged
merged 3 commits into from
Aug 5, 2024
Merged

OpenAI API JSON formatted #995

merged 3 commits into from
Aug 5, 2024

Conversation

vmpuri
Copy link
Contributor

@vmpuri vmpuri commented Aug 1, 2024

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."
      }
    ]
Screen.Recording.2024-08-02.at.1.22.21.PM.mov

@vmpuri vmpuri self-assigned this Aug 1, 2024
Copy link

pytorch-bot bot commented Aug 1, 2024

🔗 Helpful Links

🧪 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.

✅ No Failures

As of commit 0d3a5c3 with merge base a3bf37d (image):
💚 Looks good so far! There are no failures yet. 💚

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

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 1, 2024
@vmpuri vmpuri requested review from byjlw and Jack-Khuu August 1, 2024 21:51
@Jack-Khuu
Copy link
Contributor

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

Copy link
Contributor

@Jack-Khuu Jack-Khuu left a comment

Choose a reason for hiding this comment

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

Some nits, but the content lgtm

Remember to verify the behavior lines up with how people plan on using OpenAI

Comment on lines +222 to +235
self.system_fingerprint = (
self.builder_args.device + type(self.builder_args.precision).__name__
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a comment that this field doesn't match the spec, but is populated

We'll fix in a separate PR

server.py Outdated Show resolved Hide resolved
server.py Outdated
Comment on lines 68 to 69
nextok = chunk.choices[0].delta.content
nextok = nextok if nextok is not None else ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
nextok = chunk.choices[0].delta.content
nextok = nextok if nextok is not None else ""
if (next_tok := chunk.choices[0].delta.content) is None:
next_tok = ""

@vmpuri vmpuri force-pushed the openai_api_patches branch from 8472f6d to 975a817 Compare August 2, 2024 20:26
@vmpuri vmpuri mentioned this pull request Aug 2, 2024
@vmpuri vmpuri force-pushed the openai_api_patches branch from 975a817 to 6401f55 Compare August 5, 2024 21:47
@vmpuri vmpuri force-pushed the openai_api_patches branch from 6401f55 to 4e26b22 Compare August 5, 2024 21:49
@vmpuri vmpuri merged commit dea8d60 into main Aug 5, 2024
51 checks passed
@vmpuri vmpuri linked an issue Aug 6, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Open AI API Maturity
4 participants