File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments