95 lines
2.9 KiB
JavaScript
95 lines
2.9 KiB
JavaScript
import { logOpenRouterCall } from './openRouterLogger.js';
|
|
|
|
function parseResponse(response) {
|
|
return JSON.parse(response.choices[0].message.content);
|
|
}
|
|
|
|
export async function summarizeSources({ openrouter, text, question }) {
|
|
const prompt = `
|
|
You are a search result analyst.
|
|
Based on the following search results for the query "${question}",
|
|
provide a list of relevant sources with their full weblink with a concise summary for each source.
|
|
`;
|
|
|
|
const params = {
|
|
model: 'openai/gpt-oss-120b:nitro',
|
|
messages: [
|
|
{ role: 'system', content: prompt },
|
|
{ role: 'user', content: text },
|
|
],
|
|
reasoning: { effort: 'low' },
|
|
responseFormat: {
|
|
type: 'json_schema',
|
|
jsonSchema: {
|
|
name: 'search_summaries',
|
|
strict: true,
|
|
schema: {
|
|
type: 'object',
|
|
required: ['sources'],
|
|
additionalProperties: false,
|
|
properties: {
|
|
sources: {
|
|
type: 'array',
|
|
items: {
|
|
type: 'object',
|
|
required: ['url', 'summary'],
|
|
additionalProperties: false,
|
|
properties: {
|
|
url: { type: 'string', description: 'Full URL of the source' },
|
|
summary: { type: 'string', description: 'Concise summary of the content' },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
stream: false,
|
|
};
|
|
|
|
const response = await openrouter.chat.send({ chatRequest: params });
|
|
await logOpenRouterCall('summarizeSources', params, response);
|
|
return parseResponse(response);
|
|
}
|
|
|
|
export async function summarizeFinalAnswer({ openrouter, text, question }) {
|
|
const prompt = `
|
|
You are a search result analyst. Today is the date of ${new Date().toLocaleDateString()}.
|
|
Based on the following search results for the query "${question}",
|
|
Summarize the search results to answer the original query. Use Emoji and HTML. Tags allowed: <b>, <i>, <u>, <ul>, <li>, <span style="color:...">, <p> <div> <hr/>
|
|
Also provide the most relevant sources.
|
|
`;
|
|
|
|
const params = {
|
|
model: 'openai/gpt-5.4-mini',
|
|
messages: [
|
|
{ role: 'system', content: prompt },
|
|
{ role: 'user', content: text },
|
|
],
|
|
reasoning: { effort: 'none' },
|
|
responseFormat: {
|
|
type: 'json_schema',
|
|
jsonSchema: {
|
|
name: 'response',
|
|
strict: true,
|
|
schema: {
|
|
type: 'object',
|
|
required: ['fullAnswerHTMLSnippet', 'mostRelevantSources'],
|
|
properties: {
|
|
fullAnswerHTMLSnippet: { type: 'string' },
|
|
mostRelevantSources: {
|
|
type: 'array',
|
|
items: { type: 'string' },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
stream: false,
|
|
};
|
|
|
|
const response = await openrouter.chat.send({ chatRequest: params });
|
|
await logOpenRouterCall('summarizeFinalAnswer', params, response);
|
|
return parseResponse(response);
|
|
}
|