refact: openai,claude

This commit is contained in:
Sakurasan
2024-04-16 23:47:06 +08:00
parent f336eba19a
commit b61e85b7fc
5 changed files with 650 additions and 3 deletions

29
router/chat.go Normal file
View File

@@ -0,0 +1,29 @@
package router
import (
"net/http"
"strings"
"opencatd-open/pkg/claude"
"opencatd-open/pkg/openai"
"github.com/gin-gonic/gin"
)
func ChatHandler(c *gin.Context) {
var chatreq openai.ChatCompletionRequest
if err := c.ShouldBindJSON(&chatreq); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
if strings.HasPrefix(chatreq.Model, "gpt") {
openai.ChatProxy(c, &chatreq)
return
}
if strings.HasPrefix(chatreq.Model, "claude") {
claude.ChatProxy(c, &chatreq)
return
}
}

View File

@@ -499,6 +499,9 @@ func HandleProy(c *gin.Context) {
return
}
ChatHandler(c)
return
if err := c.BindJSON(&chatreq); err != nil {
c.AbortWithError(http.StatusBadRequest, err)
return