guidance icon indicating copy to clipboard operation
guidance copied to clipboard

OpenAI result_format JSON

Open ryanpeach opened this issue 1 year ago • 4 comments

Is your feature request related to a problem? Please describe.

OpenAI now provides a JSON response format! https://community.openai.com/t/how-do-i-use-the-new-json-mode/475890/14

Since OpenAI does not support enforced grammar, this is a big deal.

Describe the solution you'd like

The json grammar should trigger this functionality in the OpenAIChatEngine

ryanpeach avatar Mar 26 '24 15:03 ryanpeach

Relevant lines of code:

https://github.com/guidance-ai/guidance/blob/7c71e90ece97c879d4b3a1e2b33ecd6a522a25dd/guidance/models/_openai.py#L243-L251

https://github.com/guidance-ai/guidance/blob/7c71e90ece97c879d4b3a1e2b33ecd6a522a25dd/guidance/library/_json.py#L204-L211

ryanpeach avatar Apr 01 '24 19:04 ryanpeach

Need to upgrade openai to 1.1 based on https://github.com/openai/openai-python/compare/v1.0.1...v1.1.0

ryanpeach avatar Apr 01 '24 19:04 ryanpeach

Relevant api link https://platform.openai.com/docs/api-reference/chat/create#chat-create-response_format

ryanpeach avatar Apr 01 '24 19:04 ryanpeach

Related PR's https://github.com/guidance-ai/guidance/pull/699 https://github.com/guidance-ai/guidance/pull/724

ryanpeach avatar Apr 02 '24 17:04 ryanpeach