pr feedback

- defer closing llm on embedding
- do not override licenses
- remove debugging print line
- reformat model file docs
This commit is contained in:
Bruce MacDonald 2023-08-08 16:56:48 -04:00
parent 884d78ceb3
commit 1bee2347be
2 changed files with 18 additions and 21 deletions

View File

@ -103,9 +103,7 @@ EMBED <file path>
The `PARAMETER` instruction defines a parameter that can be set when the model is run. The `PARAMETER` instruction defines a parameter that can be set when the model is run.
``` ```
PARAMETER <parameter> <parametervalue> PARAMETER <parameter> <parametervalue>
``` ```
### Valid Parameters and Values ### Valid Parameters and Values
@ -139,25 +137,19 @@ PARAMETER <parameter> <parametervalue>
| `{{ .First }}` | A boolean value used to render specific template information for the first generation of a session. | | `{{ .First }}` | A boolean value used to render specific template information for the first generation of a session. |
``` ```
TEMPLATE """ TEMPLATE """
{{- if .First }} {{- if .First }}
### System: ### System:
{{ .System }} {{ .System }}
{{- end }} {{- end }}
### User: ### User:
{{ .Prompt }} {{ .Prompt }}
### Response: ### Response:
""" """
SYSTEM """<system message>""" SYSTEM """<system message>"""
``` ```
### SYSTEM ### SYSTEM
@ -165,9 +157,7 @@ SYSTEM """<system message>"""
The `SYSTEM` instruction specifies the system prompt to be used in the template, if applicable. The `SYSTEM` instruction specifies the system prompt to be used in the template, if applicable.
``` ```
SYSTEM """<system message>""" SYSTEM """<system message>"""
``` ```
### LICENSE ### LICENSE
@ -175,18 +165,12 @@ SYSTEM """<system message>"""
The `LICENSE` instruction allows you to specify the legal license under which the model used with this Modelfile is shared or distributed. The `LICENSE` instruction allows you to specify the legal license under which the model used with this Modelfile is shared or distributed.
``` ```
LICENSE """ LICENSE """
<license text> <license text>
""" """
``` ```
## Notes ## Notes
- the **modelfile is not case sensitive**. In the examples, we use uppercase for instructions to make it easier to distinguish it from arguments. - the **modelfile is not case sensitive**. In the examples, we use uppercase for instructions to make it easier to distinguish it from arguments.
- Instructions can be in any order. In the examples, we start with FROM instruction to keep it easily readable. - Instructions can be in any order. In the examples, we start with FROM instruction to keep it easily readable.
```
```

View File

@ -303,13 +303,23 @@ func CreateModel(name string, path string, fn func(resp api.ProgressResponse)) e
} }
} }
case "embed": case "embed":
// TODO: support entire directories here
embedFilePath, err := filenameWithPath(path, c.Args) embedFilePath, err := filenameWithPath(path, c.Args)
if err != nil { if err != nil {
return err return err
} }
embed.files = append(embed.files, embedFilePath) embed.files = append(embed.files, embedFilePath)
case "license", "template", "system", "prompt": case "license":
fn(api.ProgressResponse{Status: fmt.Sprintf("creating model %s layer", c.Name)})
mediaType := fmt.Sprintf("application/vnd.ollama.image.%s", c.Name)
layer, err := CreateLayer(strings.NewReader(c.Args))
if err != nil {
return err
}
layer.MediaType = mediaType
layers = append(layers, layer)
case "template", "system", "prompt":
fn(api.ProgressResponse{Status: fmt.Sprintf("creating model %s layer", c.Name)}) fn(api.ProgressResponse{Status: fmt.Sprintf("creating model %s layer", c.Name)})
// remove the prompt layer if one exists // remove the prompt layer if one exists
mediaType := fmt.Sprintf("application/vnd.ollama.image.%s", c.Name) mediaType := fmt.Sprintf("application/vnd.ollama.image.%s", c.Name)
@ -354,8 +364,6 @@ func CreateModel(name string, path string, fn func(resp api.ProgressResponse)) e
embed.opts.FromMap(formattedParams) embed.opts.FromMap(formattedParams)
} }
fmt.Println(embed.model)
// generate the embedding layers // generate the embedding layers
embeddingLayers, err := embeddingLayers(embed) embeddingLayers, err := embeddingLayers(embed)
if err != nil { if err != nil {
@ -426,6 +434,11 @@ func embeddingLayers(e EmbeddingParams) ([]*LayerReader, error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("load model to generate embeddings: %v", err) return nil, fmt.Errorf("load model to generate embeddings: %v", err)
} }
defer func() {
if llm != nil {
llm.Close()
}
}()
addedFiles := make(map[string]bool) // keep track of files that have already been added addedFiles := make(map[string]bool) // keep track of files that have already been added
for _, filePattern := range e.files { for _, filePattern := range e.files {