Skip to content

Commit

Permalink
chore:merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
KavithaSiva committed Aug 8, 2024
2 parents dd434c6 + 63096c3 commit 19f7bbb
Show file tree
Hide file tree
Showing 18 changed files with 341 additions and 180 deletions.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@
"scripts": {
"postinstall": "pnpm compile",
"compile": "pnpm -r -w=false run compile",
"test": "pnpm -r run test",
"test": "NODE_OPTIONS=--experimental-vm-modules pnpm -r run test",
"test:type": "tsd",
"lint": "pnpm -r run lint",
"lint:fix": "pnpm -r run lint:fix"
},
"devDependencies": {
"@changesets/cli": "^2.27.7",
"@sap-cloud-sdk/eslint-config": "^3.17.0",
"@sap-cloud-sdk/connectivity": "^3.17.0",
"@sap-cloud-sdk/http-client": "^3.17.0",
"@sap-cloud-sdk/eslint-config": "^3.18.0",
"@sap-cloud-sdk/connectivity": "^3.18.0",
"@sap-cloud-sdk/http-client": "^3.18.0",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.14",
"@jest/globals": "^29.5.12",
"eslint": "^9.8.0",
"jest": "^30.0.0-alpha.3",
"nock": "^13.5.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/ai-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
],
"scripts": {
"compile": "tsc",
"test": "jest",
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"lint": "eslint . && prettier . --config ../../.prettierrc --ignore-path ../../.prettierignore -c",
"lint:fix": "eslint . --fix && prettier . --config ../../.prettierrc --ignore-path ../../.prettierignore -w --log-level error"
},
"dependencies": {
"@sap-cloud-sdk/openapi": "^3.17.0"
"@sap-cloud-sdk/openapi": "^3.18.0"
},
"devDependencies": {
"typescript": "^5.5.4"
Expand Down
4 changes: 1 addition & 3 deletions packages/gen-ai-hub/jest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import config from '../../jest.config.mjs';
const aiCoreConfig = {
export default {
...config,
displayName: 'gen-ai-hub',
};

export default aiCoreConfig;
10 changes: 5 additions & 5 deletions packages/gen-ai-hub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
],
"scripts": {
"compile": "tsc",
"test": "jest",
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"lint": "eslint . && prettier . --config ../../.prettierrc --ignore-path ../../.prettierignore -c",
"lint:fix": "eslint . --fix && prettier . --config ../../.prettierrc --ignore-path ../../.prettierignore -w --log-level error",
"generate": "openapi-generator -i ./src/orchestration/spec/ -o ./src/orchestration/client"
},
"dependencies": {
"@sap-cloud-sdk/http-client": "^3.17.0",
"@sap-cloud-sdk/connectivity": "^3.17.0",
"@sap-cloud-sdk/util": "^3.17.0"
"@sap-cloud-sdk/http-client": "^3.18.0",
"@sap-cloud-sdk/connectivity": "^3.18.0",
"@sap-cloud-sdk/util": "^3.18.0"
},
"devDependencies": {
"@sap-cloud-sdk/openapi-generator": "^3.17.0",
"@sap-cloud-sdk/openapi-generator": "^3.18.0",
"typescript": "^5.5.4",
"nock": "^13.5.4"
}
Expand Down
19 changes: 13 additions & 6 deletions packages/gen-ai-hub/src/client/openai/openai-client.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import nock from 'nock';
import { jest } from '@jest/globals';
import { HttpDestination } from '@sap-cloud-sdk/connectivity';
import { mockGetAiCoreDestination } from '../../../test-util/mock-context.js';
import { mockGetAiCoreDestination } from '../../test-util/mock-context.js';
import {
BaseLlmParametersWithDeploymentId,
EndpointOptions
} from '../../core/http-client.js';
import {
mockInference,
parseMockResponse
} from '../../../test-util/mock-http.js';
import { OpenAiClient } from './openai-client.js';
import { mockInference, parseMockResponse } from '../../test-util/mock-http.js';
import {
OpenAiChatCompletionOutput,
OpenAiChatCompletionParameters,
OpenAiChatMessage,
OpenAiEmbeddingOutput,
OpenAiEmbeddingParameters
} from './openai-types.js';
jest.unstable_mockModule('../../core/context.js', () => ({
getAiCoreDestination: jest.fn(() =>
Promise.resolve(mockGetAiCoreDestination())
)
}));
const { OpenAiClient } = await import('./openai-client.js');

describe('openai client', () => {
let destination: HttpDestination;
Expand Down Expand Up @@ -44,6 +47,10 @@ describe('openai client', () => {
nock.cleanAll();
});

afterAll(() => {
jest.restoreAllMocks();
});

describe('chatCompletion', () => {
it('parses a successful response', async () => {
const prompt = {
Expand Down
2 changes: 1 addition & 1 deletion packages/gen-ai-hub/src/core/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
mockAiCoreEnvVariable,
mockClientCredentialsGrantCall
} from '../../test-util/mock-context.js';
} from '../test-util/mock-context.js';
import { getAiCoreDestination } from './context.js';

describe('context', () => {
Expand Down
17 changes: 14 additions & 3 deletions packages/gen-ai-hub/src/core/http-client.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { jest } from '@jest/globals';
import { HttpDestination } from '@sap-cloud-sdk/connectivity';
import { mockGetAiCoreDestination } from '../../test-util/mock-context.js';
import { mockInference } from '../../test-util/mock-http.js';
import { executeRequest } from './http-client.js';
import { mockGetAiCoreDestination } from '../test-util/mock-context.js';
import { mockInference } from '../test-util/mock-http.js';

jest.unstable_mockModule('./context.js', () => ({
getAiCoreDestination: jest.fn(() =>
Promise.resolve(mockGetAiCoreDestination())
)
}));
const { executeRequest } = await import('./http-client.js');

describe('http-client', () => {
let destination: HttpDestination;
Expand All @@ -10,6 +17,10 @@ describe('http-client', () => {
destination = mockGetAiCoreDestination();
});

afterAll(() => {
jest.restoreAllMocks();
});

it('should execute a request to the AI Core service', async () => {
const mockPrompt = { prompt: 'some test prompt' };
const mockPromptResponse = { completion: 'some test completion' };
Expand Down
24 changes: 16 additions & 8 deletions packages/gen-ai-hub/src/orchestration/orchestration-client.test.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
import nock from 'nock';
import { jest } from '@jest/globals';
import { HttpDestination } from '@sap-cloud-sdk/connectivity';
import { mockGetAiCoreDestination } from '../../test-util/mock-context.js';
import { mockInference, parseMockResponse } from '../../test-util/mock-http.js';
import { mockGetAiCoreDestination } from '../test-util/mock-context.js';
import { mockInference, parseMockResponse } from '../test-util/mock-http.js';
import { BaseLlmParametersWithDeploymentId } from '../core/index.js';
import {
GenAiHubClient,
constructCompletionPostRequest
} from './orchestration-client.js';
import { CompletionPostResponse, FilteringModuleConfig } from './api/index.js';
import { GenAiHubCompletionParameters } from './orchestration-types.js';
import {
createFilterConfig,
createInputFilter,
createOutputFilter
} from './orchestration-filter-utility.js';
jest.unstable_mockModule('../core/context.js', () => ({
getAiCoreDestination: jest.fn(() =>
Promise.resolve(mockGetAiCoreDestination())
)
}));

const { GenAiHubClient, constructCompletionPostRequest } = await import(
'./orchestration-client.js'
);
describe('GenAiHubClient', () => {
let destination: HttpDestination;
let client: GenAiHubClient;
const client = new GenAiHubClient();
const deploymentConfiguration: BaseLlmParametersWithDeploymentId = {
deploymentId: 'deployment-id'
};

beforeAll(() => {
destination = mockGetAiCoreDestination();
client = new GenAiHubClient();
});

afterEach(() => {
nock.cleanAll();
});

afterAll(() => {
jest.restoreAllMocks();
});

it('calls chatCompletion with minimum configuration and parses response', async () => {
const request: GenAiHubCompletionParameters = {
deploymentConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
ServiceCredentials
} from '@sap-cloud-sdk/connectivity';
import nock from 'nock';
import * as context from '../src/core/context.js';

export const aiCoreServiceBinding = {
label: 'aicore',
Expand Down Expand Up @@ -54,11 +53,6 @@ export function mockGetAiCoreDestination(
authentication: 'OAuth2ClientCredentials',
...createDestinationTokens()
};

jest
.spyOn(context, 'getAiCoreDestination')
.mockResolvedValue(mockDestination);

return mockDestination;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { HttpDestination } from '@sap-cloud-sdk/connectivity';
import nock from 'nock';
import {
BaseLlmParameters,
CustomRequestConfig,
EndpointOptions
} from '../src/core/http-client.js';
} from '../core/http-client.js';

// Get the directory of this file
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const mockEndpoint: EndpointOptions = {
url: 'mock-endpoint',
Expand Down
Loading

0 comments on commit 19f7bbb

Please sign in to comment.