Skip to content

Commit 50774ec

Browse files
authored
feat: add AI Gateway provider methods (crowdin#646)
1 parent ee73e7a commit 50774ec

2 files changed

Lines changed: 278 additions & 0 deletions

File tree

src/ai/index.ts

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,76 @@ export class Ai extends CrowdinApi {
520520
return this.get(url, this.defaultConfig());
521521
}
522522

523+
/**
524+
* @param aiProviderId ai Provider identifier
525+
* @param path raw provider API path after `/gateway/`
526+
* @see https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI-Gateway/operation/api.ai.providers.gateway.enterprise.get
527+
*/
528+
organizationAiGatewayGet(aiProviderId: number, path: string): Promise<ResponseObject<PlainObject>> {
529+
const url = `${this.url}/ai/providers/${aiProviderId}/gateway/${path}`;
530+
531+
return this.get(url, this.defaultConfig());
532+
}
533+
534+
/**
535+
* @param aiProviderId ai Provider identifier
536+
* @param path raw provider API path after `/gateway/`
537+
* @param request request body
538+
* @see https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI-Gateway/operation/api.ai.providers.gateway.enterprise.post
539+
*/
540+
organizationAiGatewayPost(
541+
aiProviderId: number,
542+
path: string,
543+
request?: PlainObject,
544+
): Promise<ResponseObject<PlainObject>> {
545+
const url = `${this.url}/ai/providers/${aiProviderId}/gateway/${path}`;
546+
547+
return this.post(url, request, this.defaultConfig());
548+
}
549+
550+
/**
551+
* @param aiProviderId ai Provider identifier
552+
* @param path raw provider API path after `/gateway/`
553+
* @param request request body
554+
* @see https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI-Gateway/operation/api.ai.providers.gateway.enterprise.put
555+
*/
556+
organizationAiGatewayPut(
557+
aiProviderId: number,
558+
path: string,
559+
request?: PlainObject,
560+
): Promise<ResponseObject<PlainObject>> {
561+
const url = `${this.url}/ai/providers/${aiProviderId}/gateway/${path}`;
562+
563+
return this.put(url, request, this.defaultConfig());
564+
}
565+
566+
/**
567+
* @param aiProviderId ai Provider identifier
568+
* @param path raw provider API path after `/gateway/`
569+
* @param request request body
570+
* @see https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI-Gateway/operation/api.ai.providers.gateway.enterprise.patch
571+
*/
572+
organizationAiGatewayPatch(
573+
aiProviderId: number,
574+
path: string,
575+
request?: PlainObject,
576+
): Promise<ResponseObject<PlainObject>> {
577+
const url = `${this.url}/ai/providers/${aiProviderId}/gateway/${path}`;
578+
579+
return this.patch(url, request, this.defaultConfig());
580+
}
581+
582+
/**
583+
* @param aiProviderId ai Provider identifier
584+
* @param path raw provider API path after `/gateway/`
585+
* @see https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI-Gateway/operation/api.ai.providers.gateway.enterprise.delete
586+
*/
587+
organizationAiGatewayDelete(aiProviderId: number, path: string): Promise<ResponseObject<PlainObject>> {
588+
const url = `${this.url}/ai/providers/${aiProviderId}/gateway/${path}`;
589+
590+
return this.delete(url, this.defaultConfig());
591+
}
592+
523593
// Community
524594

525595
/**
@@ -1112,6 +1182,84 @@ export class Ai extends CrowdinApi {
11121182

11131183
return this.get(url, this.defaultConfig());
11141184
}
1185+
1186+
/**
1187+
* @param userId user identifier
1188+
* @param aiProviderId ai Provider identifier
1189+
* @param path raw provider API path after `/gateway/`
1190+
* @see https://support.crowdin.com/developer/api/v2/#tag/AI-Gateway/operation/api.ai.providers.gateway.crowdin.get
1191+
*/
1192+
userAiGatewayGet(userId: number, aiProviderId: number, path: string): Promise<ResponseObject<PlainObject>> {
1193+
const url = `${this.url}/users/${userId}/ai/providers/${aiProviderId}/gateway/${path}`;
1194+
1195+
return this.get(url, this.defaultConfig());
1196+
}
1197+
1198+
/**
1199+
* @param userId user identifier
1200+
* @param aiProviderId ai Provider identifier
1201+
* @param path raw provider API path after `/gateway/`
1202+
* @param request request body
1203+
* @see https://support.crowdin.com/developer/api/v2/#tag/AI-Gateway/operation/api.ai.providers.gateway.crowdin.post
1204+
*/
1205+
userAiGatewayPost(
1206+
userId: number,
1207+
aiProviderId: number,
1208+
path: string,
1209+
request?: PlainObject,
1210+
): Promise<ResponseObject<PlainObject>> {
1211+
const url = `${this.url}/users/${userId}/ai/providers/${aiProviderId}/gateway/${path}`;
1212+
1213+
return this.post(url, request, this.defaultConfig());
1214+
}
1215+
1216+
/**
1217+
* @param userId user identifier
1218+
* @param aiProviderId ai Provider identifier
1219+
* @param path raw provider API path after `/gateway/`
1220+
* @param request request body
1221+
* @see https://support.crowdin.com/developer/api/v2/#tag/AI-Gateway/operation/api.ai.providers.gateway.crowdin.put
1222+
*/
1223+
userAiGatewayPut(
1224+
userId: number,
1225+
aiProviderId: number,
1226+
path: string,
1227+
request?: PlainObject,
1228+
): Promise<ResponseObject<PlainObject>> {
1229+
const url = `${this.url}/users/${userId}/ai/providers/${aiProviderId}/gateway/${path}`;
1230+
1231+
return this.put(url, request, this.defaultConfig());
1232+
}
1233+
1234+
/**
1235+
* @param userId user identifier
1236+
* @param aiProviderId ai Provider identifier
1237+
* @param path raw provider API path after `/gateway/`
1238+
* @param request request body
1239+
* @see https://support.crowdin.com/developer/api/v2/#tag/AI-Gateway/operation/api.ai.providers.gateway.crowdin.patch
1240+
*/
1241+
userAiGatewayPatch(
1242+
userId: number,
1243+
aiProviderId: number,
1244+
path: string,
1245+
request?: PlainObject,
1246+
): Promise<ResponseObject<PlainObject>> {
1247+
const url = `${this.url}/users/${userId}/ai/providers/${aiProviderId}/gateway/${path}`;
1248+
1249+
return this.patch(url, request, this.defaultConfig());
1250+
}
1251+
1252+
/**
1253+
* @param userId user identifier
1254+
* @param aiProviderId ai Provider identifier
1255+
* @param path raw provider API path after `/gateway/`
1256+
* @see https://support.crowdin.com/developer/api/v2/#tag/AI-Gateway/operation/api.ai.providers.gateway.crowdin.delete
1257+
*/
1258+
userAiGatewayDelete(userId: number, aiProviderId: number, path: string): Promise<ResponseObject<PlainObject>> {
1259+
const url = `${this.url}/users/${userId}/ai/providers/${aiProviderId}/gateway/${path}`;
1260+
1261+
return this.delete(url, this.defaultConfig());
1262+
}
11151263
}
11161264

