support gpt-4o-mini

This commit is contained in:
Sakurasan
2024-07-19 12:10:49 +08:00
parent 1284ad9dec
commit c11824f5aa
2 changed files with 26 additions and 27 deletions

View File

@@ -97,6 +97,8 @@ func Cost(model string, promptCount, completionCount int) float64 {
cost = 0.01*float64(prompt/1000) + 0.03*float64(completion/1000) cost = 0.01*float64(prompt/1000) + 0.03*float64(completion/1000)
case "gpt-4o", "gpt-4o-2024-05-13": case "gpt-4o", "gpt-4o-2024-05-13":
cost = 0.005*float64(prompt/1000) + 0.015*float64(completion/1000) cost = 0.005*float64(prompt/1000) + 0.015*float64(completion/1000)
case "gpt-4o-mini", "gpt-4o-mini-2024-07-18":
cost = 0.00015*float64(prompt/1000) + 0.0006*float64(completion/1000)
case "whisper-1": case "whisper-1":
// 0.006$/min // 0.006$/min
cost = 0.006 * float64(prompt+completion) / 60 cost = 0.006 * float64(prompt+completion) / 60

View File

@@ -1,15 +1,12 @@
package router package router
import ( import (
"bytes"
"encoding/json"
"net/http" "net/http"
"strings" "strings"
"opencatd-open/pkg/claude" "opencatd-open/pkg/claude"
"opencatd-open/pkg/google" "opencatd-open/pkg/google"
"opencatd-open/pkg/openai" "opencatd-open/pkg/openai"
"opencatd-open/pkg/search"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -21,31 +18,31 @@ func ChatHandler(c *gin.Context) {
return return
} }
if chatreq.Messages[len(chatreq.Messages)-1].Role == "user" { // if chatreq.Messages[len(chatreq.Messages)-1].Role == "user" {
result, err := search.BingSearch(search.SearchParams{Query: string(chatreq.Messages[len(chatreq.Messages)-1].Content)}) // result, err := search.BingSearch(search.SearchParams{Query: string(chatreq.Messages[len(chatreq.Messages)-1].Content)})
if err == nil { // if err == nil {
var msgs []openai.ChatCompletionMessage // var msgs []openai.ChatCompletionMessage
for i, m := range chatreq.Messages { // for i, m := range chatreq.Messages {
var buf bytes.Buffer // var buf bytes.Buffer
buf.WriteString("根据我提问的语言回答我,我将提供一些从搜索引擎获取的信息(以websearch:开头)。你自行判断是否使用搜索引擎获取的内容。不要原封不动照抄,根据你自己的知识库提炼信息之后回答我\n\n") // buf.WriteString("根据我提问的语言回答我,我将提供一些从搜索引擎获取的信息(以websearch:开头)。你自行判断是否使用搜索引擎获取的内容。不要原封不动照抄,根据你自己的知识库提炼信息之后回答我\n\n")
if m.Role == "system" { // if m.Role == "system" {
buf.Write(m.Content) // buf.Write(m.Content)
msgs = append(msgs, openai.ChatCompletionMessage{Role: m.Role, Content: buf.Bytes()}) // msgs = append(msgs, openai.ChatCompletionMessage{Role: m.Role, Content: buf.Bytes()})
} else { // } else {
msgs = append(msgs, openai.ChatCompletionMessage{Role: m.Role, Content: buf.Bytes()}) // msgs = append(msgs, openai.ChatCompletionMessage{Role: m.Role, Content: buf.Bytes()})
} // }
if i == len(chatreq.Messages)-1 { // if i == len(chatreq.Messages)-1 {
m.Content = append(m.Content, json.RawMessage("\n\nwebsearch:")...) // m.Content = append(m.Content, json.RawMessage("\n\nwebsearch:")...)
m.Content = append(m.Content, json.RawMessage(result.(string))...) // m.Content = append(m.Content, json.RawMessage(result.(string))...)
msgs = append(msgs, openai.ChatCompletionMessage{Role: m.Role, Content: m.Content}) // msgs = append(msgs, openai.ChatCompletionMessage{Role: m.Role, Content: m.Content})
} else { // } else {
msgs = append(msgs, openai.ChatCompletionMessage{Role: m.Role, Content: m.Content}) // msgs = append(msgs, openai.ChatCompletionMessage{Role: m.Role, Content: m.Content})
} // }
} // }
chatreq.Messages = msgs // chatreq.Messages = msgs
} // }
} // }
if strings.HasPrefix(chatreq.Model, "gpt") { if strings.HasPrefix(chatreq.Model, "gpt") {
openai.ChatProxy(c, &chatreq) openai.ChatProxy(c, &chatreq)