Skip to content

Include description in artifact generation (better quality) #886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions artifacts/code/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { createDocumentHandler } from '@/lib/artifacts/server';

export const codeDocumentHandler = createDocumentHandler<'code'>({
kind: 'code',
onCreateDocument: async ({ title, dataStream }) => {
onCreateDocument: async ({ title, description, dataStream }) => {
let draftContent = '';

const { fullStream } = streamObject({
model: myProvider.languageModel('artifact-model'),
system: codePrompt,
prompt: title,
prompt: `${title}\n\n${description}`,
schema: z.object({
code: z.string(),
}),
Expand Down
4 changes: 2 additions & 2 deletions artifacts/image/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { experimental_generateImage } from 'ai';

export const imageDocumentHandler = createDocumentHandler<'image'>({
kind: 'image',
onCreateDocument: async ({ title, dataStream }) => {
onCreateDocument: async ({ title, description, dataStream }) => {
let draftContent = '';

const { image } = await experimental_generateImage({
model: myProvider.imageModel('small-model'),
prompt: title,
prompt: `${title}\n\n${description}`,
n: 1,
});

Expand Down
4 changes: 2 additions & 2 deletions artifacts/sheet/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { z } from 'zod';

export const sheetDocumentHandler = createDocumentHandler<'sheet'>({
kind: 'sheet',
onCreateDocument: async ({ title, dataStream }) => {
onCreateDocument: async ({ title, description, dataStream }) => {
let draftContent = '';

const { fullStream } = streamObject({
model: myProvider.languageModel('artifact-model'),
system: sheetPrompt,
prompt: title,
prompt: `${title}\n\n${description}`,
schema: z.object({
csv: z.string().describe('CSV data'),
}),
Expand Down
4 changes: 2 additions & 2 deletions artifacts/text/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { updateDocumentPrompt } from '@/lib/ai/prompts';

export const textDocumentHandler = createDocumentHandler<'text'>({
kind: 'text',
onCreateDocument: async ({ title, dataStream }) => {
onCreateDocument: async ({ title, description, dataStream }) => {
let draftContent = '';

const { fullStream } = streamText({
model: myProvider.languageModel('artifact-model'),
system:
'Write about the given topic. Markdown is supported. Use headings wherever appropriate.',
experimental_transform: smoothStream({ chunking: 'word' }),
prompt: title,
prompt: `${title}\n\n${description}`,
});

for await (const delta of fullStream) {
Expand Down
4 changes: 3 additions & 1 deletion lib/ai/tools/create-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ export const createDocument = ({ session, dataStream }: CreateDocumentProps) =>
'Create a document for a writing or content creation activities. This tool will call other functions that will generate the contents of the document based on the title and kind.',
parameters: z.object({
title: z.string(),
description: z.string().describe('A detailed description of what the document should contain'),
kind: z.enum(artifactKinds),
}),
execute: async ({ title, kind }) => {
execute: async ({ title, description, kind }) => {
const id = generateUUID();

dataStream.writeData({
Expand Down Expand Up @@ -55,6 +56,7 @@ export const createDocument = ({ session, dataStream }: CreateDocumentProps) =>
await documentHandler.onCreateDocument({
id,
title,
description,
dataStream,
session,
});
Expand Down
2 changes: 2 additions & 0 deletions lib/artifacts/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface SaveDocumentProps {
export interface CreateDocumentCallbackProps {
id: string;
title: string;
description: string;
dataStream: DataStreamWriter;
session: Session;
}
Expand Down Expand Up @@ -47,6 +48,7 @@ export function createDocumentHandler<T extends ArtifactKind>(config: {
const draftContent = await config.onCreateDocument({
id: args.id,
title: args.title,
description: args.description,
dataStream: args.dataStream,
session: args.session,
});
Expand Down