Skip to content

Commit

Permalink
Allowing empty key for openai compatible, and fixing some tests (#287)
Browse files Browse the repository at this point in the history
* Allowing empty key for openai compatible, and fixing some tests

* Removing unneeded change
  • Loading branch information
jespino authored Jan 29, 2025
1 parent c2534bc commit 50c06ca
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
4 changes: 3 additions & 1 deletion server/llm/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ func (c *BotConfig) IsValid() bool {
switch c.Service.Type {
case ServiceTypeOpenAI:
return c.Service.APIKey != ""
case ServiceTypeOpenAICompatible, ServiceTypeAzure:
case ServiceTypeOpenAICompatible:
return c.Service.APIURL != ""
case ServiceTypeAzure:
return c.Service.APIKey != "" && c.Service.APIURL != ""
case ServiceTypeAnthropic:
return c.Service.APIKey != ""
Expand Down
34 changes: 28 additions & 6 deletions server/llm/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,33 @@ func TestBotConfig_IsValid(t *testing.T) {
InputTokenLimit: 100,
StreamingTimeoutSeconds: 60,
},
ChannelAccessLevel: ChannelAccessLevelNone + 1,
UserAccessLevel: UserAccessLevelNone,
ChannelAccessLevel: ChannelAccessLevelAll,
UserAccessLevel: UserAccessLevelAll,
},
want: false,
},
{
name: "OpenAI compatible service do not requires API Key to be set",
fields: fields{
ID: "xxx",
Name: "xxx",
DisplayName: "xxx",
CustomInstructions: "",
Service: ServiceConfig{
Name: "Copilot",
Type: "openaicompatible",
APIKey: "", // not bad
APIURL: "http://localhost",
OrgID: "org-xyz",
DefaultModel: "gpt-40",
InputTokenLimit: 100,
StreamingTimeoutSeconds: 60,
},
ChannelAccessLevel: ChannelAccessLevelAll,
UserAccessLevel: UserAccessLevelAll,
},
want: true,
},
{
name: "Ask Sage service requires username to be set",
fields: fields{
Expand All @@ -257,8 +279,8 @@ func TestBotConfig_IsValid(t *testing.T) {
InputTokenLimit: 100,
StreamingTimeoutSeconds: 60,
},
ChannelAccessLevel: ChannelAccessLevelNone + 1,
UserAccessLevel: UserAccessLevelNone,
ChannelAccessLevel: ChannelAccessLevelAll,
UserAccessLevel: UserAccessLevelAll,
},
want: false,
},
Expand All @@ -278,8 +300,8 @@ func TestBotConfig_IsValid(t *testing.T) {
InputTokenLimit: 100,
StreamingTimeoutSeconds: 60,
},
ChannelAccessLevel: ChannelAccessLevelNone + 1,
UserAccessLevel: UserAccessLevelNone,
ChannelAccessLevel: ChannelAccessLevelAll,
UserAccessLevel: UserAccessLevelAll,
},
want: false,
},
Expand Down

0 comments on commit 50c06ca

Please sign in to comment.