Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ollama/ollama
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.5.3
Choose a base ref
...
head repository: ollama/ollama
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.5.4
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Dec 17, 2024

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    2cde4b8 View commit details
  2. llm: do not error on "null" format (#8139)

    This fixes another regression in the previous commit that fixed other
    known bugs.
    bmizerany authored Dec 17, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    2ddc32d View commit details
Showing with 26 additions and 13 deletions.
  1. +2 −2 README.md
  2. +11 −7 llm/server.go
  3. +13 −4 llm/server_test.go
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -407,8 +407,8 @@ See the [API documentation](./docs/api.md) for all endpoints.

### Database

- [PostgreSQL extension pgai](https://github.com/timescale/pgai) (Create and search embeddings from Ollama models using pgvector)
- [Get started guide](https://github.com/timescale/pgai/blob/main/docs/ollama.md)
- [pgai](https://github.com/timescale/pgai) - PostgreSQL as a vector database (Create and search embeddings from Ollama models using pgvector)
- [Get started guide](https://github.com/timescale/pgai/blob/main/docs/vectorizer-quick-start.md)
- [MindsDB](https://github.com/mindsdb/mindsdb/blob/staging/mindsdb/integrations/handlers/ollama_handler/README.md) (Connects Ollama models with nearly 200 data platforms and apps)
- [chromem-go](https://github.com/philippgille/chromem-go/blob/v0.5.0/embed_ollama.go) with [example](https://github.com/philippgille/chromem-go/tree/v0.5.0/examples/rag-wikipedia-ollama)
- [Kangaroo](https://github.com/dbkangaroo/kangaroo) (AI-powered SQL client and admin tool for popular databases)
18 changes: 11 additions & 7 deletions llm/server.go
Original file line number Diff line number Diff line change
@@ -700,20 +700,24 @@ func (s *llmServer) Completion(ctx context.Context, req CompletionRequest, fn fu
}

if len(req.Format) > 0 {
switch {
case bytes.Equal(req.Format, []byte(`""`)):
// fallthrough
case bytes.Equal(req.Format, []byte(`"json"`)):
switch string(req.Format) {
case `null`, `""`:
// Field was set, but "missing" a value. We accept
// these as "not set".
break
case `"json"`:
request["grammar"] = grammarJSON
case bytes.HasPrefix(req.Format, []byte("{")):
default:
if req.Format[0] != '{' {
return fmt.Errorf("invalid format: %q; expected \"json\" or a valid JSON Schema object", req.Format)
}

// User provided a JSON schema
g := llama.SchemaToGrammar(req.Format)
if g == nil {
return fmt.Errorf("invalid JSON schema in format")
}
request["grammar"] = string(g)
default:
return fmt.Errorf("invalid format: %q; expected \"json\" or a valid JSON Schema", req.Format)
}
}

17 changes: 13 additions & 4 deletions llm/server_test.go
Original file line number Diff line number Diff line change
@@ -39,25 +39,34 @@ func TestLLMServerCompletionFormat(t *testing.T) {

cancel() // prevent further processing if request makes it past the format check

checkCanceled := func(err error) {
checkValid := func(err error) {
t.Helper()
if !errors.Is(err, context.Canceled) {
t.Fatalf("Completion: err = %v; expected context.Canceled", err)
}
}

valids := []string{`"json"`, `{"type":"object"}`, ``, `""`}
valids := []string{
// "missing"
``,
`""`,
`null`,

// JSON
`"json"`,
`{"type":"object"}`,
}
for _, valid := range valids {
err := s.Completion(ctx, CompletionRequest{
Options: new(api.Options),
Format: []byte(valid),
}, nil)
checkCanceled(err)
checkValid(err)
}

err := s.Completion(ctx, CompletionRequest{
Options: new(api.Options),
Format: nil, // missing format
}, nil)
checkCanceled(err)
checkValid(err)
}