Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arkose token header #20

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/clients/chatgpt-api/arkose/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { fetchArkoseToken } from './server';

export async function getArkoseToken() {
const token = await fetchArkoseToken();
if (!token) {
return '';
}

return token;
}
20 changes: 20 additions & 0 deletions src/clients/chatgpt-api/arkose/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { isEmpty } from 'lodash-es';

export async function fetchArkoseToken(): Promise<string | undefined> {
try {
const resp = await fetch('https://arkose-bypass-api.vercel.app/api/token');

if (!resp.ok) {
const error = (await resp.json().catch(() => ({}))) as Error;
const errorMessage = await resp.text();
throw new Error(!isEmpty(error) ? JSON.stringify(error) : `${resp.status} ${errorMessage || resp.statusText}`);
}

const data = (await resp.json()) as { token: string };

return data.token;
} catch (err) {
console.error(err);
return undefined;
}
}
3 changes: 3 additions & 0 deletions src/clients/chatgpt-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ISSEChatGPTResponse } from '../../interfaces';
import { ClientError, ErrorCode } from '../../utils/errors';
import { parseSSE } from '../../utils/sse';
import { AbstractClient, IGenerateResponseParams } from '../abstract';
import { getArkoseToken } from './arkose';
import { chatGPTClient } from './client';

interface ConversationContext {
Expand All @@ -21,6 +22,7 @@ export class ChatGPTApiClient extends AbstractClient {
if (!this.accessToken) this.accessToken = await chatGPTClient.getAccessToken();

const currentModel = await this.getCurrentModel();
const arkoseToken = await getArkoseToken();

const resp = await chatGPTClient.fetch('https://chat.openai.com/backend-api/conversation', {
method: 'POST',
Expand All @@ -44,6 +46,7 @@ export class ChatGPTApiClient extends AbstractClient {
model: currentModel,
conversation_id: this.conversationCtx?.conversationId || undefined,
parent_message_id: this.conversationCtx?.lastMessageId || uuid(),
arkose_token: arkoseToken,
}),
});

Expand Down