mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-10 02:23:43 +08:00
feat: support vision
- Added new dependencies: `github.com/fsnotify/fsnotify v1.4.9`, `github.com/go-playground/assert/v2 v2.2.0`, `github.com/nxadm/tail v1.4.8`, `github.com/onsi/ginkgo v1.16.5`, `github.com/onsi/gomega v1.18.1`, `golang.org/x/net v0.10.0`, `gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7` - Updated dependencies: `github.com/gin-gonic/gin` from v1.9.0 to v2.0.0, `golang.org/x/net` from v0.17.0 to v0.10.0 - Removed dependencies: `github.com/golang-jwt/jwt v3.2.2+incompatible`, `github.com/gorilla/websocket v1.5.1` - Updated Go version from `1.18` to `1.21` - Made various modifications and refactoring in the code: - Added new struct `VisionMessage` with fields `Role`, `Content`, and `Name` - Added constants for certain types - Added methods and error handling to handle different message types - Modified existing struct and methods to accommodate changes - Removed unused imports
This commit is contained in:
@@ -4,12 +4,14 @@ import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"one-api/common"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// https://docs.aiproxy.io/dev/library#使用已经定制好的知识库进行对话问答
|
||||
@@ -47,9 +49,27 @@ type AIProxyLibraryStreamResponse struct {
|
||||
|
||||
func requestOpenAI2AIProxyLibrary(request GeneralOpenAIRequest) *AIProxyLibraryRequest {
|
||||
query := ""
|
||||
if len(request.Messages) != 0 {
|
||||
query = request.Messages[len(request.Messages)-1].Content
|
||||
if request.MessagesLen() != 0 {
|
||||
switch msgs := request.Messages.(type) {
|
||||
case []Message:
|
||||
query = msgs[len(msgs)-1].Content
|
||||
case []VisionMessage:
|
||||
query = msgs[len(msgs)-1].Content.Text
|
||||
case []any:
|
||||
msg := msgs[len(msgs)-1]
|
||||
switch msg := msg.(type) {
|
||||
case Message:
|
||||
query = msg.Content
|
||||
case VisionMessage:
|
||||
query = msg.Content.Text
|
||||
default:
|
||||
log.Panicf("unknown message type: %T", msg)
|
||||
}
|
||||
default:
|
||||
log.Panicf("unknown message type: %T", msgs)
|
||||
}
|
||||
}
|
||||
|
||||
return &AIProxyLibraryRequest{
|
||||
Model: request.Model,
|
||||
Stream: request.Stream,
|
||||
|
||||
Reference in New Issue
Block a user