chore: rename blocks to artifacts (#793)
This commit is contained in:
parent
01f589b603
commit
81f909ac3a
41 changed files with 473 additions and 473 deletions
78
artifacts/sheet/server.ts
Normal file
78
artifacts/sheet/server.ts
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
import { myProvider } from '@/lib/ai/models';
|
||||
import { sheetPrompt, updateDocumentPrompt } from '@/lib/ai/prompts';
|
||||
import { createDocumentHandler } from '@/lib/artifacts/server';
|
||||
import { streamObject } from 'ai';
|
||||
import { z } from 'zod';
|
||||
|
||||
export const sheetDocumentHandler = createDocumentHandler<'sheet'>({
|
||||
kind: 'sheet',
|
||||
onCreateDocument: async ({ title, dataStream }) => {
|
||||
let draftContent = '';
|
||||
|
||||
const { fullStream } = streamObject({
|
||||
model: myProvider.languageModel('artifact-model'),
|
||||
system: sheetPrompt,
|
||||
prompt: title,
|
||||
schema: z.object({
|
||||
csv: z.string().describe('CSV data'),
|
||||
}),
|
||||
});
|
||||
|
||||
for await (const delta of fullStream) {
|
||||
const { type } = delta;
|
||||
|
||||
if (type === 'object') {
|
||||
const { object } = delta;
|
||||
const { csv } = object;
|
||||
|
||||
if (csv) {
|
||||
dataStream.writeData({
|
||||
type: 'sheet-delta',
|
||||
content: csv,
|
||||
});
|
||||
|
||||
draftContent = csv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dataStream.writeData({
|
||||
type: 'sheet-delta',
|
||||
content: draftContent,
|
||||
});
|
||||
|
||||
return draftContent;
|
||||
},
|
||||
onUpdateDocument: async ({ document, description, dataStream }) => {
|
||||
let draftContent = '';
|
||||
|
||||
const { fullStream } = streamObject({
|
||||
model: myProvider.languageModel('artifact-model'),
|
||||
system: updateDocumentPrompt(document.content, 'sheet'),
|
||||
prompt: description,
|
||||
schema: z.object({
|
||||
csv: z.string(),
|
||||
}),
|
||||
});
|
||||
|
||||
for await (const delta of fullStream) {
|
||||
const { type } = delta;
|
||||
|
||||
if (type === 'object') {
|
||||
const { object } = delta;
|
||||
const { csv } = object;
|
||||
|
||||
if (csv) {
|
||||
dataStream.writeData({
|
||||
type: 'sheet-delta',
|
||||
content: csv,
|
||||
});
|
||||
|
||||
draftContent = csv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return draftContent;
|
||||
},
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue