/* eslint-disable lingui/text-restrictions */ import { t } from "@lingui/macro"; import { DEFAULT_MAX_TOKENS, DEFAULT_MODEL } from "@/client/constants/llm"; import { useOpenAiStore } from "@/client/stores/openai"; import { openai } from "./client"; const PROMPT = `You are an AI writing assistant specialized in writing copy for resumes. Do not return anything else except the text you improved. It should not begin with a newline. It should not have any prefix or suffix text. Improve the writing of the following paragraph and returns in the language of the text: Text: """{input}""" Revised Text: """`; export const improveWriting = async (text: string) => { const prompt = PROMPT.replace("{input}", text); const { model, maxTokens } = useOpenAiStore.getState(); const result = await openai().chat.completions.create({ messages: [{ role: "user", content: prompt }], model: model ?? DEFAULT_MODEL, max_tokens: maxTokens ?? DEFAULT_MAX_TOKENS, temperature: 0, stop: ['"""'], n: 1, }); if (result.choices.length === 0) { throw new Error(t`OpenAI did not return any choices for your text.`); } return result.choices[0].message.content ?? text; };