inject necessary header for sse style streaming response

This commit is contained in:
Vinay Maniam 2025-02-24 18:05:30 +00:00
parent ebc29f54c5
commit be423fa96d

View file

@ -1,4 +1,5 @@
import { LLMOptions } from "../../index.js";
import { ChatMessage, CompletionOptions, LLMOptions } from "../../index.js";
import { ChatCompletionCreateParams } from "openai/resources/index";
import OpenAI from "./OpenAI.js";
@ -11,11 +12,28 @@ class NCompass extends OpenAI {
private static modelConversion: { [key: string]: string } = {
"qwen2.5-coder-32b": "Qwen/Qwen2.5-Coder-32B-Instruct",
"qwen2.5-72b": "Qwen/Qwen2.5-72B-Instruct",
"llama3.3-70b": "meta-llama/Meta-Llama-3.3-70B-Instruct",
"llama3.3-70b": "meta-llama/Llama-3.3-70B-Instruct",
"llama3.1-8b": "meta-llama/Llama-3.1-8B-Instruct",
};
protected _convertModelName(model: string): string {
return NCompass.modelConversion[model] ?? model;
}
protected _convertArgs(
options: CompletionOptions,
messages: ChatMessage[],
): ChatCompletionCreateParams {
const finalOptions = super._convertArgs(options, messages);
finalOptions.model = this._convertModelName(options.model);
return finalOptions;
}
protected _getHeaders() {
const headers = super._getHeaders() as { "Content-Type": string; Authorization: string; "api-key": string; Accept?: string };
headers["Accept"] = "text/event-stream";
return headers;
}
}
export default NCompass;