Skip to content

Commit

Permalink
tweak prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyphilemon committed Jan 7, 2025
1 parent 8350be7 commit f8f5080
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/(chat)/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export async function POST(request: Request) {
if (document.kind === 'text') {
const { fullStream } = streamText({
model: customModel(model.apiIdentifier),
system: updateDocumentPrompt(currentContent),
system: updateDocumentPrompt(currentContent, 'text'),
prompt: description,
experimental_providerMetadata: {
openai: {
Expand Down Expand Up @@ -284,7 +284,7 @@ export async function POST(request: Request) {
} else if (document.kind === 'code') {
const { fullStream } = streamObject({
model: customModel(model.apiIdentifier),
system: updateDocumentPrompt(currentContent),
system: updateDocumentPrompt(currentContent, 'code'),
prompt: description,
schema: z.object({
code: z.string(),
Expand Down
20 changes: 17 additions & 3 deletions lib/ai/prompts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { BlockKind } from '@/components/block';

export const blocksPrompt = `
Blocks is a special user interface mode that helps users with writing, editing, and other content creation tasks. When block is open, it is on the right side of the screen, while the conversation is on the left side. When creating or updating documents, changes are reflected in real-time on the blocks and visible to the user.
Expand Down Expand Up @@ -62,8 +64,20 @@ print(f"Factorial of 5 is: {factorial(5)}")
\`\`\`
`;

export const updateDocumentPrompt = (currentContent: string | null) => `\
Update the following contents of the document based on the given prompt.
export const updateDocumentPrompt = (
currentContent: string | null,
type: BlockKind,
) =>
type === 'text'
? `\
Improve the following contents of the document based on the given prompt.
${currentContent}
`;
`
: type === 'code'
? `\
Improve the following code snippet based on the given prompt.
${currentContent}
`
: '';

0 comments on commit f8f5080

Please sign in to comment.