Skip to content

Commit 14d617d

Browse files
committed
Fix claude model not allowed error
1 parent e30199b commit 14d617d

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/app/bots/claude-web/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ interface ConversationContext {
1111
export class ClaudeWebBot extends AbstractBot {
1212
private organizationId?: string
1313
private conversationContext?: ConversationContext
14+
private model: string
1415

15-
async doSendMessage(params: SendMessageParams) {
16+
constructor() {
17+
super()
18+
this.model = 'claude-2.1'
19+
}
20+
21+
async doSendMessage(params: SendMessageParams): Promise<void> {
1622
if (!(await requestHostPermission('https://*.claude.ai/'))) {
1723
throw new ChatError('Missing claude.ai permission', ErrorCode.MISSING_HOST_PERMISSION)
1824
}
@@ -39,12 +45,20 @@ export class ClaudeWebBot extends AbstractBot {
3945
text: params.prompt,
4046
completion: {
4147
prompt: params.prompt,
42-
model: 'claude-2.1',
48+
model: this.model,
4349
},
4450
attachments: [],
4551
}),
4652
})
4753

54+
// different models are available for different accounts
55+
if (!resp.ok && resp.status === 403 && this.model === 'claude-2.1') {
56+
if ((await resp.text()).includes('model_not_allowed')) {
57+
this.model = 'claude-2.0'
58+
return this.doSendMessage(params)
59+
}
60+
}
61+
4862
let result = ''
4963

5064
await parseSSEResponse(resp, (message) => {

0 commit comments

Comments
 (0)