Genesis
This commit is contained in:
90
src/services/openRouterService.js
Normal file
90
src/services/openRouterService.js
Normal file
@@ -0,0 +1,90 @@
|
||||
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 });
|
||||
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 });
|
||||
return parseResponse(response);
|
||||
}
|
||||
Reference in New Issue
Block a user