enhance checky by requesting endpoint propert to be set when apiType is Azure

Signed-off-by: fabistb <fabian0401@online.de>
This commit is contained in:
fabistb 2025-07-29 19:44:06 +02:00
parent f7f3dc5c3e
commit b667ae76eb
2 changed files with 18 additions and 0 deletions

View File

@ -82,6 +82,11 @@ func (o *OpenAI) Init(ctx context.Context, meta conversation.Metadata) error {
return errors.New("apiVersion must be provided when apiType is set to 'azure'")
}
// Return error when api Type is azure but the endpoint is not provided
if md.ApiType == "azure" && md.Endpoint == "" {
return errors.New("endpoint must be provided when apiType is set to 'azure'")
}
// Set api version if provided
if md.ApiVersion != "" {
options = append(options, openai.WithAPIVersion(md.ApiVersion))

View File

@ -94,6 +94,19 @@ func TestInit(t *testing.T) {
assert.EqualError(t, err, "apiVersion must be provided when apiType is set to 'azure'")
},
},
{
name: "with apiType azure but missing endpoint",
metadata: map[string]string{
"key": "test-key",
"model": "gpt-4",
"apiType": "azure",
"apiVersion": "2025-01-01-preview",
},
testFn: func(t *testing.T, o *OpenAI, err error) {
require.Error(t, err)
assert.EqualError(t, err, "endpoint must be provided when apiType is set to 'azure'")
},
},
}
for _, tc := range testCases {