Skip to content

Commit

Permalink
refactor: improve generateSummaryFromContent function and add command…
Browse files Browse the repository at this point in the history
… to generate summary from selected text
  • Loading branch information
anpigon committed Jul 6, 2024
1 parent ad8c7ce commit 0210160
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions src/libs/ai/generate/generateSummaryFromContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ export default async function generateSummaryFromContent(settings: MAXSettings,
const {provider, model} = getSelectedAIProviderAndModel(settings);
const llm = createChatModelInstance(provider, model, settings);
// TODO: model의 performance와 max context length에 따라서 prompt를 수정해야 함
const prompt = [
new SystemMessage(
`You will generate increasingly concise, entity-dense summaries of the above article.
try {
const prompt = [
new SystemMessage(
`You will generate increasingly concise, entity-dense summaries of the above article.
Repeat the following 2 steps 5 times:
Expand All @@ -42,12 +43,34 @@ Guidelines:
Ensure that each summary has exactly the same number of words.
Respond in JSON format. The JSON should be a list (length 5) of dictionaries with keys "Missing_Entities" and "Denser_Summary".
!IMPORTANT: Answer language is ${globalThis.moment().locale()}`
),
new HumanMessage(`#Article:\n\n${fileContent}`),
];
Logger.debug(prompt);
const chain = llm.pipe<Summary[]>(new JsonOutputParser());
const response = await chain.invoke(prompt);
Logger.debug(response);
return response.last()?.Denser_Summary;
),
new HumanMessage(`#Article:\n\n${fileContent}`),
];
Logger.debug(prompt);
const chain = llm.pipe<Summary[]>(new JsonOutputParser());
const response = await chain.invoke(prompt);
Logger.debug(response);
return response.last()?.Denser_Summary;
} catch (e) {
Logger.error(e);
const prompt = [
new SystemMessage(
`Please summarize the following notes in a concise and clear manner:
1. Include only the main concepts and ideas.
2. Exclude unnecessary details, focusing on the core content.
3. Maintain the original structure and logical flow.
4. Preserve technical terms or important keywords.
5. Ensure the summary is approximately 20% of the original length.
6. Use bullet points to list the key points.
7. Answer language is ${globalThis.moment().locale()}`
),
new HumanMessage(`#Notes content:\n\n${fileContent}`),
];
Logger.debug(prompt);
const chain = llm.pipe<string>(new StringOutputParser());
const response = await chain.invoke(prompt);
Logger.debug(response);
return response;
}
}

0 comments on commit 0210160

Please sign in to comment.