Skip to content

Commit

Permalink
Update api.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
PushkarOP authored Oct 23, 2024
1 parent ddc206e commit 67b3a2f
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const executeRecaptcha = async (action: string): Promise<string> => {
};

const getSessionCookie = (): string | undefined => {
const name = 'session=';
const name = 'session_id=';
const decodedCookie = decodeURIComponent(document.cookie);
const ca = decodedCookie.split(';');
for (let i = 0; i < ca.length; i++) {
Expand All @@ -44,11 +44,9 @@ export const getChatCompletion = async (

const headers: HeadersInit = {
'Content-Type': 'application/json',
'X-Session-ID': '${sessionCookie}',
...customHeaders,
};
if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
if (sessionCookie) headers['Cookie'] = `session=${sessionCookie}`;

if (isAzureEndpoint(endpoint) && apiKey) {
headers['api-key'] = apiKey;
Expand Down Expand Up @@ -87,6 +85,7 @@ export const getChatCompletion = async (
messages,
...modifiedConfig, // Use modified config that excludes the penalties
max_tokens: undefined,
session: sessionCookie,
recaptcha_token: recaptchaToken
}),
});
Expand All @@ -108,11 +107,9 @@ export const getChatCompletionStream = async (

const headers: HeadersInit = {
'Content-Type': 'application/json',
'X-Session-ID': '${sessionCookie}',
...customHeaders,
};
if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
if (sessionCookie) headers['Cookie'] = `session=${sessionCookie}`;

if (isAzureEndpoint(endpoint) && apiKey) {
headers['api-key'] = apiKey;
Expand Down Expand Up @@ -150,6 +147,7 @@ export const getChatCompletionStream = async (
...modifiedConfig, // Use modified config that excludes the penalties
max_tokens: undefined,
stream: true,
session: sessionCookie,
recaptcha_token: recaptchaToken
}),
});
Expand Down Expand Up @@ -188,14 +186,11 @@ export const submitShareGPT = async (body: ShareGPTSubmitBodyInterface) => {
const recaptchaToken = await executeRecaptcha('submitShareGPT');
const sessionCookie = getSessionCookie();

const headers: HeadersInit = {
'Content-Type': 'application/json',
'X-Session-ID': '${sessionCookie}',
};

const request = await fetch('https://sharegpt.com/api/conversations', {
body: JSON.stringify({ ...body, recaptcha_token: recaptchaToken }),
headers,
body: JSON.stringify({ ...body, recaptcha_token: recaptchaToken, session: sessionCookie }),
headers: {
'Content-Type': 'application/json',
},
method: 'POST',
});

Expand Down

0 comments on commit 67b3a2f

Please sign in to comment.