Skip to content

Commit

Permalink
Merge pull request #9 from tope-olajide/feature/summarize-text
Browse files Browse the repository at this point in the history
Fix summarizeText instruction prompt and serverless function
  • Loading branch information
tope-olajide authored Dec 2, 2024
2 parents 8f3ca1e + 2d7154c commit a3cf32b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 51 deletions.
20 changes: 13 additions & 7 deletions assembly/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import { models } from "@hypermode/modus-sdk-as"
import { models } from "@hypermode/modus-sdk-as";
import {
OpenAIChatModel,
ResponseFormat,
SystemMessage,
UserMessage,
} from "@hypermode/modus-sdk-as/models/openai/chat"
import { bulletPointSummaryInstruction, generateSummaryInstruction, grammarCheckerInstruction, SummaryCategory, SummaryMode } from "./instructions";
} from "@hypermode/modus-sdk-as/models/openai/chat";
import {
bulletPointSummaryInstruction,
generateSummaryInstruction,

grammarCheckerInstruction,

} from "./instructions";

export function sayHello(name: string | null = null): string {
return "hello " + (name != null ? name : "world");
}

return `hello ${name || "world"}`;}
const grammarCheckerModel: string = "grammar-error-checker";
const summarizeTextModel: string = "text-summarizer";


const grammarCheckerModel: string = "grammar-error-checker"
const summarizeTextModel:string = "text-summarizer"
export function checkGrammarErrors(text: string): string {
const model = models.getModel<OpenAIChatModel>(grammarCheckerModel)
const input = model.createInput([
Expand All @@ -27,7 +32,8 @@ export function checkGrammarErrors(text: string): string {
return output.choices[0].message.content.trim()
}

export function summarizeText(text: string, length:SummaryCategory, summaryMode:SummaryMode ): string {

export function summarizeText(text: string, length:string, summaryMode:string ): string {
const model = models.getModel<OpenAIChatModel>(summarizeTextModel)
const summarizeTextInstruction = generateSummaryInstruction(length)
const bulletPointSummaryPrompt = bulletPointSummaryInstruction;
Expand Down
60 changes: 16 additions & 44 deletions assembly/instructions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const grammarCheckerInstruction = `
export const grammarCheckerInstruction = `
You are a grammar expert tasked with analyzing text for grammatical errors. Analyze the provided text for any grammatical errors, including spelling, punctuation, syntax, verb tense, subject-verb agreement, and word choice issues.
For each grammatical error found, provide the following details:
Expand Down Expand Up @@ -27,37 +27,25 @@ Return the results in the following JSON format:



export type SummaryCategory = "Brief" | "Concise" | "Detailed" | "Comprehensive";
export type SummaryMode = "Bullet" | "Paragraph"
function generateSummaryInstruction(category: SummaryCategory): string {
// Define category descriptions
const categoryDescriptions: { [key in SummaryCategory]: string } = {
Brief: "A very short summary focusing only on the core idea.",
Concise: "A slightly longer summary highlighting key points clearly and succinctly.",
Detailed: "A more descriptive summary with additional context and nuances.",
Comprehensive: "An in-depth and thorough summary covering all critical details."
};

// Prompt construction
const prompt = `
There are four summary length categories: Brief, Concise, Detailed, and Comprehensive.
- Brief: ${categoryDescriptions.Brief}
- Concise: ${categoryDescriptions.Concise}
- Detailed: ${categoryDescriptions.Detailed}
- Comprehensive: ${categoryDescriptions.Comprehensive}
Based on the specified length category (${category}), generate an appropriate summary of the given text

`;

return prompt;
}

const bulletPointSummaryInstruction = `
export function generateSummaryInstruction(category: string): string {

const prompt: string = `
There are four summary length categories: Brief, Concise, Detailed, and Comprehensive.
- Brief: A very short summary focusing only on the core idea.
- Concise: A slightly longer summary highlighting key points clearly and succinctly.
- Detailed: A more descriptive summary with additional context and nuances.
- Comprehensive: An in-depth and thorough summary covering all critical details.
Based on the specified length category (${category}), generate an appropriate summary of the given text.
Return only the summary text without any prefixes, introductory phrases, or meta-commentary. `;

"Summarize the following text into key bullet points, each representing a distinct idea or concept. Return the summary in the form of a JSON array, where each bullet point is a separate item in the array.
return prompt;
}

export const bulletPointSummaryInstruction: string = `
Summarize the following text into key bullet points, each representing a distinct idea or concept. Return the summary in the form of a JSON array, where each bullet point is a separate item in the array.
Expected output format:
Expand All @@ -67,20 +55,4 @@ Expected output format:
"Bullet point 3",
"Bullet point n"
]
**Important**: Do not include markdown-style code block indicators (\`json and \`\`) in your response. Return only the array.
`












export { grammarCheckerInstruction, generateSummaryInstruction, bulletPointSummaryInstruction}
`;

0 comments on commit a3cf32b

Please sign in to comment.