torchchat icon indicating copy to clipboard operation
torchchat copied to clipboard

OpenAI API JSON formatted

Open vmpuri opened this issue 6 months 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