mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-20 17:26:38 +08:00
Merge pull request #405 from utopeadia/main
Modify the GEMINI version acquisition logic and add support for more gemini1.5pro/flash interfaces
This commit is contained in:
commit
54657ec27b
@ -64,6 +64,7 @@
|
|||||||
- `GET_MEDIA_TOKEN`:是统计图片token,默认为 `true`,关闭后将不再在本地计算图片token,可能会导致和上游计费不同,此项覆盖 `GET_MEDIA_TOKEN_NOT_STREAM` 选项作用。
|
- `GET_MEDIA_TOKEN`:是统计图片token,默认为 `true`,关闭后将不再在本地计算图片token,可能会导致和上游计费不同,此项覆盖 `GET_MEDIA_TOKEN_NOT_STREAM` 选项作用。
|
||||||
- `GET_MEDIA_TOKEN_NOT_STREAM`:是否在非流(`stream=false`)情况下统计图片token,默认为 `true`。
|
- `GET_MEDIA_TOKEN_NOT_STREAM`:是否在非流(`stream=false`)情况下统计图片token,默认为 `true`。
|
||||||
- `UPDATE_TASK`:是否更新异步任务(Midjourney、Suno),默认为 `true`,关闭后将不会更新任务进度。
|
- `UPDATE_TASK`:是否更新异步任务(Midjourney、Suno),默认为 `true`,关闭后将不会更新任务进度。
|
||||||
|
- `GEMINI_MODEL_API`:Gemini模型指定版本(v1/v1beta),如果配置会覆盖默认配置需要完整给出全部v1beta模型,使用模型:版本指定,","分隔,例如:-e GEMINI_MODEL_API="gemini-1.5-pro-latest:v1beta,gemini-1.5-pro-001:v1beta",为空则使用默认配置:gemini-1.5-pro-latest,gemini-1.5-pro-001,gemini-1.5-pro,gemini-1.5-pro-exp-0801,gemini-1.5-flash-latest,gemini-1.5-flash-001,gemini-1.5-flash,gemini-ultra模型为v1beta,其他为v1。
|
||||||
|
|
||||||
## 部署
|
## 部署
|
||||||
### 部署要求
|
### 部署要求
|
||||||
|
@ -6,12 +6,15 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"one-api/dto"
|
"one-api/dto"
|
||||||
"one-api/relay/channel"
|
"one-api/relay/channel"
|
||||||
|
"strings"
|
||||||
relaycommon "one-api/relay/common"
|
relaycommon "one-api/relay/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Adaptor struct {
|
type Adaptor struct {
|
||||||
|
modelVersionMap map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Adaptor) ConvertAudioRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.AudioRequest) (io.Reader, error) {
|
func (a *Adaptor) ConvertAudioRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.AudioRequest) (io.Reader, error) {
|
||||||
@ -25,18 +28,32 @@ func (a *Adaptor) ConvertImageRequest(c *gin.Context, info *relaycommon.RelayInf
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Adaptor) Init(info *relaycommon.RelayInfo) {
|
func (a *Adaptor) Init(info *relaycommon.RelayInfo) {
|
||||||
}
|
modelVersionMapStr := os.Getenv("GEMINI_MODEL_API")
|
||||||
|
if modelVersionMapStr == "" {
|
||||||
// 定义一个映射,存储模型名称和对应的版本
|
a.modelVersionMap = map[string]string{
|
||||||
var modelVersionMap = map[string]string{
|
"gemini-1.5-pro-latest": "v1beta",
|
||||||
"gemini-1.5-pro-latest": "v1beta",
|
"gemini-1.5-pro-001": "v1beta",
|
||||||
"gemini-1.5-flash-latest": "v1beta",
|
"gemini-1.5-pro": "v1beta",
|
||||||
"gemini-ultra": "v1beta",
|
"gemini-1.5-pro-exp-0801": "v1beta",
|
||||||
|
"gemini-1.5-flash-latest": "v1beta",
|
||||||
|
"gemini-1.5-flash-001": "v1beta",
|
||||||
|
"gemini-1.5-flash": "v1beta",
|
||||||
|
"gemini-ultra": "v1beta",
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
a.modelVersionMap = make(map[string]string)
|
||||||
|
for _, pair := range strings.Split(modelVersionMapStr, ",") {
|
||||||
|
parts := strings.Split(pair, ":")
|
||||||
|
if len(parts) == 2 {
|
||||||
|
a.modelVersionMap[parts[0]] = parts[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
|
func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
|
||||||
// 从映射中获取模型名称对应的版本,如果找不到就使用 info.ApiVersion 或默认的版本 "v1"
|
// 从映射中获取模型名称对应的版本,如果找不到就使用 info.ApiVersion 或默认的版本 "v1"
|
||||||
version, beta := modelVersionMap[info.UpstreamModelName]
|
version, beta := a.modelVersionMap[info.UpstreamModelName]
|
||||||
if !beta {
|
if !beta {
|
||||||
if info.ApiVersion != "" {
|
if info.ApiVersion != "" {
|
||||||
version = info.ApiVersion
|
version = info.ApiVersion
|
||||||
|
Loading…
Reference in New Issue
Block a user