-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (ui/solid): useAssistant, useObject, fix deep object updating (#…
…3829) Co-authored-by: Ian Pascoe <ian.g.pascoe@gmail.com>
- Loading branch information
1 parent
b78b7fe
commit 88b364b
Showing
34 changed files
with
1,569 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@ai-sdk/ui-utils': patch | ||
--- | ||
|
||
fix (ui-utils): deep clone messages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@ai-sdk/solid': patch | ||
--- | ||
|
||
feat (ui/solid): add useObject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@ai-sdk/solid': patch | ||
--- | ||
|
||
feat (ui/solid): add useAssistant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@ai-sdk/solid': patch | ||
--- | ||
|
||
fix (ui/solid): fix useChat deep object updates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
examples/solidstart-openai/src/routes/api/use-object/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { openai } from '@ai-sdk/openai'; | ||
import { streamObject } from 'ai'; | ||
import { notificationSchema } from './schema'; | ||
import { APIHandler } from '@solidjs/start/server'; | ||
|
||
// Allow streaming responses up to 30 seconds | ||
export const maxDuration = 30; | ||
|
||
export const POST: APIHandler = async ({ request }) => { | ||
const context = await request.json(); | ||
|
||
const result = streamObject({ | ||
model: openai('gpt-4o'), | ||
prompt: `Generate 3 notifications for a messages app in this context: ${context}`, | ||
schema: notificationSchema, | ||
}); | ||
|
||
return result.toTextStreamResponse(); | ||
}; |
16 changes: 16 additions & 0 deletions
16
examples/solidstart-openai/src/routes/api/use-object/schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { DeepPartial } from 'ai'; | ||
import { z } from 'zod'; | ||
|
||
// define a schema for the notifications | ||
export const notificationSchema = z.object({ | ||
notifications: z.array( | ||
z.object({ | ||
name: z.string().describe('Name of a fictional person.'), | ||
message: z.string().describe('Message. Do not use emojis or links.'), | ||
minutesAgo: z.number(), | ||
}), | ||
), | ||
}); | ||
|
||
// define a type for the partial notifications during generation | ||
export type PartialNotification = DeepPartial<typeof notificationSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
examples/solidstart-openai/src/routes/use-object/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { experimental_useObject as useObject } from '@ai-sdk/solid'; | ||
import { notificationSchema } from '../api/use-object/schema'; | ||
import { For, Show } from 'solid-js'; | ||
|
||
export default function Page() { | ||
const { submit, isLoading, object, stop, error } = useObject({ | ||
api: '/api/use-object', | ||
schema: notificationSchema, | ||
}); | ||
|
||
return ( | ||
<div class="flex flex-col items-center min-h-screen p-4 m-4"> | ||
<button | ||
class="px-4 py-2 mt-4 text-white bg-blue-500 rounded-md disabled:bg-blue-200" | ||
onClick={async () => { | ||
submit('Messages during finals week.'); | ||
}} | ||
disabled={isLoading()} | ||
> | ||
Generate notifications | ||
</button> | ||
|
||
<Show when={error()}> | ||
{error => ( | ||
<div class="mt-4 text-red-500"> | ||
An error occurred. {error()?.message} | ||
</div> | ||
)} | ||
</Show> | ||
|
||
<Show when={isLoading()}> | ||
<div class="mt-4 text-gray-500"> | ||
<div>Loading...</div> | ||
<button | ||
type="button" | ||
class="px-4 py-2 mt-4 text-blue-500 border border-blue-500 rounded-md" | ||
onClick={() => stop()} | ||
> | ||
STOP | ||
</button> | ||
</div> | ||
</Show> | ||
|
||
<div class="flex flex-col gap-4 mt-4"> | ||
<For each={object()?.notifications}> | ||
{(notification, index) => ( | ||
<div | ||
class="flex items-start gap-4 p-4 bg-gray-100 rounded-md dark:bg-gray-800" | ||
data-index={index()} | ||
> | ||
<div class="flex-1 space-y-1"> | ||
<div class="flex items-center justify-between"> | ||
<p class="font-medium dark:text-white"> | ||
{notification?.name} | ||
</p> | ||
<p class="text-sm text-gray-500 dark:text-gray-400"> | ||
{notification?.minutesAgo} | ||
{notification?.minutesAgo != null ? ' minutes ago' : ''} | ||
</p> | ||
</div> | ||
<p class="text-gray-700 dark:text-gray-300"> | ||
{notification?.message} | ||
</p> | ||
</div> | ||
</div> | ||
)} | ||
</For> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './use-chat'; | ||
export * from './use-completion'; | ||
export * from './use-object'; | ||
export * from './use-assistant'; |
Oops, something went wrong.