Fix claude model not allowed error

This commit is contained in:
wong2
2023-12-25 12:10:42 +08:00
parent e30199bc2a
commit 14d617d1ef

View File

@@ -11,8 +11,14 @@ interface ConversationContext {
export class ClaudeWebBot extends AbstractBot {
private organizationId?: string
private conversationContext?: ConversationContext
private model: string
async doSendMessage(params: SendMessageParams) {
constructor() {
super()
this.model = 'claude-2.1'
}
async doSendMessage(params: SendMessageParams): Promise<void> {
if (!(await requestHostPermission('https://*.claude.ai/'))) {
throw new ChatError('Missing claude.ai permission', ErrorCode.MISSING_HOST_PERMISSION)
}
@@ -39,12 +45,20 @@ export class ClaudeWebBot extends AbstractBot {
text: params.prompt,
completion: {
prompt: params.prompt,
model: 'claude-2.1',
model: this.model,
},
attachments: [],
}),
})
// different models are available for different accounts
if (!resp.ok && resp.status === 403 && this.model === 'claude-2.1') {
if ((await resp.text()).includes('model_not_allowed')) {
this.model = 'claude-2.0'
return this.doSendMessage(params)
}
}
let result = ''
await parseSSEResponse(resp, (message) => {