Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 46cfd38

Browse files
authored
fix: chat completion endpoint is hang (#877)
1 parent 9ed712b commit 46cfd38

File tree

5 files changed

+8
-12
lines changed

5 files changed

+8
-12
lines changed

cortex-js/src/domain/abstracts/oai.abstract.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ export abstract class OAIEngineExtension extends EngineExtension {
2020
): Promise<stream.Readable | any> {
2121
const payload = this.transformPayload ? this.transformPayload(createChatDto) : createChatDto;
2222
const { stream: isStream } = payload;
23-
const additionalHeaders = _.omit(headers, ['content-type', 'authorization']);
23+
const additionalHeaders = _.omit(headers, [
24+
'content-type',
25+
'authorization',
26+
'content-length'
27+
]);
2428
const response = await firstValueFrom(
2529
this.httpService.post(this.apiUrl, payload, {
2630
headers: {
@@ -33,11 +37,11 @@ export abstract class OAIEngineExtension extends EngineExtension {
3337
responseType: isStream ? 'stream' : 'json',
3438
}),
3539
);
36-
40+
3741
if (!response) {
3842
throw new Error('No response');
3943
}
40-
if(!this.transformResponse) {
44+
if (!this.transformResponse) {
4145
return response.data;
4246
}
4347
if (isStream) {
@@ -55,7 +59,7 @@ export abstract class OAIEngineExtension extends EngineExtension {
5559
}
5660
}
5761
callback(null, transformedLines.join(''));
58-
}
62+
},
5963
});
6064
return response.data.pipe(lineStream);
6165
}

cortex-js/src/extensions/anthropic.engine.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ export default class AnthropicEngineExtension extends OAIEngineExtension {
3737
this.name,
3838
)) as unknown as { apiKey: string };
3939
this.apiKey = configs?.apiKey;
40-
if (!configs?.apiKey)
41-
await this.configsUsecases.saveConfig('apiKey', '', this.name);
4240
}
4341

4442
override async inference(dto: any, headers: Record<string, string>): Promise<stream.Readable | any> {

cortex-js/src/extensions/groq.engine.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,5 @@ export default class GroqEngineExtension extends OAIEngineExtension {
3636
)) as unknown as { apiKey: string };
3737

3838
this.apiKey = configs?.apiKey;
39-
if (!configs?.apiKey)
40-
await this.configsUsecases.saveConfig('apiKey', '', this.name);
4139
}
4240
}

cortex-js/src/extensions/mistral.engine.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,5 @@ export default class MistralEngineExtension extends OAIEngineExtension {
3535
this.name,
3636
)) as unknown as { apiKey: string };
3737
this.apiKey = configs?.apiKey;
38-
if (!configs?.apiKey)
39-
await this.configsUsecases.saveConfig('apiKey', '', this.name);
4038
}
4139
}

cortex-js/src/extensions/openai.engine.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,5 @@ export default class OpenAIEngineExtension extends OAIEngineExtension {
3535
this.name,
3636
)) as unknown as { apiKey: string };
3737
this.apiKey = configs?.apiKey;
38-
if (!configs?.apiKey)
39-
await this.configsUsecases.saveConfig('apiKey', '', this.name);
4038
}
4139
}

0 commit comments

Comments
 (0)