Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
18f6a98b
Unverified
Commit
18f6a98b
authored
Dec 11, 2024
by
Parth Sareen
Committed by
GitHub
Dec 11, 2024
Browse files
llama: enable JSON schema key ordering for generating grammars (#8055)
parent
b1fd7fef
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
6 deletions
+24
-6
llama/grammar_test.go
llama/grammar_test.go
+1
-5
llama/json-schema-to-grammar.cpp
llama/json-schema-to-grammar.cpp
+1
-1
llama/patches/0012-Maintain-ordering-for-rules-for-grammar.patch
...atches/0012-Maintain-ordering-for-rules-for-grammar.patch
+22
-0
No files found.
llama/grammar_test.go
View file @
18f6a98b
...
...
@@ -30,8 +30,6 @@ const issue7978JSONSchema = `{
}`
func
TestIssue7978
(
t
*
testing
.
T
)
{
t
.
Skip
(
"schema_to_grammar is broken; skipping until fixed"
)
g
:=
SchemaToGrammar
([]
byte
(
issue7978JSONSchema
))
if
g
==
nil
{
t
.
Fatal
(
"failed to convert JSON schema to grammar"
)
...
...
@@ -54,8 +52,6 @@ func TestIssue7978(t *testing.T) {
}
func
TestSchemaToGrammer
(
t
*
testing
.
T
)
{
t
.
Skip
(
"schema_to_grammar is broken; skipping until fixed"
)
cases
:=
[]
struct
{
schema
string
prefix
[]
byte
// nil is check as nil
...
...
@@ -63,7 +59,7 @@ func TestSchemaToGrammer(t *testing.T) {
{
`invalid`
,
nil
},
// Simple heuristic/smoke test
{
`{"type":"object"}`
,
[]
byte
(
"object
::=
"
)},
{
`{"type":"object"}`
,
[]
byte
(
"
root ::=
object"
)},
}
for
_
,
c
:=
range
cases
{
...
...
llama/json-schema-to-grammar.cpp
View file @
18f6a98b
...
...
@@ -417,7 +417,7 @@ class SchemaConverter {
private:
std
::
function
<
json
(
const
std
::
string
&
)
>
_fetch_json
;
bool
_dotall
;
std
::
map
<
std
::
string
,
std
::
string
>
_rules
;
std
::
unordered_
map
<
std
::
string
,
std
::
string
>
_rules
;
std
::
unordered_map
<
std
::
string
,
json
>
_refs
;
std
::
unordered_set
<
std
::
string
>
_refs_being_resolved
;
std
::
vector
<
std
::
string
>
_errors
;
...
...
llama/patches/0012-Maintain-ordering-for-rules-for-grammar.patch
0 → 100644
View file @
18f6a98b
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: ParthSareen <parth.sareen@ollama.com>
Date: Wed, 11 Dec 2024 15:37:32 -0800
Subject: [PATCH] Maintain ordering for rules for grammar
---
common/json-schema-to-grammar.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/json-schema-to-grammar.cpp b/common/json-schema-to-grammar.cpp
index dadc18c8..2a8dbd22 100644
--- a/common/json-schema-to-grammar.cpp
+++ b/common/json-schema-to-grammar.cpp
@@ -391,7 +391,7 @@
class SchemaConverter {
private:
std::function<json(const std::string &)> _fetch_json;
bool _dotall;
- std::map<std::string, std::string> _rules;
+ std::unordered_map<std::string, std::string> _rules;
std::unordered_map<std::string, json> _refs;
std::unordered_set<std::string> _refs_being_resolved;
std::vector<std::string> _errors;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment