-
Notifications
You must be signed in to change notification settings - Fork 509
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
555 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
apps/dashboard/src/actions/ai/editor/generate-editor-content.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"use server"; | ||
|
||
import { openai } from "@ai-sdk/openai"; | ||
import { streamText } from "ai"; | ||
import { createStreamableValue } from "ai/rsc"; | ||
|
||
type Params = { | ||
input: string; | ||
context?: string; | ||
}; | ||
|
||
export async function generateEditorContent({ input, context }: Params) { | ||
console.log(context); | ||
const stream = createStreamableValue(""); | ||
|
||
(async () => { | ||
const { textStream } = await streamText({ | ||
model: openai("gpt-4o-mini"), | ||
prompt: input, | ||
temperature: 0.8, | ||
system: ` | ||
You are an expert AI assistant specializing in invoice-related content generation and improvement. Your task is to enhance or modify invoice text based on specific instructions. Follow these guidelines: | ||
1. Language: Always respond in the same language as the input prompt. | ||
2. Conciseness: Keep responses brief and precise, with a maximum of 200 characters. | ||
3. Context-awareness: Utilize any provided due date to inform payment terms. | ||
You will perform one of these primary functions: | ||
- Fix grammar: Rectify any grammatical errors while preserving the original meaning. | ||
- Improve text: Refine the text to improve clarity and professionalism. | ||
- Condense text: Remove any unnecessary text and only keep the invoice-related content and make it more concise. | ||
If a due date is provided, incorporate it into the payment terms. | ||
Adjust payment terms based on the due date, ensuring they are realistic and aligned with standard business practices. | ||
Format your response as plain text, using '\n' for line breaks when necessary. | ||
Do not include any titles or headings in your response. | ||
Provide only invoice-relevant content without any extraneous information. | ||
Begin your response directly with the relevant invoice text or information. | ||
For custom prompts, maintain focus on invoice-related content. Ensure all generated text is appropriate for formal business communications and adheres to standard invoice practices. | ||
Current date is: ${new Date().toISOString().split("T")[0]} \n | ||
${context} | ||
`, | ||
}); | ||
|
||
for await (const delta of textStream) { | ||
stream.update(delta); | ||
} | ||
|
||
stream.done(); | ||
})(); | ||
|
||
return { output: stream.value }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use server"; | ||
|
||
import { z } from "zod"; | ||
import { authActionClient } from "./safe-action"; | ||
|
||
const ENDPOINT = "https://api.vatcheckapi.com/v2/check"; | ||
|
||
export const validateVatNumberAction = authActionClient | ||
.schema( | ||
z.object({ | ||
vat_number: z.string().min(7), | ||
country_code: z.string(), | ||
}), | ||
) | ||
.metadata({ | ||
name: "validate-vat-number", | ||
}) | ||
.action(async ({ parsedInput: { vat_number, country_code } }) => { | ||
const response = await fetch( | ||
`${ENDPOINT}?vat_number=${vat_number}&country_code=${country_code}&apikey=${process.env.VATCHECKAPI_API_KEY}`, | ||
{ | ||
method: "GET", | ||
}, | ||
); | ||
|
||
const data = await response.json(); | ||
|
||
console.log(data); | ||
|
||
return data; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,11 @@ | ||
import { | ||
Color, | ||
HorizontalRule, | ||
Placeholder, | ||
StarterKit, | ||
TaskItem, | ||
TaskList, | ||
TextStyle, | ||
TiptapLink, | ||
UpdatedImage, | ||
} from "novel/extensions"; | ||
import { Placeholder, StarterKit, TextStyle } from "novel/extensions"; | ||
|
||
import { cx } from "class-variance-authority"; | ||
const starterKit = StarterKit.configure(); | ||
|
||
// TODO I am using cx here to get tailwind autocomplete working, idk if someone else can write a regex to just capture the class key in objects | ||
|
||
// You can overwrite the placeholder with your own configuration | ||
const placeholder = Placeholder; | ||
// const tiptapLink = TiptapLink.configure({ | ||
// HTMLAttributes: { | ||
// class: cx( | ||
// "text-muted-foreground underline underline-offset-[3px] hover:text-primary transition-colors cursor-pointer", | ||
// ), | ||
// }, | ||
// }); | ||
|
||
const starterKit = StarterKit.configure({ | ||
bulletList: { | ||
HTMLAttributes: { | ||
class: cx("list-disc list-outside leading-3 -mt-2"), | ||
}, | ||
}, | ||
orderedList: { | ||
HTMLAttributes: { | ||
class: cx("list-decimal list-outside leading-3 -mt-2"), | ||
}, | ||
}, | ||
listItem: { | ||
HTMLAttributes: { | ||
class: cx("leading-normal -mb-2"), | ||
}, | ||
}, | ||
blockquote: { | ||
HTMLAttributes: { | ||
class: cx("border-l-4 border-primary"), | ||
}, | ||
}, | ||
horizontalRule: false, | ||
dropcursor: { | ||
color: "#DBEAFE", | ||
width: 4, | ||
}, | ||
gapcursor: false, | ||
}); | ||
|
||
export const defaultExtensions = [starterKit, placeholder, TextStyle, Color]; | ||
export function setupExtensions({ placeholder }: { placeholder?: string }) { | ||
return [ | ||
starterKit, | ||
placeholder ? Placeholder.configure({ placeholder }) : null, | ||
TextStyle, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.