Skip to content

Conversation

@Accelerator1996
Copy link
Contributor

@Accelerator1996 Accelerator1996 commented Apr 8, 2025

No related Issue, just fix chat input string in xgrammar format

If I launch an api server as follow:

python3 -m vllm.entrypoints.openai.api_server --model=mistralai/Mistral-7B-Instruct-v0.3

If I send a chat request as follow:

curl -X POST http://0.0.0.0:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
  "model": "mistralai/Mistral-7B-Instruct-v0.3",
  "messages": [{
      "role": "user",
      "content": "What is the weather in Dallas, Texas in Fahrenheit?"
    }],
  "max_completion_tokens": 100,
  "temperature": 0.0,
  "tools": [{
     "type": "function",
     "function": {
       "name": "get_current_weather",
       "description": "Get the current weather in a given location",
       "parameters": {
         "type": "object",
         "properties": {
           "city": {
             "type": "string",
             "description": "The city to find the weather for, e.g. \"San Francisco\""
           },
           "state": {
             "type": "string",
             "description": "must the two-letter abbreviation for the state that the city is in, e.g. \"CA\" which would mean \"California\""
           },
           "unit": {
             "type": "string",
             "description": "The unit to fetch the temperature in",
             "enum": ["celsius", "fahrenheit"]
           }
         }
       }
     }
  }],
  "tool_choice": {
    "type": "function",
    "function": { "name": "get_current_weather" }
  },
  "logprobs": false
}'

I will receive response {"object":"error","message":"The provided JSON schema contains features not supported by xgrammar.","type":"BadRequestError","param":null,"code":400}

After modifying the input content as below:

curl -X POST http://0.0.0.0:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
  "model": "mistralai/Mistral-7B-Instruct-v0.3",
  "messages": [{
      "role": "user",
      "content": "What is the weather in Dallas, Texas in Fahrenheit?"
    }],
  "max_completion_tokens": 100,
  "temperature": 0.0,
  "tools": [{
     "type": "function",
     "function": {
       "name": "get_current_weather",
       "description": "Get the current weather in a given location",
       "parameters": {
         "type": "object",
         "properties": {
           "city": {
             "type": "string",
             "description": "The city to find the weather for, e.g. \"San Francisco\""
           },
           "state": {
             "type": "string",
             "description": "must the two-letter abbreviation for the state that the city is in, e.g. \"CA\" which would mean \"California\""
           },
           "unit": {
             "type": "string",
             "description": "The unit to fetch the temperature in",
             "oneOf": [
               {"const": "celsius"},
               {"const": "fahrenheit"}
             ]
           }
         }
       }
     }
  }],
  "tool_choice": {
    "type": "function",
    "function": { "name": "get_current_weather" }
  },
  "logprobs": false
}'

I will receive response {"id":"chatcmpl-730d806c0eeb4a058b4892a51d8c740f","object":"chat.completion","created":1744094949,"model":"mistralai/Mistral-7B-Instruct-v0.3","choices":[{"index":0,"message":{"role":"assistant","reasoning_content":null,"content":"","tool_calls":[{"id":"chatcmpl-tool-e505d4794688402f9fda7f1685adc933","type":"function","function":{"name":"get_current_weather","arguments":"{\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}}]},"logprobs":null,"finish_reason":"length","stop_reason":null}],"usage":{"prompt_tokens":188,"total_tokens":288,"completion_tokens":100,"prompt_tokens_details":null},"prompt_logprobs":null}

@github-actions
Copy link

github-actions bot commented Apr 8, 2025

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

🚀

@Accelerator1996
Copy link
Contributor Author

Hello, @Isotr0py, can you help me to review this pull request ? I think the failure of CI is not caused by my code. Thank you very much!

@Isotr0py
Copy link
Member

Isotr0py commented Apr 9, 2025

I'm not familiar with structured-outputs, perhaps @russellb can take a look to this xgrammar related PR?

@Isotr0py Isotr0py requested a review from russellb April 9, 2025 05:38
Copy link
Member

@russellb russellb left a comment

Choose a reason for hiding this comment

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

To deal with the stream of \n, change your --guided-decoding-backend to xgrammar:disable-any-whitespace

"const": "celsius"
}, {
"const": "fahrenheit"
}]
Copy link
Member

Choose a reason for hiding this comment

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

enum should work now

#15594

#15878

Copy link
Contributor Author

Choose a reason for hiding this comment

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

enum should work now

#15594

#15878

Thank you very much

@russellb
Copy link
Member

russellb commented Apr 9, 2025

If you still have a problem given my feedback above, please feel free to reopen this, or we can talk in #feat-structured-output on slack. Thank you!

@russellb russellb closed this Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants