АДРЕСНЫЙ РЕЖИМ -Step-5 - feat(assistant): стабилизация свободного LLM-роутинга, прическа маршрутов chat/address, прототип прогноза НДС
This commit is contained in:
@@ -203,6 +203,103 @@ function buildBaseUrlCandidates(config: OpenAIRequestConfig): string[] {
|
||||
}
|
||||
|
||||
export class OpenAIResponsesClient {
|
||||
public async chat(
|
||||
config: OpenAIRequestConfig,
|
||||
prompt: {
|
||||
systemPrompt?: string;
|
||||
developerPrompt?: string;
|
||||
userMessage: string;
|
||||
maxOutputTokens?: number;
|
||||
temperature?: number;
|
||||
}
|
||||
): Promise<OpenAIResponseEnvelope> {
|
||||
const responsesPayload = {
|
||||
model: config.model,
|
||||
temperature: prompt.temperature ?? config.temperature ?? 0.2,
|
||||
max_output_tokens: prompt.maxOutputTokens ?? config.maxOutputTokens ?? 400,
|
||||
input: [
|
||||
...(String(prompt.systemPrompt ?? "").trim().length > 0
|
||||
? [
|
||||
{
|
||||
role: "system",
|
||||
content: [{ type: "input_text", text: String(prompt.systemPrompt ?? "").trim() }]
|
||||
}
|
||||
]
|
||||
: []),
|
||||
...(String(prompt.developerPrompt ?? "").trim().length > 0
|
||||
? [
|
||||
{
|
||||
role: "developer",
|
||||
content: [{ type: "input_text", text: String(prompt.developerPrompt ?? "").trim() }]
|
||||
}
|
||||
]
|
||||
: []),
|
||||
{
|
||||
role: "user",
|
||||
content: [{ type: "input_text", text: String(prompt.userMessage ?? "") }]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const provider = resolveProvider(config);
|
||||
if (provider === "openai") {
|
||||
const raw = await this.postResponses(config, responsesPayload);
|
||||
return {
|
||||
raw,
|
||||
outputText: extractOutputTextFromResponses(raw),
|
||||
usage: extractUsage(raw)
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const raw = await this.postResponses(config, responsesPayload);
|
||||
return {
|
||||
raw,
|
||||
outputText: extractOutputTextFromResponses(raw),
|
||||
usage: extractUsage(raw)
|
||||
};
|
||||
} catch (error) {
|
||||
if (!shouldFallbackToChatCompletions(error)) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
const chatPayload = {
|
||||
model: config.model,
|
||||
temperature: prompt.temperature ?? config.temperature ?? 0.2,
|
||||
max_tokens: prompt.maxOutputTokens ?? config.maxOutputTokens ?? 400,
|
||||
messages: [
|
||||
...(String(prompt.systemPrompt ?? "").trim().length > 0
|
||||
? [
|
||||
{
|
||||
role: "system",
|
||||
content: String(prompt.systemPrompt ?? "").trim()
|
||||
}
|
||||
]
|
||||
: []),
|
||||
...(String(prompt.developerPrompt ?? "").trim().length > 0
|
||||
? [
|
||||
{
|
||||
role: "developer",
|
||||
content: String(prompt.developerPrompt ?? "").trim()
|
||||
}
|
||||
]
|
||||
: []),
|
||||
{
|
||||
role: "user",
|
||||
content: String(prompt.userMessage ?? "")
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const raw = await this.postChatCompletions(config, chatPayload);
|
||||
return {
|
||||
raw,
|
||||
outputText: extractOutputTextFromChatCompletions(raw),
|
||||
usage: extractUsage(raw)
|
||||
};
|
||||
}
|
||||
|
||||
public async listModels(config: OpenAIRequestConfig): Promise<string[]> {
|
||||
const payload = await this.getModels(config);
|
||||
const data = Array.isArray(payload.data) ? payload.data : [];
|
||||
|
||||
Reference in New Issue
Block a user