llama.cpp icon indicating copy to clipboard operation
llama.cpp copied to clipboard

Feature Request: Req to support Structured output and JSON schema to GBNF

Open jkfnc opened this issue 1 year ago • 2 comments

Prerequisites

  • [X] I am running the latest code. Mention the version if possible as well.
  • [X] I carefully followed the README.md.
  • [X] I searched using keywords relevant to my issue to make sure that I am creating a new issue that is not already open (or closed).
  • [X] I reviewed the Discussions, and have a new and useful enhancement to share.

Feature Description

Openai updated sdk with support for structured output and json schema. Is it possible to get similar feature added to completion api but compiling to GBNF grammar. https://platform.openai.com/docs/guides/structured-outputs

Motivation

This will enable feature parity with completions api.

Possible Implementation

No response

jkfnc avatar Aug 07 '24 17:08 jkfnc

Made one proposal to solve this problem:

https://github.com/ollama/ollama/issues/6302

James4Ever0 avatar Aug 10 '24 16:08 James4Ever0

Llamasharp already supports GBNF grammars. I've been using them for a while now. Take a look at the LLama.Unittest/GrammarTest.cs for example usage. It's a little convoluted, but it works. You have to create a SafeLLamaGrammarHandle for your grammar and pass that handle in your InferenceParams. Just make sure you use a Clone() of the handle instead of the original handle. Otherwise, it would be disposed afterwards.

webitube avatar Aug 11 '24 12:08 webitube

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Sep 26 '24 01:09 github-actions[bot]