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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: guided jsons with date fields are not valid #4583

Open
andreas-22 opened this issue May 3, 2024 · 3 comments
Open

[Bug]: guided jsons with date fields are not valid #4583

andreas-22 opened this issue May 3, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@andreas-22
Copy link

andreas-22 commented May 3, 2024

Your current environment

I host llama3-8B-instruct model
in a docker image using the base image vllm/vllm-openai:0.4.1

openai version: 1.6.1 (example script below)

馃悰 Describe the bug

description

When we prompt the model to produce a json with the guided_json parameter set and including a date field, we get an invalid json response.

This is also not dependent on the specific model. We got the same error with mixtral models.

code

from openai import OpenAI


model_name = "/docker_share/models/llama3_8b_instruct"
num_prompt_tokens = 1000
base_url = "http://model-url"
api_key = "EMPTY"
client = OpenAI(base_url=base_url, api_key=api_key)
def call_vllm(prompt, guided_json=None):
        if guided_json:
            extra_body = {
                 "guided_json": guided_json
                 }
        messages = [{"role": "user", "content": prompt}]
        
        chat_completion = client.chat.completions.create(
            model=model_name,
            messages=messages,
            extra_body=extra_body,
            seed=42,
            max_tokens=num_prompt_tokens,
            temperature=0
        )
        return chat_completion.choices[0].message.content

guided_json = """{ 
    "additionalProperties": false, 
    "properties": { 
        "DocumentDate": {"anyOf": [{"format": "date", "type": "string"}, {"type": "null"}], 
        "description": "Document date", 
        "title": "DocumentDate"} 
    }, 
    "required": ["DocumentDate"], 
    "title": "Document", 
    "type": "object" 
}"""

if __name__ == "__main__":
    res = call_vllm("Extract a date from this string: date of the document - 01.01.1999", guided_json=guided_json)
    print(res)

result

{ "DocumentDate": 1999-01-01 }

expected result

{ "DocumentDate": "1999-01-01" }

@andreas-22 andreas-22 added the bug Something isn't working label May 3, 2024
@simon-mo
Copy link
Collaborator

simon-mo commented May 3, 2024

@andreas-22
Copy link
Author

This seems to be related to a known issue with older versions of outlines:
bug: predibase/lorax#392
fix: outlines-dev/outlines#567

Perhaps the outlines version should be updated
In vllm, in requirements-common.txt it is specified outlines == 0.0.34.
Using outlines==0.0.41 in the example script above, I get valid jsons with date field.

Copy link
Collaborator

simon-mo commented May 6, 2024

Being worked on in #4558 and #4330

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants