Skip to content

Commit

Permalink
feat(core): ai images
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Apr 10, 2024
1 parent c92bec0 commit 6767cf4
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assertExists } from '@blocksuite/global/utils';
import { AIProvider } from '@blocksuite/presets';

import { textToTextStream } from './request';
import { imageToTextStream, textToTextStream } from './request';

export function setupAIProvider() {
AIProvider.provideAction('chat', options => {
Expand Down Expand Up @@ -118,4 +118,41 @@ export function setupAIProvider() {
prompt,
});
});

AIProvider.provideAction('makeItReal', options => {

Check failure on line 122 in packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/provider.ts

View workflow job for this annotation

GitHub Actions / Lint

Argument of type '"makeItReal"' is not assignable to parameter of type 'keyof AIActions'.
assertExists(options.stream);
const prompt = `You are an expert web developer who specializes in building working website prototypes from low-fidelity wireframes.
Your job is to accept low-fidelity wireframes, then create a working prototype using HTML, CSS, and JavaScript, and finally send back the results.
The results should be a single HTML file.
Use tailwind to style the website.
Put any additional CSS styles in a style tag and any JavaScript in a script tag.
Use unpkg or skypack to import any required dependencies.
Use Google fonts to pull in any open source fonts you require.
If you have any images, load them from Unsplash or use solid colored rectangles.
The wireframes may include flow charts, diagrams, labels, arrows, sticky notes, and other features that should inform your work.
If there are screenshots or images, use them to inform the colors, fonts, and layout of your website.
Use your best judgement to determine whether what you see should be part of the user interface, or else is just an annotation.
Use what you know about applications and user experience to fill in any implicit business logic in the wireframes. Flesh it out, make it real!
The user may also provide you with the html of a previous design that they want you to iterate from.
In the wireframe, the previous design's html will appear as a white rectangle.
Use their notes, together with the previous design, to inform your next result.
Sometimes it's hard for you to read the writing in the wireframes.
For this reason, all text from the wireframes will be provided to you as a list of strings, separated by newlines.
Use the provided list of text from the wireframes as a reference if any text is hard to read.
You love your designers and want them to be happy. Incorporating their feedback and notes and producing working websites makes them happy.
When sent new wireframes, respond ONLY with the contents of the html file.`;
return imageToTextStream({
docId: options.docId,
workspaceId: options.workspaceId,
params: options.params,

Check failure on line 153 in packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/provider.ts

View workflow job for this annotation

GitHub Actions / Lint

Property 'params' does not exist on type 'AITextActionOptions | TranslateOptions | ChangeToneOptions'.
attachments: options.atachments,

Check failure on line 154 in packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/provider.ts

View workflow job for this annotation

GitHub Actions / Lint

Property 'atachments' does not exist on type 'AITextActionOptions | TranslateOptions | ChangeToneOptions'.
prompt,
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,57 @@ export function textToTextStream({
},
};
}

// Image to text(html)
export function imageToTextStream({
docId,
workspaceId,
...options
}: {
docId: string;
workspaceId: string;
prompt: string;
params?: string;
attachments?: string[];
}) {
const client = new CopilotClient(getBaseUrl());
return {
[Symbol.asyncIterator]: async function* () {
const session = await client.createSession({
workspaceId,
docId,
promptName: 'Summary', // placeholder
});
const message = await client.createMessage(options);

Check failure on line 49 in packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/request.ts

View workflow job for this annotation

GitHub Actions / Lint

Property 'createMessage' does not exist on type 'CopilotClient'.
const eventSource = client.textStream(message, session);

Check failure on line 50 in packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/request.ts

View workflow job for this annotation

GitHub Actions / Lint

Property 'textStream' does not exist on type 'CopilotClient'.
yield* toTextStream(eventSource, { timeout: TIMEOUT });
},
};
}

// Image to images
export function imageToImagesStream({
docId,
workspaceId,
...options
}: {
docId: string;
workspaceId: string;
prompt: string;
params?: string;
attachments?: string[];
}) {
const client = new CopilotClient(getBaseUrl());
return {
[Symbol.asyncIterator]: async function* () {
const session = await client.createSession({
workspaceId,
docId,
promptName: 'Summary', // placeholder
});
const message = await client.createMessage(options);

Check failure on line 76 in packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/request.ts

View workflow job for this annotation

GitHub Actions / Lint

Property 'createMessage' does not exist on type 'CopilotClient'.
const eventSource = client.imagesStream(message, session);

Check failure on line 77 in packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/request.ts

View workflow job for this annotation

GitHub Actions / Lint

Property 'imagesStream' does not exist on type 'CopilotClient'.
yield* toTextStream(eventSource, { timeout: TIMEOUT });
},
};
}

0 comments on commit 6767cf4

Please sign in to comment.