From 591420d6094f8cd315c0667e995354275781045f Mon Sep 17 00:00:00 2001 From: Nicat <59221034+Nicat-dcw@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:13:30 +0400 Subject: [PATCH] Create api.ts --- src/providers/antrophic/api.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/providers/antrophic/api.ts diff --git a/src/providers/antrophic/api.ts b/src/providers/antrophic/api.ts new file mode 100644 index 0000000..6f9cab1 --- /dev/null +++ b/src/providers/antrophic/api.ts @@ -0,0 +1,33 @@ +export interface AntrophicFetchPayload { + apiKey: string + baseUrl: string + body: Record + signal?: AbortSignal +} + +export const fetchChatCompletion = async(payload: AntrophicFetchPayload) => { + const initOptions = { + headers: { + 'anthropic-version':'2023-06-01', + 'Content-Type': 'application/json', + 'x-api-key': ${payload.apiKey}`, + }, + method: 'POST', + body: JSON.stringify(payload.body), + signal: payload.signal, + } + return fetch(`${payload.baseUrl}/v1/messages`, initOptions) +} + +export const fetchImageGeneration = async(payload: AntrophicFetchPayload) => { + const initOptions = { + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${payload.apiKey}`, + }, + method: 'POST', + body: JSON.stringify(payload.body), + signal: payload.signal, + } + return fetch(`${payload.baseUrl}/v1/images/generations`, initOptions) +}