Skip to content

Commit

Permalink
Merge pull request ollama#50 from jmorganca/go-prompts
Browse files Browse the repository at this point in the history
fix prompt templates
  • Loading branch information
mxyng authored Jul 7, 2023
2 parents 963c202 + 15c114d commit 7d50069
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions server/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"log"
"math"
"net"
"net/http"
"path"
Expand Down Expand Up @@ -48,7 +49,7 @@ func generate(c *gin.Context) {
templateNames = append(templateNames, template.Name())
}

match, _ := matchRankOne(path.Base(req.Prompt), templateNames)
match, _ := matchRankOne(path.Base(req.Model), templateNames)
if template := templates.Lookup(match); template != nil {
var sb strings.Builder
if err := template.Execute(&sb, req); err != nil {
Expand Down Expand Up @@ -146,8 +147,9 @@ func Serve(ln net.Listener) error {
}

func matchRankOne(source string, targets []string) (bestMatch string, bestRank int) {
bestRank = math.MaxInt
for _, target := range targets {
if rank := fuzzy.LevenshteinDistance(source, target); bestRank < rank {
if rank := fuzzy.LevenshteinDistance(source, target); bestRank > rank {
bestRank = rank
bestMatch = target
}
Expand Down

0 comments on commit 7d50069

Please sign in to comment.