11171265
export namespace AiModel {

tests/ai/api.test.ts

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,46 @@ describe('AI API', () => {
626626
url: link,
627627
},
628628
})
629+
.get(`/ai/providers/${aiProviderId}/gateway/chat/completions`, undefined, {
630+
reqheaders: {
631+
Authorization: `Bearer ${api.token}`,
632+
},
633+
})
634+
.reply(200, {
635+
data: field,
636+
})
637+
.post(`/ai/providers/${aiProviderId}/gateway/chat/completions`, field, {
638+
reqheaders: {
639+
Authorization: `Bearer ${api.token}`,
640+
},
641+
})
642+
.reply(200, {
643+
data: field,
644+
})
645+
.put(`/ai/providers/${aiProviderId}/gateway/chat/completions`, field, {
646+
reqheaders: {
647+
Authorization: `Bearer ${api.token}`,
648+
},
649+
})
650+
.reply(200, {
651+
data: field,
652+
})
653+
.patch(`/ai/providers/${aiProviderId}/gateway/chat/completions`, field, {
654+
reqheaders: {
655+
Authorization: `Bearer ${api.token}`,
656+
},
657+
})
658+
.reply(200, {
659+
data: field,
660+
})
661+
.delete(`/ai/providers/${aiProviderId}/gateway/chat/completions`, undefined, {
662+
reqheaders: {
663+
Authorization: `Bearer ${api.token}`,
664+
},
665+
})
666+
.reply(200, {
667+
data: field,
668+
})
629669
.get(`/users/${userId}/ai/settings/custom-placeholders`, undefined, {
630670
reqheaders: {
631671
Authorization: `Bearer ${api.token}`,
@@ -1185,6 +1225,46 @@ describe('AI API', () => {
11851225
data: {
11861226
url: link,
11871227
},
1228+
})
1229+
.get(`/users/${userId}/ai/providers/${aiProviderId}/gateway/chat/completions`, undefined, {
1230+
reqheaders: {
1231+
Authorization: `Bearer ${api.token}`,
1232+
},
1233+
})
1234+
.reply(200, {
1235+
data: field,
1236+
})
1237+
.post(`/users/${userId}/ai/providers/${aiProviderId}/gateway/chat/completions`, field, {
1238+
reqheaders: {
1239+
Authorization: `Bearer ${api.token}`,
1240+
},
1241+
})
1242+
.reply(200, {
1243+
data: field,
1244+
})
1245+
.put(`/users/${userId}/ai/providers/${aiProviderId}/gateway/chat/completions`, field, {
1246+
reqheaders: {
1247+
Authorization: `Bearer ${api.token}`,
1248+
},
1249+
})
1250+
.reply(200, {
1251+
data: field,
1252+
})
1253+
.patch(`/users/${userId}/ai/providers/${aiProviderId}/gateway/chat/completions`, field, {
1254+
reqheaders: {
1255+
Authorization: `Bearer ${api.token}`,
1256+
},
1257+
})
1258+
.reply(200, {
1259+
data: field,
1260+
})
1261+
.delete(`/users/${userId}/ai/providers/${aiProviderId}/gateway/chat/completions`, undefined, {
1262+
reqheaders: {
1263+
Authorization: `Bearer ${api.token}`,
1264+
},
1265+
})
1266+
.reply(200, {
1267+
data: field,
11881268
});
11891269
});
11901270

@@ -1461,6 +1541,31 @@ describe('AI API', () => {
14611541
expect(res.data.url).toBe(link);
14621542
});
14631543

1544+
it('Organization AI Gateway GET', async () => {
1545+
const res = await api.organizationAiGatewayGet(aiProviderId, 'chat/completions');
1546+
expect(res.data).toStrictEqual(field);
1547+
});
1548+
1549+
it('Organization AI Gateway POST', async () => {
1550+
const res = await api.organizationAiGatewayPost(aiProviderId, 'chat/completions', field);
1551+
expect(res.data).toStrictEqual(field);
1552+
});
1553+
1554+
it('Organization AI Gateway PUT', async () => {
1555+
const res = await api.organizationAiGatewayPut(aiProviderId, 'chat/completions', field);
1556+
expect(res.data).toStrictEqual(field);
1557+
});
1558+
1559+
it('Organization AI Gateway PATCH', async () => {
1560+
const res = await api.organizationAiGatewayPatch(aiProviderId, 'chat/completions', field);
1561+
expect(res.data).toStrictEqual(field);
1562+
});
1563+
1564+
it('Organization AI Gateway DELETE', async () => {
1565+
const res = await api.organizationAiGatewayDelete(aiProviderId, 'chat/completions');
1566+
expect(res.data).toStrictEqual(field);
1567+
});
1568+
14641569
it('List AI User Custom Placeholders', async () => {
14651570
const placeholders = await api.listAiUserCustomPlaceholders(userId);
14661571
expect(placeholders.data.length).toBe(1);
@@ -1729,4 +1834,29 @@ describe('AI API', () => {
17291834
const res = await api.downloadAiUserFileTranslationStrings(userId, jobId);
17301835
expect(res.data.url).toBe(link);
17311836
});
1837+
1838+
it('User AI Gateway GET', async () => {
1839+
const res = await api.userAiGatewayGet(userId, aiProviderId, 'chat/completions');
1840+
expect(res.data).toStrictEqual(field);
1841+
});
1842+
1843+
it('User AI Gateway POST', async () => {
1844+
const res = await api.userAiGatewayPost(userId, aiProviderId, 'chat/completions', field);
1845+
expect(res.data).toStrictEqual(field);
1846+
});
1847+
1848+
it('User AI Gateway PUT', async () => {
1849+
const res = await api.userAiGatewayPut(userId, aiProviderId, 'chat/completions', field);
1850+
expect(res.data).toStrictEqual(field);
1851+
});
1852+
1853+
it('User AI Gateway PATCH', async () => {
1854+
const res = await api.userAiGatewayPatch(userId, aiProviderId, 'chat/completions', field);
1855+
expect(res.data).toStrictEqual(field);
1856+
});
1857+
1858+
it('User AI Gateway DELETE', async () => {
1859+
const res = await api.userAiGatewayDelete(userId, aiProviderId, 'chat/completions');
1860+
expect(res.data).toStrictEqual(field);
1861+
});
17321862
});

0 commit comments

Comments
 (0)