File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 11from os .path import expandvars
22from typing import Literal
33
4- from pydantic import BaseModel , Field
4+ from pydantic import BaseModel , Field , validator
55
66
77class 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
106112class Config (BaseModel ):
107113 program : Program = Program ()
Original file line number Diff line number Diff line change 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"
You can’t perform that action at this time.
0 commit comments