diff --git a/.changeset/unlucky-eyes-lick.md b/.changeset/unlucky-eyes-lick.md new file mode 100644 index 0000000..cbd53f0 --- /dev/null +++ b/.changeset/unlucky-eyes-lick.md @@ -0,0 +1,5 @@ +--- +"inform-ai": patch +--- + +Delete vestigial example dir diff --git a/src/example/Table.tsx b/src/example/Table.tsx deleted file mode 100644 index 599ec7e..0000000 --- a/src/example/Table.tsx +++ /dev/null @@ -1,64 +0,0 @@ -"use client"; - -import { ReactNode } from "react"; -import { useInformAI } from "../useInformAI"; - -type TableProps = { - data: any[]; - colHeaders?: string[]; -}; - -const prompt = `This component is a table that displays data in a tabular format. -It takes two props: data and colHeaders. The data prop is an array of objects, where -each object represents a row in the table. The colHeaders prop is an optional -array of strings that represent the column headers of the table. -If the colHeaders prop is not provided, the component will use the -keys of the first object in the data array as the column headers. -The component will render the table with the provided data and column headers.`; - -export function Table({ data, colHeaders }: TableProps) { - const { updateState, addEvent } = useInformAI({ - name: "Table", - prompt, - props: { - data, - colHeaders, - }, - }); - - const cellClicked = (e: React.MouseEvent) => { - //would update any of the keys this Component already registered - updateState({ props: { colHeaders: ["new", "headers"] } }); - - //adds a new hint to the AI - addEvent({ - type: "click", - description: "User clicked on a cell with data: " + (e.target as HTMLElement).textContent, - }); - }; - - return ( -
- - - - {colHeaders - ? colHeaders.map((header, index) => ) - : Object.keys(data[0]).map((header, index) => )} - - - - {data.map((row, rowIndex) => ( - - {Object.values(row).map((cell, cellIndex) => ( - - ))} - - ))} - -
{header}{header}
- {cell as ReactNode} -
-
- ); -} diff --git a/src/example/actions.tsx b/src/example/actions.tsx deleted file mode 100644 index 92e0329..0000000 --- a/src/example/actions.tsx +++ /dev/null @@ -1,175 +0,0 @@ -"use server"; - -import { createAI, getMutableAIState, streamUI, createStreamableValue } from "ai/rsc"; -import { openai } from "@ai-sdk/openai"; - -import z from "zod"; - -import { createInformAI } from "../createInformAI"; -import { CoreMessage, generateId } from "ai"; - -const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); - -export async function submitUserMessage(content: string, role: string = "user") { - "use server"; - - const aiState = getMutableAIState(); - - aiState.update({ - ...aiState.get(), - messages: [ - ...aiState.get().messages, - { - id: generateId(), - role: "user", - content, - }, - ], - }); - - let textStream: undefined | ReturnType>; - let textNode: undefined | React.ReactNode; - - const result = await streamUI({ - model: openai("gpt-3.5-turbo"), - initial: "Spinner...", //, - system: `\ - You are a stock trading conversation bot and you can help users buy stocks, step by step. - You and the user can discuss stock prices and the user can adjust the amount of stocks they want to buy, or place an order, in the UI. - - Messages inside [] means that it's a UI element or a user event. For example: - - "[Price of AAPL = 100]" means that an interface of the stock price of AAPL is shown to the user. - - "[User has changed the amount of AAPL to 10]" means that the user has changed the amount of AAPL to 10 in the UI. - - If the user requests purchasing a stock, call \`show_stock_purchase_ui\` to show the purchase UI. - If the user just wants the price, call \`show_stock_price\` to show the price. - If you want to show trending stocks, call \`list_stocks\`. - If you want to show events, call \`get_events\`. - If the user wants to sell stock, or complete another impossible task, respond that you are a demo and cannot do that. - - Besides that, you can also chat with users and do some calculations if needed.`, - messages: [ - ...aiState.get().messages.map((message: any) => ({ - role: message.role, - content: message.content, - name: message.name, - })), - ], - text: ({ content, done, delta }) => { - if (!textStream) { - textStream = createStreamableValue(""); - // textNode =
{textStream.value}
; - } - - if (done) { - textStream.done(); - aiState.done({ - ...aiState.get(), - messages: [ - ...aiState.get().messages, - { - id: generateId(), - role: "assistant", - content, - }, - ], - }); - } else { - textStream.update(delta); - } - - return textNode; - }, - tools: { - listStocks: { - description: "List three imaginary stocks that are trending.", - parameters: z.object({ - stocks: z.array( - z.object({ - symbol: z.string().describe("The symbol of the stock"), - price: z.number().describe("The price of the stock"), - delta: z.number().describe("The change in price of the stock"), - }) - ), - }), - generate: async function* ({ stocks }) { - yield
Loading...
; - - await sleep(1000); - - const toolCallId = generateId(); - - aiState.done({ - ...aiState.get(), - messages: [ - ...aiState.get().messages, - { - id: generateId(), - role: "assistant", - content: [ - { - type: "tool-call", - toolName: "listStocks", - toolCallId, - args: { stocks }, - }, - ], - }, - { - id: generateId(), - role: "tool", - content: [ - { - type: "tool-result", - toolName: "listStocks", - toolCallId, - result: stocks, - }, - ], - }, - ], - }); - - return
Done
; - }, - }, - }, - }); - - return { - id: generateId(), - display: result.value, - }; -} - -export type ClientMessage = CoreMessage & { - id: string; -}; - -export type AIState = { - chatId: string; - messages: ClientMessage[]; -}; - -export type UIState = { - id: string; - display: React.ReactNode; -}[]; - -export const AI = createAI({ - actions: { - submitUserMessage, - }, - initialUIState: [] as UIState, - initialAIState: { chatId: generateId(), messages: [] } as AIState, -}); - -export const InformAI = createInformAI({ - // vercel: AI, - onEvent: (message: string) => { - // Custom logic to send a message to an LLM - //this is happening on the server - console.log(`Custom send message: ${message}`); - console.log(JSON.stringify(message, null, 4)); - }, -}); diff --git a/src/example/layout.tsx b/src/example/layout.tsx deleted file mode 100644 index 73cc38b..0000000 --- a/src/example/layout.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import { InformAI, AI } from "./actions"; - -export default function layout({ children }: { children: React.ReactNode }) { - return ( - - {children} - - ); -}