Skip to content

Commit

Permalink
Merge pull request #12 from tope-olajide/feature/paraphraser
Browse files Browse the repository at this point in the history
Add Paraphrasing Feature with 7 Modes and Serverless Function
  • Loading branch information
tope-olajide authored Dec 4, 2024
2 parents 8035449 + 7756f55 commit 3a84bcf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import {
bulletPointSummaryInstruction,
generateGrammarCheckerInstruction,
generateParaphraseInstruction,
generateSummaryInstruction,


Expand Down Expand Up @@ -48,3 +49,13 @@ export function summarizeText(text: string, length:string, summaryMode:string ):
return output.choices[0].message.content.trim()
}

export function paraphraseText(text: string, mode:string ): string {
const model = models.getModel<OpenAIChatModel>(summarizeTextModel)
const paraphraseTextInstruction = generateParaphraseInstruction(mode)
const input = model.createInput([
new SystemMessage(paraphraseTextInstruction),
new UserMessage(text),
])
const output = model.invoke(input)
return output.choices[0].message.content.trim()
}
19 changes: 19 additions & 0 deletions assembly/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,22 @@ Expected output format:
]
**Important**: Do not include markdown-style code block indicators (\`json and \`\`) in your response. Return only the array.
`;

export function generateParaphraseInstruction(tone: string): string {

const prompt: string = `
Rewrite the given text in a ${tone} tone while:
- Preserving the core meaning and context
- Maintaining natural flow and readability
- Keeping key terminology and technical concepts
- Adapting word choice and expressions to match the ${tone} style
- Ensuring proper grammar and punctuation
- Retaining the original language and general sentence structure
**Important**:
- Output only the paraphrased text
- Do not include any explanatory notes or meta-commentary
- Do not add introductory phrases or conclusions
- Do not include phrases like "Here's the rewritten text' or any other explanation—just the paraphrased text itself."`;
return prompt;
}

0 comments on commit 3a84bcf

Please sign in to comment.