diff --git a/src/ai/index.ts b/src/ai/index.ts index d027d5cad..874636818 100644 --- a/src/ai/index.ts +++ b/src/ai/index.ts @@ -1,11 +1,11 @@ import { CrowdinApi, PaginationOptions, PatchRequest, ResponseList, ResponseObject } from '../core'; -export class AI extends CrowdinApi { +export class Ai extends CrowdinApi { /** * @param options optional parameters for the request * @see https://developer.crowdin.com/enterprise/api/v2/#operation/api.ai.prompts.getMany */ - listAIPrompts(options?: AIModel.ListAIPromptsOptions): Promise> { + listAiOrganizationPrompts(options?: AiModel.ListAiPromptsOptions): Promise> { let url = `${this.url}/ai/prompts`; url = this.addQueryParam(url, 'projectId', options?.projectId); url = this.addQueryParam(url, 'action', options?.action); @@ -17,7 +17,7 @@ export class AI extends CrowdinApi { * @param request request body * @see https://developer.crowdin.com/enterprise/api/v2/#operation/api.ai.prompts.post */ - addAIPrompt(request: AIModel.AddAIPromptRequest): Promise> { + addAiOrganizationPrompt(request: AiModel.AddAiPromptRequest): Promise> { const url = `${this.url}/ai/prompts`; return this.post(url, request, this.defaultConfig()); @@ -27,7 +27,7 @@ export class AI extends CrowdinApi { * @param aiPromptId ai Prompt identifier. * @see https://developer.crowdin.com/enterprise/api/v2/#operation/api.ai.prompts.get */ - getAIPrompt(aiPromptId: number): Promise> { + getAiOrganizationPrompt(aiPromptId: number): Promise> { const url = `${this.url}/ai/prompts/${aiPromptId}`; return this.get(url, this.defaultConfig()); @@ -37,7 +37,7 @@ export class AI extends CrowdinApi { * @param aiPromptId ai Prompt identifier. * @see https://developer.crowdin.com/enterprise/api/v2/#operation/api.ai.prompts.delete */ - deleteAIPrompt(aiPromptId: number): Promise { + deleteAiOrganizationPrompt(aiPromptId: number): Promise { const url = `${this.url}/ai/prompts/${aiPromptId}`; return this.delete(url, this.defaultConfig()); @@ -48,7 +48,10 @@ export class AI extends CrowdinApi { * @param request request body * @see https://developer.crowdin.com/enterprise/api/v2/#operation/api.ai.prompts.patch */ - editAIPrompt(aiPromptId: number, request: PatchRequest[]): Promise> { + editAiOrganizationPrompt( + aiPromptId: number, + request: PatchRequest[], + ): Promise> { const url = `${this.url}/ai/prompts/${aiPromptId}`; return this.patch(url, request, this.defaultConfig()); @@ -58,7 +61,7 @@ export class AI extends CrowdinApi { * @param options optional parameters for the request * @see https://developer.crowdin.com/enterprise/api/v2/#operation/api.ai.providers.getMany */ - listAIProviders(options?: PaginationOptions): Promise> { + listAiOrganizationProviders(options?: PaginationOptions): Promise> { const url = `${this.url}/ai/providers`; return this.getList(url, options?.limit, options?.offset); @@ -68,7 +71,9 @@ export class AI extends CrowdinApi { * @param request request body * @see https://developer.crowdin.com/enterprise/api/v2/#operation/api.ai.providers.post */ - addAIProvider(request: AIModel.AddAIProviderRequest): Promise> { + addAiOrganizationProvider( + request: AiModel.AddAiProviderRequest, + ): Promise> { const url = `${this.url}/ai/providers`; return this.post(url, request, this.defaultConfig()); @@ -78,7 +83,7 @@ export class AI extends CrowdinApi { * @param aiProviderId ai Provider identifier. * @see https://developer.crowdin.com/enterprise/api/v2/#operation/api.ai.providers.get */ - getAIProvider(aiProviderId: number): Promise> { + getAiOrganizationProvider(aiProviderId: number): Promise> { const url = `${this.url}/ai/providers/${aiProviderId}`; return this.get(url, this.defaultConfig()); @@ -88,7 +93,7 @@ export class AI extends CrowdinApi { * @param aiProviderId ai Provider identifier. * @see https://developer.crowdin.com/enterprise/api/v2/#operation/api.ai.providers.delete */ - deleteAIProvider(aiProviderId: number): Promise { + deleteAiOrganizationProvider(aiProviderId: number): Promise { const url = `${this.url}/ai/providers/${aiProviderId}`; return this.delete(url, this.defaultConfig()); @@ -99,7 +104,10 @@ export class AI extends CrowdinApi { * @param request request body * @see https://developer.crowdin.com/enterprise/api/v2/#operation/api.ai.providers.patch */ - editAIProvider(aiProviderId: number, request: PatchRequest[]): Promise> { + editAiOrganizationProvider( + aiProviderId: number, + request: PatchRequest[], + ): Promise> { const url = `${this.url}/ai/providers/${aiProviderId}`; return this.patch(url, request, this.defaultConfig()); @@ -110,10 +118,10 @@ export class AI extends CrowdinApi { * @param options optional parameters for the request * @see https://developer.crowdin.com/enterprise/api/v2/#operation/api.ai.providers.models.getMany */ - listAIProviderModels( + listAiOrganizationProviderModels( aiProviderId: number, options?: PaginationOptions, - ): Promise> { + ): Promise> { let url = `${this.url}/ai/providers/${aiProviderId}/models`; url = this.addQueryParam(url, 'limit', options?.limit); url = this.addQueryParam(url, 'offset', options?.offset); @@ -122,53 +130,220 @@ export class AI extends CrowdinApi { } /** - * @param userId User Identifier + * @param aiProviderId ai Provider identifier + * @param request request body + * @see https://developer.crowdin.com/enterprise/api/v2/#operation/api.ai.providers.chat.completions.post + */ + createAiOrganizationProxyChatCompletion( + aiProviderId: number, + request?: AiModel.OtherChatCompletionRequest | AiModel.GoogleGeminiChatCompletionRequest, + ): Promise> { + const url = `${this.url}/ai/providers/${aiProviderId}/chat/completions`; + + return this.post(url, request, this.defaultConfig()); + } + + /** + * @param userId user identifier + * @param options optional parameters for the request + * @see https://developer.crowdin.com/api/v2/#operation/api.users.ai.prompts.post + */ + listAiUserPrompts( + userId: number, + options?: AiModel.ListAiPromptsOptions, + ): Promise> { + let url = `${this.url}/users/${userId}/ai/prompts`; + + url = this.addQueryParam(url, 'projectId', options?.projectId); + url = this.addQueryParam(url, 'action', options?.action); + + return this.getList(url, options?.limit, options?.offset); + } + + /** + * @param userId user identifier + * @param request request body + * @see https://developer.crowdin.com/api/v2/#operation/api.users.ai.prompts.post + */ + addAiUserPrompt( + userId: number, + request: AiModel.AddAiPromptRequest, + ): Promise> { + const url = `${this.url}/users/${userId}/ai/prompts`; + + return this.post(url, request, this.defaultConfig()); + } + + /** + * @param userId user identifier + * @param aiPromptId ai Prompt identifier. + * @see https://developer.crowdin.com/api/v2/#operation/api.users.ai.prompts.get + */ + getAiUserPrompt(userId: number, aiPromptId: number): Promise> { + const url = `${this.url}/users/${userId}/ai/prompts/${aiPromptId}`; + + return this.get(url, this.defaultConfig()); + } + + /** + * @param userId user identifier + * @param aiPromptId ai Prompt identifier. + * @see https://developer.crowdin.com/api/v2/#operation/api.users.ai.prompts.delete + */ + deleteAiUserPrompt(userId: number, aiPromptId: number): Promise { + const url = `${this.url}/users/${userId}/ai/prompts/${aiPromptId}`; + + return this.delete(url, this.defaultConfig()); + } + + /** + * @param userId user identifier + * @param aiPromptId ai Prompt identifier + * @param request request body + * @see https://developer.crowdin.com/api/v2/#operation/api.users.ai.prompts.patch + */ + editAiUserPrompt( + userId: number, + aiPromptId: number, + request: PatchRequest[], + ): Promise> { + const url = `${this.url}/users/${userId}/ai/prompts/${aiPromptId}`; + + return this.patch(url, request, this.defaultConfig()); + } + + /** + * @param userId user identifier + * @param options optional parameters for the request + * @see https://developer.crowdin.com/api/v2/#operation/api.ai.providers.getMany + */ + listAiUserProviders( + userId: number, + options?: PaginationOptions, + ): Promise> { + const url = `${this.url}/users/${userId}/ai/providers`; + + return this.getList(url, options?.limit, options?.offset); + } + + /** + * @param userId user identifier + * @param request request body + * @see https://developer.crowdin.com/api/v2/#operation/api.users.ai.providers.post + */ + addAiUserProvider( + userId: number, + request: AiModel.AddAiProviderRequest, + ): Promise> { + const url = `${this.url}/users/${userId}/ai/providers`; + + return this.post(url, request, this.defaultConfig()); + } + + /** + * @param userId user identifier + * @param aiProviderId ai Provider identifier. + * @see https://developer.crowdin.com/api/v2/#operation/api.users.ai.providers.get + */ + getAiUserProvider(userId: number, aiProviderId: number): Promise> { + const url = `${this.url}/users/${userId}/ai/providers/${aiProviderId}`; + + return this.get(url, this.defaultConfig()); + } + + /** + * @param userId user identifier + * @param aiProviderId ai Provider identifier. + * @see https://developer.crowdin.com/api/v2/#operation/api.users.ai.providers.delete + */ + deleteAiUserProvider(userId: number, aiProviderId: number): Promise { + const url = `${this.url}/users/${userId}/ai/providers/${aiProviderId}`; + + return this.delete(url, this.defaultConfig()); + } + + /** + * @param userId user identifier + * @param aiProviderId ai Provider identifier + * @param request request body + * @see https://developer.crowdin.com/api/v2/#operation/api.users.ai.providers.patch + */ + editAiUserProvider( + userId: number, + aiProviderId: number, + request: PatchRequest[], + ): Promise> { + const url = `${this.url}/users/${userId}/ai/providers/${aiProviderId}`; + + return this.patch(url, request, this.defaultConfig()); + } + + /** + * @param userId user identifier + * @param aiProviderId ai Provider identifier + * @param options optional parameters for the request + * @see https://developer.crowdin.com/api/v2/#operation/api.ai.providers.models.getMany + */ + listAiUserProviderModels( + userId: number, + aiProviderId: number, + options?: PaginationOptions, + ): Promise> { + let url = `${this.url}/users/${userId}/ai/providers/${aiProviderId}/models`; + url = this.addQueryParam(url, 'limit', options?.limit); + url = this.addQueryParam(url, 'offset', options?.offset); + + return this.getList(url); + } + + /** + * @param userId user Identifier * @param aiProviderId ai Provider identifier * @param request request body * @see https://developer.crowdin.com/api/v2/#operation/api.users.ai.providers.chat.completions.post */ - createAIProxyChatCompletion( + createAiUserProxyChatCompletion( userId: number, aiProviderId: number, - request?: AIModel.OtherChatCompletionRequest | AIModel.GoogleGeminiChatCompletionRequest, - ): Promise> { + request?: AiModel.OtherChatCompletionRequest | AiModel.GoogleGeminiChatCompletionRequest, + ): Promise> { const url = `${this.url}/users/${userId}/ai/providers/${aiProviderId}/chat/completions`; return this.post(url, request, this.defaultConfig()); } } -export namespace AIModel { +export namespace AiModel { /* ai Prompts Section START*/ - export interface ListAIPromptsOptions extends PaginationOptions { + export interface ListAiPromptsOptions extends PaginationOptions { projectId?: number; action?: string; } - export interface AIPromptResponse { + export interface AiPromptResponse { id: number; name: string; action: string; aiProviderId: number; - aiModelId: string; + AiModelId: string; isEnabled: boolean; enabledProjectIds: number[]; - config: AIModel.AIPromptConfigBasic | AIModel.AIPromptConfigAdvanced; + config: AiModel.AiPromptConfigBasic | AiModel.AiPromptConfigAdvanced; createdAt: string; updatedAt: string; } - export interface AIPromptConfigBasicOtherLanguageTranslations { + export interface AiPromptConfigBasicOtherLanguageTranslations { isEnabled?: boolean; languageIds?: string[]; } - export interface AIPromptConfigBasic { + export interface AiPromptConfigBasic { mode: 'basic'; companyDescription?: string; projectDescription?: string; audienceDescription?: string; - otherLanguageTranslations?: AIModel.AIPromptConfigBasicOtherLanguageTranslations; + otherLanguageTranslations?: AiModel.AiPromptConfigBasicOtherLanguageTranslations; glossaryTerms?: boolean; tmSuggestions?: boolean; fileContent?: boolean; @@ -176,83 +351,83 @@ export namespace AIModel { publicProjectDescription?: boolean; } - export interface AIPromptConfigAdvanced { + export interface AiPromptConfigAdvanced { mode: 'advanced'; prompt: string; } - export interface AddAIPromptRequest { + export interface AddAiPromptRequest { name: string; action: string; aiProviderId: number; aiModelId: string; isEnabled?: boolean; enabledProjectIds?: number[]; - config: AIModel.AIPromptConfigBasic | AIModel.AIPromptConfigAdvanced; + config: AiModel.AiPromptConfigBasic | AiModel.AiPromptConfigAdvanced; } /* ai Prompts Section END*/ /* ai Providers Section START*/ - export interface AIProviderResponse { + export interface AiProviderResponse { id: number; name: string; type: string; credentials: - | AIModel.AIProviderCredentialsOpenAI - | AIModel.AIProviderCredentialsAzureOpenAI - | AIProviderCredentialsGoogleGemini; - config: AIModel.AIProviderConfig; + | AiModel.AiProviderCredentialsOpenAi + | AiModel.AiProviderCredentialsAzureOpenAi + | AiProviderCredentialsGoogleGemini; + config: AiModel.AiProviderConfig; isEnabled: boolean; createdAt: string; updatedAt: string; } - export interface AIProviderCredentialsOpenAI { + export interface AiProviderCredentialsOpenAi { apiKey: string; } - export interface AIProviderCredentialsAzureOpenAI { + export interface AiProviderCredentialsAzureOpenAi { resourceName: string; apiKey: string; deploymentName: string; apiVersion: string; } - export interface AIProviderCredentialsGoogleGemini { + export interface AiProviderCredentialsGoogleGemini { project: string; region: string; serviceAccountKey: string; } - export interface AIProviderConfig { - actionRules?: AIModel.AIProviderConfigActionRule[]; + export interface AiProviderConfig { + actionRules?: AiModel.AiProviderConfigActionRule[]; } - export interface AIProviderConfigActionRule { + export interface AiProviderConfigActionRule { action?: string; availableAiModelIds?: string[]; } - export interface AddAIProviderRequest { + export interface AddAiProviderRequest { name: string; type: string; credentials: - | AIModel.AIProviderCredentialsOpenAI - | AIModel.AIProviderCredentialsAzureOpenAI - | AIProviderCredentialsGoogleGemini; - config?: AIModel.AIProviderConfig; + | AiModel.AiProviderCredentialsOpenAi + | AiModel.AiProviderCredentialsAzureOpenAi + | AiProviderCredentialsGoogleGemini; + config?: AiModel.AiProviderConfig; isEnabled?: boolean; } /* ai Providers Section END*/ /* ai Provider Models Section START*/ - export interface AIProviderModelResponse { + export interface AiProviderModelResponse { id: string; } /* ai Provider Models Section END*/ /* ai Provider Models Section START*/ - export interface AIProviderProxyResponseData { + export interface AiProviderProxyResponseData { data: object; } /* ai Provider Models Section END*/ diff --git a/src/index.ts b/src/index.ts index aed421933..919f9ae43 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import { AI } from './ai'; +import { Ai } from './ai'; import { Applications } from './applications'; import { Bundles } from './bundles'; import { Clients } from './clients'; @@ -70,7 +70,7 @@ export * from './workflows'; * @internal */ export default class Client extends CrowdinApi { - readonly AIApi: AI; + readonly aiApi: Ai; readonly applicationsApi: Applications; readonly sourceFilesApi: SourceFiles; readonly glossariesApi: Glossaries; @@ -108,7 +108,7 @@ export default class Client extends CrowdinApi { constructor(credentials: Credentials, config?: ClientConfig) { super(credentials, config); - this.AIApi = new AI(credentials, config); + this.aiApi = new Ai(credentials, config); this.applicationsApi = new Applications(credentials, config); this.sourceFilesApi = new SourceFiles(credentials, config); this.glossariesApi = new Glossaries(credentials, config); diff --git a/tests/ai/api.test.ts b/tests/ai/api.test.ts index 57107909f..fa77c8268 100644 --- a/tests/ai/api.test.ts +++ b/tests/ai/api.test.ts @@ -1,5 +1,5 @@ import * as nock from 'nock'; -import { AI, AIModel, Credentials } from '../../src'; +import { Ai, AiModel, Credentials } from '../../src'; describe('AI API', () => { let scope: nock.Scope; @@ -7,7 +7,7 @@ describe('AI API', () => { token: 'testToken', organization: 'testOrg', }; - const api: AI = new AI(userCredentials); + const api: Ai = new Ai(userCredentials); const aiPromptId = 3; const aiProviderId = 4; @@ -18,7 +18,7 @@ describe('AI API', () => { const action = 'promptAction'; const mode = 'advanced'; const prompt = 'translate '; - const config: AIModel.AIPromptConfigAdvanced = { + const config: AiModel.AiPromptConfigAdvanced = { mode, prompt, }; @@ -197,6 +197,178 @@ describe('AI API', () => { limit: limit, }, }) + .post(`/ai/providers/${aiProviderId}/chat/completions`, field, { + reqheaders: { + Authorization: `Bearer ${api.token}`, + }, + }) + .reply(200, { + data: field, + }) + .get(`/users/${userId}/ai/prompts`, undefined, { + reqheaders: { + Authorization: `Bearer ${api.token}`, + }, + }) + .reply(200, { + data: [ + { + data: { + id: aiPromptId, + }, + }, + ], + pagination: { + offset: 0, + limit: limit, + }, + }) + .post( + `/users/${userId}/ai/prompts`, + { + name, + action, + aiProviderId, + aiModelId, + config, + }, + { + reqheaders: { + Authorization: `Bearer ${api.token}`, + }, + }, + ) + .reply(200, { + data: { + id: aiPromptId, + }, + }) + .get(`/users/${userId}/ai/prompts/${aiPromptId}`, undefined, { + reqheaders: { + Authorization: `Bearer ${api.token}`, + }, + }) + .reply(200, { + data: { + id: aiPromptId, + }, + }) + .delete(`/users/${userId}/ai/prompts/${aiPromptId}`, undefined, { + reqheaders: { + Authorization: `Bearer ${api.token}`, + }, + }) + .reply(200) + .patch( + `/users/${userId}/ai/prompts/${aiPromptId}`, + [ + { + value: name, + op: 'replace', + path: '/name', + }, + ], + { + reqheaders: { + Authorization: `Bearer ${api.token}`, + }, + }, + ) + .reply(200, { + data: { + id: aiPromptId, + }, + }) + .get(`/users/${userId}/ai/providers`, undefined, { + reqheaders: { + Authorization: `Bearer ${api.token}`, + }, + }) + .reply(200, { + data: [ + { + data: { + id: aiProviderId, + }, + }, + ], + pagination: { + offset: 0, + limit: limit, + }, + }) + .post( + `/users/${userId}/ai/providers`, + { + name, + type, + credentials, + }, + { + reqheaders: { + Authorization: `Bearer ${api.token}`, + }, + }, + ) + .reply(200, { + data: { + id: aiProviderId, + }, + }) + .get(`/users/${userId}/ai/providers/${aiProviderId}`, undefined, { + reqheaders: { + Authorization: `Bearer ${api.token}`, + }, + }) + .reply(200, { + data: { + id: aiProviderId, + }, + }) + .delete(`/users/${userId}/ai/providers/${aiProviderId}`, undefined, { + reqheaders: { + Authorization: `Bearer ${api.token}`, + }, + }) + .reply(200) + .patch( + `/users/${userId}/ai/providers/${aiProviderId}`, + [ + { + value: name, + op: 'replace', + path: '/name', + }, + ], + { + reqheaders: { + Authorization: `Bearer ${api.token}`, + }, + }, + ) + .reply(200, { + data: { + id: aiProviderId, + }, + }) + .get(`/users/${userId}/ai/providers/${aiProviderId}/models`, undefined, { + reqheaders: { + Authorization: `Bearer ${api.token}`, + }, + }) + .reply(200, { + data: [ + { + data: { + id: aiModelId, + }, + }, + ], + pagination: { + offset: 0, + limit: limit, + }, + }) .post(`/users/${userId}/ai/providers/${aiProviderId}/chat/completions`, field, { reqheaders: { Authorization: `Bearer ${api.token}`, @@ -210,16 +382,101 @@ describe('AI API', () => { afterAll(() => { scope.done(); }); + it('List AI Organization Prompts', async () => { + const prompts = await api.listAiOrganizationPrompts(); + expect(prompts.data.length).toBe(1); + expect(prompts.data[0].data.id).toBe(aiPromptId); + expect(prompts.pagination.limit).toBe(limit); + }); + + it('Add AI Organization Prompt', async () => { + const prompt = await api.addAiOrganizationPrompt({ + name, + action, + aiProviderId, + aiModelId, + config, + }); + expect(prompt.data.id).toBe(aiPromptId); + }); + + it('Get AI Organization Prompt', async () => { + const prompt = await api.getAiOrganizationPrompt(aiPromptId); + expect(prompt.data.id).toBe(aiPromptId); + }); + + it('Delete AI Organization Prompt', async () => { + await api.deleteAiOrganizationPrompt(aiPromptId); + }); + + it('Edit AI Organization Prompt', async () => { + const prompt = await api.editAiOrganizationPrompt(aiPromptId, [ + { + op: 'replace', + path: '/name', + value: name, + }, + ]); + expect(prompt.data.id).toBe(aiPromptId); + }); + + it('List AI Organization Providers', async () => { + const providers = await api.listAiOrganizationProviders(); + expect(providers.data.length).toBe(1); + expect(providers.data[0].data.id).toBe(aiProviderId); + expect(providers.pagination.limit).toBe(limit); + }); + + it('Add AI Organization Provider', async () => { + const provider = await api.addAiOrganizationProvider({ + name, + type, + credentials, + }); + expect(provider.data.id).toBe(aiProviderId); + }); + + it('Get AI Organization Provider', async () => { + const provider = await api.getAiOrganizationProvider(aiProviderId); + expect(provider.data.id).toBe(aiProviderId); + }); + + it('Delete AI Organization Provider', async () => { + await api.deleteAiOrganizationProvider(aiProviderId); + }); + + it('Edit AI Organization Provider', async () => { + const provider = await api.editAiOrganizationProvider(aiProviderId, [ + { + op: 'replace', + path: '/name', + value: name, + }, + ]); + expect(provider.data.id).toBe(aiProviderId); + }); + + it('List AI Organization Provider Models', async () => { + const providers = await api.listAiOrganizationProviderModels(aiProviderId); + expect(providers.data.length).toBe(1); + expect(providers.data[0].data.id).toBe(aiModelId); + expect(providers.pagination.limit).toBe(limit); + }); + + it('Create AI Organization Proxy Chat Completion', async () => { + const proxy = await api.createAiOrganizationProxyChatCompletion(aiProviderId, field); + expect(proxy.data).toStrictEqual(field); + }); - it('List AI Prompts', async () => { - const prompts = await api.listAIPrompts(); + it('List AI User Prompts', async () => { + const prompts = await api.listAiUserPrompts(userId); expect(prompts.data.length).toBe(1); expect(prompts.data[0].data.id).toBe(aiPromptId); expect(prompts.pagination.limit).toBe(limit); }); - it('Add AI Prompt', async () => { - const prompt = await api.addAIPrompt({ + it('Add AI User Prompt', async () => { + const prompt = await api.addAiUserPrompt(userId, { name, action, aiProviderId, @@ -229,17 +486,17 @@ describe('AI API', () => { expect(prompt.data.id).toBe(aiPromptId); }); - it('Get AI Prompt', async () => { - const prompt = await api.getAIPrompt(aiPromptId); + it('Get AI User Prompt', async () => { + const prompt = await api.getAiUserPrompt(userId, aiPromptId); expect(prompt.data.id).toBe(aiPromptId); }); - it('Delete AI Prompt', async () => { - await api.deleteAIPrompt(aiPromptId); + it('Delete AI User Prompt', async () => { + await api.deleteAiUserPrompt(userId, aiPromptId); }); - it('Edit AI Prompt', async () => { - const prompt = await api.editAIPrompt(aiPromptId, [ + it('Edit AI User Prompt', async () => { + const prompt = await api.editAiUserPrompt(userId, aiPromptId, [ { op: 'replace', path: '/name', @@ -249,15 +506,15 @@ describe('AI API', () => { expect(prompt.data.id).toBe(aiPromptId); }); - it('List AI Providers', async () => { - const providers = await api.listAIProviders(); + it('List AI User Providers', async () => { + const providers = await api.listAiUserProviders(userId); expect(providers.data.length).toBe(1); expect(providers.data[0].data.id).toBe(aiProviderId); expect(providers.pagination.limit).toBe(limit); }); - it('Add AI Provider', async () => { - const provider = await api.addAIProvider({ + it('Add AI User Provider', async () => { + const provider = await api.addAiUserProvider(userId, { name, type, credentials, @@ -265,17 +522,17 @@ describe('AI API', () => { expect(provider.data.id).toBe(aiProviderId); }); - it('Get AI Provider', async () => { - const provider = await api.getAIProvider(aiProviderId); + it('Get AI User Provider', async () => { + const provider = await api.getAiUserProvider(userId, aiProviderId); expect(provider.data.id).toBe(aiProviderId); }); - it('Delete AI Provider', async () => { - await api.deleteAIProvider(aiProviderId); + it('Delete AI User Provider', async () => { + await api.deleteAiUserProvider(userId, aiProviderId); }); - it('Edit AI Provider', async () => { - const provider = await api.editAIProvider(aiProviderId, [ + it('Edit AI User Provider', async () => { + const provider = await api.editAiUserProvider(userId, aiProviderId, [ { op: 'replace', path: '/name', @@ -285,15 +542,15 @@ describe('AI API', () => { expect(provider.data.id).toBe(aiProviderId); }); - it('List AI Provider Models', async () => { - const providers = await api.listAIProviderModels(aiProviderId); + it('List AI User Provider Models', async () => { + const providers = await api.listAiUserProviderModels(userId, aiProviderId); expect(providers.data.length).toBe(1); expect(providers.data[0].data.id).toBe(aiModelId); expect(providers.pagination.limit).toBe(limit); }); - it('Create AI Proxy Chat Completion', async () => { - const proxy = await api.createAIProxyChatCompletion(userId, aiProviderId, field); + it('Create AI User Proxy Chat Completion', async () => { + const proxy = await api.createAiUserProxyChatCompletion(userId, aiProviderId, field); expect(proxy.data).toStrictEqual(field); }); });