mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-16 09:22:22 +00:00
fix(zai): write the prompted JSON schema as JSON so models answer with valid JSON
This commit is contained in:
parent
20c90d4ed1
commit
218e7e08ef
2 changed files with 5 additions and 3 deletions
|
|
@ -5906,8 +5906,8 @@ def default_response_schema_prompt(response_schema: Mapping[str, object]) -> str
|
|||
This is the default prompt. Allow user to override this with a custom_prompt.
|
||||
"""
|
||||
prompt_str: Final = f"""Use this JSON schema:
|
||||
```json
|
||||
{response_schema}
|
||||
```json
|
||||
{json.dumps(response_schema, default=str)}
|
||||
```"""
|
||||
return prompt_str
|
||||
|
||||
|
|
|
|||
|
|
@ -223,7 +223,9 @@ def test_zai_puts_json_schema_in_prompt_for_models_that_ignore_it(
|
|||
assert body["response_format"] == {"type": "json_object"}
|
||||
assert body["messages"][0] == {"role": "user", "content": "Ann likes 7"}
|
||||
assert body["messages"][-1]["role"] == "user"
|
||||
assert "favorite_number" in body["messages"][-1]["content"]
|
||||
prompt = body["messages"][-1]["content"]
|
||||
rendered_schema = prompt[prompt.index("{") : prompt.rindex("}") + 1]
|
||||
assert json.loads(rendered_schema) == JSON_SCHEMA_RESPONSE_FORMAT["json_schema"]["schema"]
|
||||
|
||||
|
||||
def test_zai_glm_5v_turbo_bills_cached_input_at_cache_read_price(local_model_cost_map: None) -> None:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue