mirror of
https://github.com/chathub-dev/chathub.git
synced 2025-09-26 20:31:18 +08:00
Add arkose_token for gpt-4 webapp request
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { random } from 'lodash-es'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { ChatGPTWebModel } from '~services/user-config'
|
||||
import { ChatError, ErrorCode } from '~utils/errors'
|
||||
@@ -10,6 +11,24 @@ function removeCitations(text: string) {
|
||||
return text.replaceAll(/\u3010\d+\u2020source\u3011/g, '')
|
||||
}
|
||||
|
||||
function generateRandomHex(length: number) {
|
||||
let result = ''
|
||||
const characters = '0123456789abcdef'
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += characters.charAt(Math.floor(Math.random() * characters.length))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
function generateArkoseToken() {
|
||||
return `${generateRandomHex(
|
||||
17,
|
||||
)}|r=ap-southeast-1|meta=3|meta_width=300|metabgclr=transparent|metaiconclr=%23555555|guitextcolor=%23000000|pk=35536E1E-65B4-4D96-9D97-6ADB7EFF8147|at=40|sup=1|rid=${random(
|
||||
1,
|
||||
99,
|
||||
)}|ag=101|cdn_url=https%3A%2F%2Ftcr9i.chat.openai.com%2Fcdn%2Ffc|lurl=https%3A%2F%2Faudio-ap-southeast-1.arkoselabs.com|surl=https%3A%2F%2Ftcr9i.chat.openai.com|smurl=https%3A%2F%2Ftcr9i.chat.openai.com%2Fcdn%2Ffc%2Fassets%2Fstyle-manager`
|
||||
}
|
||||
|
||||
interface ConversationContext {
|
||||
conversationId: string
|
||||
lastMessageId: string
|
||||
@@ -25,7 +44,7 @@ export class ChatGPTWebBot extends AbstractBot {
|
||||
|
||||
private async getModelName(): Promise<string> {
|
||||
if (this.model === ChatGPTWebModel['GPT-4']) {
|
||||
return 'gpt-4-mobile'
|
||||
return 'gpt-4'
|
||||
}
|
||||
if (this.model === ChatGPTWebModel['GPT-4 Browsing']) {
|
||||
return 'gpt-4-browsing'
|
||||
@@ -66,6 +85,7 @@ export class ChatGPTWebBot extends AbstractBot {
|
||||
},
|
||||
],
|
||||
model: modelName,
|
||||
arkose_token: modelName.startsWith('gpt-4') ? generateArkoseToken() : undefined,
|
||||
conversation_id: this.conversationContext?.conversationId || undefined,
|
||||
parent_message_id: this.conversationContext?.lastMessageId || uuidv4(),
|
||||
}),
|
||||
|
Reference in New Issue
Block a user