Skip to content

Commit 40b52dc

Browse files
authored
feat: list all ai models (#562)
1 parent 56e9d1e commit 40b52dc

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

src/ai/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,17 @@ export class Ai extends CrowdinApi {
355355
return this.getList(url, options?.limit, options?.offset);
356356
}
357357

358+
/**
359+
* @param options optional parameters for the request
360+
* @see https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.providers.models.enterprise.getMany
361+
*/
362+
listAiOrganizationAllProviderModels(
363+
options?: PaginationOptions,
364+
): Promise<ResponseList<AiModel.AiProviderModelResponse>> {
365+
const url = `${this.url}/ai/providers/models`;
366+
return this.getList(url, options?.limit, options?.offset);
367+
}
368+
358369
/**
359370
* @param aiProviderId ai Provider identifier
360371
* @param request request body
@@ -824,6 +835,20 @@ export class Ai extends CrowdinApi {
824835
return this.getList(url);
825836
}
826837

838+
/**
839+
* @param userId user identifier
840+
* @param options optional parameters for the request
841+
* @see https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.ai.providers.models.crowdin.getMany
842+
*
843+
*/
844+
listAiUserAllProviderModels(
845+
userId: number,
846+
options?: PaginationOptions,
847+
): Promise<ResponseList<AiModel.AiProviderModelResponse>> {
848+
const url = `${this.url}/users/${userId}/ai/providers/models`;
849+
return this.getList(url, options?.limit, options?.offset);
850+
}
851+
827852
/**
828853
* @param userId user Identifier
829854
* @param aiProviderId ai Provider identifier

tests/ai/api.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,24 @@ describe('AI API', () => {
450450
limit: limit,
451451
},
452452
})
453+
.get('/ai/providers/models', undefined, {
454+
reqheaders: {
455+
Authorization: `Bearer ${api.token}`,
456+
},
457+
})
458+
.reply(200, {
459+
data: [
460+
{
461+
data: {
462+
id: aiModelId,
463+
},
464+
},
465+
],
466+
pagination: {
467+
offset: 0,
468+
limit: limit,
469+
},
470+
})
453471
.post(`/ai/providers/${aiProviderId}/chat/completions`, field, {
454472
reqheaders: {
455473
Authorization: `Bearer ${api.token}`,
@@ -902,6 +920,24 @@ describe('AI API', () => {
902920
limit: limit,
903921
},
904922
})
923+
.get(`/users/${userId}/ai/providers/models`, undefined, {
924+
reqheaders: {
925+
Authorization: `Bearer ${api.token}`,
926+
},
927+
})
928+
.reply(200, {
929+
data: [
930+
{
931+
data: {
932+
id: aiModelId,
933+
},
934+
},
935+
],
936+
pagination: {
937+
offset: 0,
938+
limit: limit,
939+
},
940+
})
905941
.post(`/users/${userId}/ai/providers/${aiProviderId}/chat/completions`, field, {
906942
reqheaders: {
907943
Authorization: `Bearer ${api.token}`,
@@ -1158,6 +1194,13 @@ describe('AI API', () => {
11581194
expect(providers.pagination.limit).toBe(limit);
11591195
});
11601196

1197+
it('List AI Organization All Provider Models', async () => {
1198+
const providers = await api.listAiOrganizationAllProviderModels();
1199+
expect(providers.data.length).toBe(1);
1200+
expect(providers.data[0].data.id).toBe(aiModelId);
1201+
expect(providers.pagination.limit).toBe(limit);
1202+
});
1203+
11611204
it('Create AI Organization Proxy Chat Completion', async () => {
11621205
const proxy = await api.createAiOrganizationProxyChatCompletion(aiProviderId, field);
11631206
expect(proxy.data).toStrictEqual(field);
@@ -1376,6 +1419,13 @@ describe('AI API', () => {
13761419
expect(providers.pagination.limit).toBe(limit);
13771420
});
13781421

1422+
it('List AI User All Provider Models', async () => {
1423+
const providers = await api.listAiUserAllProviderModels(userId);
1424+
expect(providers.data.length).toBe(1);
1425+
expect(providers.data[0].data.id).toBe(aiModelId);
1426+
expect(providers.pagination.limit).toBe(limit);
1427+
});
1428+
13791429
it('Create AI User Proxy Chat Completion', async () => {
13801430
const proxy = await api.createAiUserProxyChatCompletion(userId, aiProviderId, field);
13811431
expect(proxy.data).toStrictEqual(field);

0 commit comments

Comments
 (0)