Skip to content

Commit

Permalink
[ResponseOps] Fix Azure Connector Streaming Validation (elastic#191552)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic authored Aug 28, 2024
1 parent 30b5657 commit 97b5479
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
6 changes: 3 additions & 3 deletions x-pack/plugins/stack_connectors/common/openai/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export const DEFAULT_OPENAI_MODEL = 'gpt-4o';
export const OPENAI_CHAT_URL = 'https://api.openai.com/v1/chat/completions' as const;
export const OPENAI_LEGACY_COMPLETION_URL = 'https://api.openai.com/v1/completions' as const;
export const AZURE_OPENAI_CHAT_URL =
'https://{your-resource-name}.openai.azure.com/openai/deployments/{deployment-id}/chat/completions?api-version={api-version}' as const;
'/openai/deployments/{deployment-id}/chat/completions?api-version={api-version}' as const;
export const AZURE_OPENAI_COMPLETIONS_URL =
'https://{your-resource-name}.openai.azure.com/openai/deployments/{deployment-id}/completions?api-version={api-version}' as const;
'/openai/deployments/{deployment-id}/completions?api-version={api-version}' as const;
export const AZURE_OPENAI_COMPLETIONS_EXTENSIONS_URL =
'https://{your-resource-name}.openai.azure.com/openai/deployments/{deployment-id}/extensions/chat/completions?api-version={api-version}' as const;
'/openai/deployments/{deployment-id}/extensions/chat/completions?api-version={api-version}' as const;
Original file line number Diff line number Diff line change
Expand Up @@ -146,38 +146,29 @@ describe('Azure Open AI Utils', () => {
const regex = transformApiUrlToRegex(AZURE_OPENAI_CHAT_URL);
const match = chatUrl.match(regex);
expect(match).not.toBeNull();
expect(match![0]).toEqual(
'https://My-test-resource-123.openai.azure.com/openai/deployments/NEW-DEPLOYMENT-321/chat/completions'
);
expect(match![0]).toEqual('/openai/deployments/NEW-DEPLOYMENT-321/chat/completions');
});

it('should match valid completion url', () => {
const regex = transformApiUrlToRegex(AZURE_OPENAI_COMPLETIONS_URL);
const match = completionUrl.match(regex);
expect(match).not.toBeNull();
expect(match![0]).toEqual(
'https://My-test-resource-123.openai.azure.com/openai/deployments/NEW-DEPLOYMENT-321/completions'
);
expect(match![0]).toEqual('/openai/deployments/NEW-DEPLOYMENT-321/completions');
});

it('should match valid completion extensions url', () => {
const regex = transformApiUrlToRegex(AZURE_OPENAI_COMPLETIONS_EXTENSIONS_URL);
const match = completionExtensionsUrl.match(regex);
expect(match).not.toBeNull();
expect(match![0]).toEqual(
'https://My-test-resource-123.openai.azure.com/openai/deployments/NEW-DEPLOYMENT-321/extensions/chat/completions'
'/openai/deployments/NEW-DEPLOYMENT-321/extensions/chat/completions'
);
});

it('should not match invalid chat url', () => {
const regex = transformApiUrlToRegex(AZURE_OPENAI_CHAT_URL);
[
'https://openai.azure.com/openai/deployments/NEW-DEPLOYMENT-321/chat/completions?api-version=2023-05-15',
'https://My-test-resource-123.openaiazure.com/openai/deployments/NEW-DEPLOYMENT-321/chat/completions?api-version=2023-05-15',
'https://My-test-resource-123.openaiaazure.com/openai/deployments/NEW-DEPLOYMENT-321/chat/completions?api-version=2023-05-15',
'https://My-test-resource-123openai.azure.com/openai/deployments/NEW-DEPLOYMENT-321/chat/completions?api-version=2023-05-15',
'https://My-test-resource-123.openai.azure.com//openai/deployments/NEW-DEPLOYMENT-321/chat/completions?api-version=2023-05-15',
'https:///My-test-resource-123.openai.azure.com/openai/deployments/NEW-DEPLOYMENT-321/chat/completions?api-version=2023-05-15',
'https://openai.azure.com/openai/deployments/NEW-DEPLOYMENT-321/chat/not-completions?api-version=2023-05-15',
].forEach((url) => {
const match = url.match(regex);
expect(match).toBeNull();
Expand All @@ -187,12 +178,7 @@ describe('Azure Open AI Utils', () => {
it('should not match invalid completion url', () => {
const regex = transformApiUrlToRegex(AZURE_OPENAI_COMPLETIONS_URL);
[
'https://fooai.com/completions?api-version=2023-05-15',
'https://My-test-resource-123.openaiazure.com/openai/deployments/NEW-DEPLOYMENT-321/completions?api-version=2023-05-15',
'https://My-test-resource-123.openaiaazure.com/openai/deployments/NEW-DEPLOYMENT-321/completions?api-version=2023-05-15',
'https://My-test-resource-123openai.azure.com/openai/deployments/NEW-DEPLOYMENT-321/completions?api-version=2023-05-15',
'https://My-test-resource-123.openai.azure.com//openai/deployments/NEW-DEPLOYMENT-321/completions?api-version=2023-05-15',
'https:///My-test-resource-123.openai.azure.com/openai/deployments/NEW-DEPLOYMENT-321/completions?api-version=2023-05-15',
'https://My-test-resource-123.openaiazure.com/openai/deployments/NEW-DEPLOYMENT-321/not-completions?api-version=2023-05-15',
].forEach((url) => {
const match = url.match(regex);
expect(match).toBeNull();
Expand All @@ -202,12 +188,7 @@ describe('Azure Open AI Utils', () => {
it('should not match invalid completion extensions url', () => {
const regex = transformApiUrlToRegex(AZURE_OPENAI_COMPLETIONS_EXTENSIONS_URL);
[
'https://My-test-resource-123.openai.azure.com/openai/deployments/extensions/chat/completions?api-version=2023-05-15',
'https://My-test-resource-123.openaiazure.com/openai/deployments/NEW-DEPLOYMENT-321/extensions/chat/completions?api-version=2023-05-15',
'https://My-test-resource-123.openaiaazure.com/openai/deployments/NEW-DEPLOYMENT-321/extensions/chat/completions?api-version=2023-05-15',
'https://My-test-resource-123openai.azure.com/openai/deployments/NEW-DEPLOYMENT-321/extensions/chat/completions?api-version=2023-05-15',
'https:///My-test-resource-123.openai.azure.com/openai/deployments/NEW-DEPLOYMENT-321/extensions/chat/completions?api-version=2023-05-15',
'https://My-test-resource-123.openai.azure.com/openai//deployments/NEW-DEPLOYMENT-321/extensions/chat/completions?api-version=2023-05-15',
'https://My-test-resource-123.openai.azure.com/openai/deployments/extensions/chat/not-completions?api-version=2023-05-15',
].forEach((url) => {
const match = url.match(regex);
expect(match).toBeNull();
Expand Down

0 comments on commit 97b5479

Please sign in to comment.