refact: openai,claude
This commit is contained in:
29
router/chat.go
Normal file
29
router/chat.go
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user