Skip to content

Commit 150f128

Browse files
committed
feat: spoourts using apiKey passed to it or crud read apikey
1 parent 7931c27 commit 150f128

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/server.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ class CoCreateOpenAi {
2020
try {
2121
let organization = await this.organizations[data.organization_id]
2222
if (!organization) {
23-
let apiKey = await this.getApiKey(data.organization_id, this.name)
24-
organization = new OpenAI({ apiKey });
25-
this.organizations[data.organization_id] = organization
23+
if (data.chat.apiKey) {
24+
organization = new OpenAI({ apiKey: data.chat.apiKey });
25+
this.organizations[data.organization_id] = organization
26+
} else {
27+
let apiKey = await this.getApiKey(data.organization_id, this.name)
28+
organization = new OpenAI({ apiKey });
29+
this.organizations[data.organization_id] = organization
30+
}
2631
}
2732

2833
const openai = organization
@@ -32,6 +37,7 @@ class CoCreateOpenAi {
3237
case 'chat.completions':
3338
case 'chat.completions.create':
3439
case 'openai.chat':
40+
delete data.chat.apiKey
3541
data.chat = await openai.chat.completions.create(data.chat);
3642
break;
3743
}
@@ -44,6 +50,10 @@ class CoCreateOpenAi {
4450
return data
4551
} catch (error) {
4652
console.error('OpenAi Error:', error);
53+
data.error = error.message
54+
let socket = data.socket
55+
delete data.socket
56+
socket.send(JSON.stringify(data))
4757
}
4858
}
4959

0 commit comments

Comments
 (0)