mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-26 20:06:37 +08:00
feat: Support github models
This commit is contained in:
parent
9b14c5da63
commit
e68447e696
@ -5,7 +5,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/bytedance/gopkg/util/gopool"
|
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -24,6 +23,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/bytedance/gopkg/util/gopool"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,9 +37,15 @@ func testChannel(channel *model.Channel, testModel string) (err error, openAIErr
|
|||||||
}
|
}
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
c, _ := gin.CreateTestContext(w)
|
c, _ := gin.CreateTestContext(w)
|
||||||
|
baseUrl := channel.GetBaseURL()
|
||||||
|
chatPath := "/v1/chat/completions"
|
||||||
|
if strings.HasPrefix(baseUrl, "https://models.inference.ai.azure.com") {
|
||||||
|
chatPath = "/chat/completions"
|
||||||
|
}
|
||||||
|
common.SysLog(fmt.Sprintf("testing channel %d with model %s path %s", channel.Id, testModel, chatPath))
|
||||||
c.Request = &http.Request{
|
c.Request = &http.Request{
|
||||||
Method: "POST",
|
Method: "POST",
|
||||||
URL: &url.URL{Path: "/v1/chat/completions"},
|
URL: &url.URL{Path: chatPath},
|
||||||
Body: nil,
|
Body: nil,
|
||||||
Header: make(http.Header),
|
Header: make(http.Header),
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"io"
|
"io"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -19,6 +18,8 @@ import (
|
|||||||
relaycommon "one-api/relay/common"
|
relaycommon "one-api/relay/common"
|
||||||
"one-api/relay/constant"
|
"one-api/relay/constant"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Adaptor struct {
|
type Adaptor struct {
|
||||||
@ -47,6 +48,14 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
|
|||||||
return minimax.GetRequestURL(info)
|
return minimax.GetRequestURL(info)
|
||||||
case common.ChannelTypeCustom:
|
case common.ChannelTypeCustom:
|
||||||
url := info.BaseUrl
|
url := info.BaseUrl
|
||||||
|
if strings.HasPrefix(url, "https://models.inference.ai.azure.com") {
|
||||||
|
url = strings.TrimPrefix(url, "/v1")
|
||||||
|
if info.RelayMode == constant.RelayModeCompletions {
|
||||||
|
url = fmt.Sprintf("%s/%s", url, "chat/completions")
|
||||||
|
} else if info.RelayMode == constant.RelayModeEmbeddings {
|
||||||
|
url = fmt.Sprintf("%s/%s", url, "embeddings")
|
||||||
|
}
|
||||||
|
}
|
||||||
url = strings.Replace(url, "{model}", info.UpstreamModelName, -1)
|
url = strings.Replace(url, "{model}", info.UpstreamModelName, -1)
|
||||||
return url, nil
|
return url, nil
|
||||||
default:
|
default:
|
||||||
|
@ -46,6 +46,8 @@ func Path2RelayMode(path string) int {
|
|||||||
relayMode = RelayModeChatCompletions
|
relayMode = RelayModeChatCompletions
|
||||||
} else if strings.HasPrefix(path, "/v1/completions") {
|
} else if strings.HasPrefix(path, "/v1/completions") {
|
||||||
relayMode = RelayModeCompletions
|
relayMode = RelayModeCompletions
|
||||||
|
} else if strings.HasPrefix(path, "/chat/completions") {
|
||||||
|
relayMode = RelayModeCompletions
|
||||||
} else if strings.HasPrefix(path, "/v1/embeddings") {
|
} else if strings.HasPrefix(path, "/v1/embeddings") {
|
||||||
relayMode = RelayModeEmbeddings
|
relayMode = RelayModeEmbeddings
|
||||||
} else if strings.HasSuffix(path, "embeddings") {
|
} else if strings.HasSuffix(path, "embeddings") {
|
||||||
|
Loading…
Reference in New Issue
Block a user