Skip to content

Commit ca676f9

Browse files
authored
Merge pull request #623 from 100gle/bugfix-openai-baseurl
bugfix(experimental): add api version for openai api base automatically
2 parents 5c1c5e2 + e6f029b commit ca676f9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

backend/src/module/models/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from os.path import expandvars
22
from typing import Literal
33

4-
from pydantic import BaseModel, Field
4+
from pydantic import BaseModel, Field, validator
55

66

77
class Program(BaseModel):
@@ -102,6 +102,12 @@ class ExperimentalOpenAI(BaseModel):
102102
"", description="Azure OpenAI deployment id, ignored when api type is openai"
103103
)
104104

105+
@validator("api_base")
106+
def validate_api_base(cls, value: str):
107+
if value == "https://api.openai.com/":
108+
return "https://api.openai.com/v1"
109+
return value
110+
105111

106112
class Config(BaseModel):
107113
program: Program = Program()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from module.models.config import ExperimentalOpenAI
2+
3+
4+
def test_experimental_openai_validate_api_base():
5+
config = ExperimentalOpenAI(api_type="openai", api_base="https://api.openai.com/")
6+
assert config.api_base == "https://api.openai.com/v1"
7+
8+
config = ExperimentalOpenAI(api_base="https://api.openai.com/")
9+
assert config.api_base == "https://api.openai.com/v1"
10+
11+
config = ExperimentalOpenAI(
12+
api_type="azure", api_base="https://custom-api-base.com"
13+
)
14+
assert config.api_base == "https://custom-api-base.com"

0 commit comments

Comments
 (0)