feat: implement AI suggestion

This commit is contained in:
2024-12-12 21:22:50 +07:00
parent 3652fda7d3
commit 68353d8985
7 changed files with 133 additions and 183 deletions

View File

@@ -59,7 +59,7 @@ export class OpenaiService {
return response.choices[0].message.content
}
async processText(text: string, sentenceIndex: number, prompt: PromptType) {
async processText(text: string, prompt: PromptType) {
const systemPrompt = 'You are an expert proofreader, the most advanced AI tool on the planet.'
const userPrompt = prompts[prompt].replace('{text}', text)
try {
@@ -74,11 +74,7 @@ export class OpenaiService {
const result = response.choices[0].message.content
// split to get data only in triple quotes
const resultData = result?.split('"""')[1]
Logger.log(resultData, 'result')
return {
sentenceIndex,
result: resultData,
}
return resultData
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
} catch (error: any) {
Logger.error(`Error in text processing: ${error.message}`, 'OpenaiService')