Skip to content

Commit

Permalink
update isOpenSourceModel
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic committed Oct 7, 2024
1 parent 9fc41f1 commit 1008079
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
12 changes: 12 additions & 0 deletions x-pack/plugins/elastic_assistant/server/routes/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,17 @@ describe('Utils', () => {
const isOpenModel = isOpenSourceModel(connector);
expect(isOpenModel).toEqual(true);
});

it('should return `true` when apiProvider of OpenAiProviderType.Other is specified', async () => {
const connector = {
actionTypeId: '.gen-ai',
config: {
apiUrl: OPENAI_CHAT_URL,
apiProvider: OpenAiProviderType.Other,
},
} as unknown as Connector;
const isOpenModel = isOpenSourceModel(connector);
expect(isOpenModel).toEqual(true);
});
});
});
26 changes: 16 additions & 10 deletions x-pack/plugins/elastic_assistant/server/routes/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,25 @@ export const isOpenSourceModel = (connector?: Connector): boolean => {
}

const llmType = getLlmType(connector.actionTypeId);
const connectorApiUrl = connector.config?.apiUrl
? (connector.config.apiUrl as string)
: undefined;
const isOpenAiType = llmType === 'openai';

if (!isOpenAiType) {
return false;
}
const connectorApiProvider = connector.config?.apiProvider
? (connector.config?.apiProvider as OpenAiProviderType)
: undefined;
if (connectorApiProvider === OpenAiProviderType.Other) {
return true;
}

const isOpenAiType = llmType === 'openai';
const isOpenAI =
isOpenAiType &&
(!connectorApiUrl ||
connectorApiUrl === OPENAI_CHAT_URL ||
connectorApiProvider === OpenAiProviderType.AzureAi);
const connectorApiUrl = connector.config?.apiUrl
? (connector.config.apiUrl as string)
: undefined;

return isOpenAiType && !isOpenAI;
return (
!!connectorApiUrl &&
connectorApiUrl !== OPENAI_CHAT_URL &&
connectorApiProvider !== OpenAiProviderType.AzureAi
);
};

0 comments on commit 1008079

Please sign in to comment.