123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- package llm
- import (
- _ "embed"
- "fmt"
- "time"
- "github.com/jmorganca/ollama/api"
- )
- const jsonGrammar = `
- root ::= object
- value ::= object | array | string | number | ("true" | "false" | "null") ws
- object ::=
- "{" ws (
- string ":" ws value
- ("," ws string ":" ws value)*
- )? "}" ws
- array ::=
- "[" ws (
- value
- ("," ws value)*
- )? "]" ws
- string ::=
- "\"" (
- [^"\\] |
- "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F]) # escapes
- )* "\"" ws
- number ::= ("-"? ([0-9] | [1-9] [0-9]*)) ("." [0-9]+)? ([eE] [-+]? [0-9]+)? ws
- # Optional space: by convention, applied in this grammar after literal chars when allowed
- ws ::= ([ \t\n] ws)?
- `
- type ImageData struct {
- Data []byte `json:"data"`
- ID int `json:"id"`
- }
- var payloadMissing = fmt.Errorf("expected dynamic library payloads not included in this build of ollama")
- type prediction struct {
- Content string `json:"content"`
- Model string `json:"model"`
- Prompt string `json:"prompt"`
- Stop bool `json:"stop"`
- Timings struct {
- PredictedN int `json:"predicted_n"`
- PredictedMS float64 `json:"predicted_ms"`
- PromptN int `json:"prompt_n"`
- PromptMS float64 `json:"prompt_ms"`
- }
- }
- const maxRetries = 3
- type PredictOpts struct {
- Prompt string
- Format string
- Images []ImageData
- Options api.Options
- }
- type PredictResult struct {
- Content string
- Done bool
- PromptEvalCount int
- PromptEvalDuration time.Duration
- EvalCount int
- EvalDuration time.Duration
- }
- type TokenizeRequest struct {
- Content string `json:"content"`
- }
- type TokenizeResponse struct {
- Tokens []int `json:"tokens"`
- }
- type DetokenizeRequest struct {
- Tokens []int `json:"tokens"`
- }
- type DetokenizeResponse struct {
- Content string `json:"content"`
- }
- type EmbeddingRequest struct {
- Content string `json:"content"`
- }
- type EmbeddingResponse struct {
- Embedding []float64 `json:"embedding"`
- }
|