modelfile params

This commit is contained in:
Michael Yang
2023-07-17 12:08:10 -07:00
parent 529ff9ab6d
commit 28a136e9a3
4 changed files with 85 additions and 63 deletions

View File

@@ -2,7 +2,6 @@ package server
import (
"encoding/json"
"fmt"
"io"
"log"
"net"
@@ -13,6 +12,7 @@ import (
"text/template"
"time"
"dario.cat/mergo"
"github.com/gin-gonic/gin"
"github.com/jmorganca/ollama/api"
@@ -31,11 +31,7 @@ func cacheDir() string {
func generate(c *gin.Context) {
start := time.Now()
req := api.GenerateRequest{
Options: api.DefaultOptions(),
Prompt: "",
}
var req api.GenerateRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
@@ -47,6 +43,17 @@ func generate(c *gin.Context) {
return
}
opts := api.DefaultOptions()
if err := mergo.Merge(&opts, model.Options, mergo.WithOverride); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
if err := mergo.Merge(&opts, req.Options, mergo.WithOverride); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
templ, err := template.New("").Parse(model.Prompt)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
@@ -60,9 +67,9 @@ func generate(c *gin.Context) {
}
req.Prompt = sb.String()
fmt.Printf("prompt = >>>%s<<<\n", req.Prompt)
log.Printf("prompt: \n%s", req.Prompt)
llm, err := llama.New(model.ModelPath, req.Options)
llm, err := llama.New(model.ModelPath, opts)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return