fix: Add dynamic values from engine settings and model params to inference request

This commit is contained in:
hiro 2023-12-05 00:32:09 +07:00
parent 4f2a3b7b27
commit 16f2ffe9b4

View File

@ -1,26 +1,32 @@
import { Observable } from "rxjs"; import { Observable } from "rxjs";
import { EngineSettings, OpenAIModel } from "../@types/global";
/** /**
* Sends a request to the inference server to generate a response based on the recent messages. * Sends a request to the inference server to generate a response based on the recent messages.
* @param recentMessages - An array of recent messages to use as context for the inference. * @param recentMessages - An array of recent messages to use as context for the inference.
* @param engine - The engine settings to use for the inference.
* @param model - The model to use for the inference.
* @returns An Observable that emits the generated response as a string. * @returns An Observable that emits the generated response as a string.
*/ */
export function requestInference( export function requestInference(
recentMessages: any[], recentMessages: any[],
engine: EngineSettings,
model: OpenAIModel,
controller?: AbortController controller?: AbortController
): Observable<string> { ): Observable<string> {
return new Observable((subscriber) => { return new Observable((subscriber) => {
const requestBody = JSON.stringify({ const requestBody = JSON.stringify({
messages: recentMessages, messages: recentMessages,
stream: true, stream: true,
model: "gpt-3.5-turbo", model: model.id,
max_tokens: 2048,
}); });
fetch(INFERENCE_URL, { fetch(engine.base_url, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Accept: "text/event-stream", Accept: "text/event-stream",
"Access-Control-Allow-Origin": "*", "Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${engine.api_key}`,
}, },
body: requestBody, body: requestBody,
signal: controller?.signal, signal: controller?.signal,