This commit is contained in:
sebseb7
2026-04-04 16:33:33 +02:00
parent 27180aa2c3
commit 2e9a5e9e7f
9 changed files with 218 additions and 82 deletions

View File

@@ -1,7 +1,7 @@
import { logOpenRouterCall } from './openRouterLogger.js';
function parseResponse(response) {
return JSON.parse(response.choices[0].message.content);
return { cost: response.usage.cost, data: JSON.parse(response.choices[0].message.content) };
}
export async function summarizeSources({ openrouter, text, question }) {
@@ -18,9 +18,9 @@ export async function summarizeSources({ openrouter, text, question }) {
{ role: 'user', content: text },
],
reasoning: { effort: 'low' },
responseFormat: {
response_format: {
type: 'json_schema',
jsonSchema: {
json_schema: {
name: 'search_summaries',
strict: true,
schema: {
@@ -47,7 +47,17 @@ export async function summarizeSources({ openrouter, text, question }) {
stream: false,
};
const response = await openrouter.chat.send({ chatRequest: params });
// Using direct fetch API instead of OpenRouter SDK
const apiKey = process.env.OPENROUTER_API_KEY;
const fetchResponse = await fetch('https://openrouter.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(params),
});
const response = await fetchResponse.json();
await logOpenRouterCall('summarizeSources', params, response);
return parseResponse(response);
}
@@ -67,9 +77,9 @@ export async function summarizeFinalAnswer({ openrouter, text, question }) {
{ role: 'user', content: text },
],
reasoning: { effort: 'none' },
responseFormat: {
response_format: {
type: 'json_schema',
jsonSchema: {
json_schema: {
name: 'response',
strict: true,
schema: {
@@ -88,7 +98,19 @@ export async function summarizeFinalAnswer({ openrouter, text, question }) {
stream: false,
};
const response = await openrouter.chat.send({ chatRequest: params });
// Using direct fetch API instead of OpenRouter SDK
const apiKey = process.env.OPENROUTER_API_KEY;
const fetchResponse = await fetch('https://openrouter.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(params),
});
const response = await fetchResponse.json();
await logOpenRouterCall('summarizeFinalAnswer', params, response);
return parseResponse(response);
}