feat: Support github models

This commit is contained in:
aka-ioc 2024-09-22 13:58:52 +00:00
parent 9b14c5da63
commit e68447e696
3 changed files with 20 additions and 3 deletions

View File

@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/bytedance/gopkg/util/gopool"
"io"
"math"
"net/http"
@ -24,6 +23,7 @@ import (
"sync"
"time"
"github.com/bytedance/gopkg/util/gopool"
"github.com/gin-gonic/gin"
)
@ -37,9 +37,15 @@ func testChannel(channel *model.Channel, testModel string) (err error, openAIErr
}
w := httptest.NewRecorder()
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{
Method: "POST",
URL: &url.URL{Path: "/v1/chat/completions"},
URL: &url.URL{Path: chatPath},
Body: nil,
Header: make(http.Header),
}

View File

@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"io"
"mime/multipart"
"net/http"
@ -19,6 +18,8 @@ import (
relaycommon "one-api/relay/common"
"one-api/relay/constant"
"strings"
"github.com/gin-gonic/gin"
)
type Adaptor struct {
@ -47,6 +48,14 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
return minimax.GetRequestURL(info)
case common.ChannelTypeCustom:
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)
return url, nil
default:

View File

@ -46,6 +46,8 @@ func Path2RelayMode(path string) int {
relayMode = RelayModeChatCompletions
} else if strings.HasPrefix(path, "/v1/completions") {
relayMode = RelayModeCompletions
} else if strings.HasPrefix(path, "/chat/completions") {
relayMode = RelayModeCompletions
} else if strings.HasPrefix(path, "/v1/embeddings") {
relayMode = RelayModeEmbeddings
} else if strings.HasSuffix(path, "embeddings") {