diff --git a/README.md b/README.md index bc69aca..9a3aade 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ console.log(result); // I am a large language model, trained by Google. ``` -Chrome built-in language models can also be used in the generateObject function: +Chrome built-in language models can also be used in the `generateObject/streamObject` function: ```javascript import { generateObject } from 'ai'; @@ -143,7 +143,35 @@ console.log(object); // { recipe: {...} } ``` -> Due to model reasons, `toolCall` and `streamObject` are not supported. We are making an effort to implement these functions by prompt engineering. +```javascript +import { streamObject } from 'ai'; +import { chromeai } from 'chrome-ai'; +import { z } from 'zod'; + +const { partialObjectStream } = await streamObject({ + model: chromeai(), + schema: z.object({ + recipe: z.object({ + name: z.string(), + ingredients: z.array( + z.object({ + name: z.string(), + amount: z.string(), + }) + ), + steps: z.array(z.string()), + }), + }), + prompt: 'Generate a lasagna recipe.', +}); + +for await (const partialObject of result.partialObjectStream) { + console.log(JSON.stringify(partialObject, null, 2)); + // { recipe: {...} } +} +``` + +> Due to model reasons, `toolCall/functionCall` are not supported. We are making an effort to implement these functions by prompt engineering. ## Enable AI in Chrome diff --git a/app/components/chat-card.tsx b/app/components/chat-card.tsx deleted file mode 100644 index e437d35..0000000 --- a/app/components/chat-card.tsx +++ /dev/null @@ -1,49 +0,0 @@ -'use client'; - -import React from 'react'; -import { MemoizedReactMarkdown } from './markdown'; -import { - Card, - CardContent, - CardDescription, - CardFooter, - CardHeader, - CardTitle, -} from './ui/card'; -import { Skeleton } from './ui/skeleton'; - -export interface ChatCardProps { - message?: string; - loading?: boolean; -} - -export const ChatCard: React.FC = ({ message, loading }) => { - if (loading && !message) { - return ( -
- - -
- ); - } - if (!message) return null; - return ( - - - ChatBot: - - - {children}

; - }, - }} - > - {message} -
-
-
- ); -}; diff --git a/app/components/footer.tsx b/app/components/footer.tsx index da4a97f..3953371 100644 --- a/app/components/footer.tsx +++ b/app/components/footer.tsx @@ -2,9 +2,9 @@ import React from 'react'; export const Footer: React.FC = () => { return ( -
+

- Open source AI demo built with{' '} + Built with{' '} = () => { .

-
+ ); }; diff --git a/app/components/layout.tsx b/app/components/layout.tsx new file mode 100644 index 0000000..c167393 --- /dev/null +++ b/app/components/layout.tsx @@ -0,0 +1,121 @@ +'use client'; + +import React from 'react'; +import { + SquareTerminal, + Chrome, + Github, + Twitter, + SquareKanban, +} from 'lucide-react'; +import { Button } from '../components/ui/button'; +import { + Tooltip, + TooltipContent, + TooltipTrigger, + TooltipProvider, +} from '../components/ui/tooltip'; +import { ThemeSwitcher } from '../components/theme-switcher'; +import Link from 'next/link'; +import { usePathname } from 'next/navigation'; +import { cn } from '../utils'; + +export interface LayoutProps extends React.HTMLAttributes {} + +export const Layout: React.FC> = ({ + children, +}) => { + const pathname = usePathname(); + + return ( +
+ +
+
+

Chrome AI

+ + {/* */} + + + + +
+ {children} +
+
+ ); +}; diff --git a/app/components/markdown.tsx b/app/components/markdown.tsx deleted file mode 100644 index abdca72..0000000 --- a/app/components/markdown.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import React from 'react'; -import ReactMarkdown, { Options } from 'react-markdown'; - -export const MemoizedReactMarkdown: React.FC = React.memo( - ReactMarkdown, - (prevProps, nextProps) => - prevProps.children === nextProps.children && - prevProps.className === nextProps.className -); diff --git a/app/components/profile.tsx b/app/components/profile.tsx deleted file mode 100644 index e69de29..0000000 diff --git a/app/components/prompt-card.tsx b/app/components/prompt-card.tsx deleted file mode 100644 index 062b378..0000000 --- a/app/components/prompt-card.tsx +++ /dev/null @@ -1,59 +0,0 @@ -'use client'; - -import React from 'react'; -import { Textarea } from './ui/textarea'; -import { Button } from './ui/button'; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from './ui/select'; -import { ThemeSwitcher } from './theme-switcher'; - -export interface PromptCardProps { - onPrompt?: (message: string, template?: string) => void | Promise; -} - -export const PromptCard = React.forwardRef( - ({ onPrompt }, ref) => { - const [prompt, setPrompt] = React.useState(''); - - return ( -
-