Unverified Commit 7d500692 authored by Michael Yang's avatar Michael Yang Committed by GitHub
Browse files

Merge pull request #50 from jmorganca/go-prompts

fix prompt templates
parents 963c2025 15c114de
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"io" "io"
"log" "log"
"math"
"net" "net"
"net/http" "net/http"
"path" "path"
...@@ -48,7 +49,7 @@ func generate(c *gin.Context) { ...@@ -48,7 +49,7 @@ func generate(c *gin.Context) {
templateNames = append(templateNames, template.Name()) 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 { if template := templates.Lookup(match); template != nil {
var sb strings.Builder var sb strings.Builder
if err := template.Execute(&sb, req); err != nil { if err := template.Execute(&sb, req); err != nil {
...@@ -146,8 +147,9 @@ func Serve(ln net.Listener) error { ...@@ -146,8 +147,9 @@ func Serve(ln net.Listener) error {
} }
func matchRankOne(source string, targets []string) (bestMatch string, bestRank int) { func matchRankOne(source string, targets []string) (bestMatch string, bestRank int) {
bestRank = math.MaxInt
for _, target := range targets { for _, target := range targets {
if rank := fuzzy.LevenshteinDistance(source, target); bestRank < rank { if rank := fuzzy.LevenshteinDistance(source, target); bestRank > rank {
bestRank = rank bestRank = rank
bestMatch = target bestMatch = target
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment