-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1bb4c06
commit aef9047
Showing
101 changed files
with
3,667 additions
and
2,095 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
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 |
---|---|---|
|
@@ -14,4 +14,4 @@ | |
"components": "@/components", | ||
"utils": "@/lib/utils" | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { openai } from '@ai-sdk/openai'; | ||
import { convertToCoreMessages, streamText } from 'ai'; | ||
import { z } from 'zod'; | ||
|
||
// Allow streaming responses up to 30 seconds | ||
export const maxDuration = 30; | ||
|
||
export async function POST(req: Request) { | ||
const { messages } = await req.json(); | ||
|
||
const result = await streamText({ | ||
model: openai('gpt-4-turbo'), | ||
messages: convertToCoreMessages(messages), | ||
tools: { | ||
// server-side tool with execute function: | ||
getWeatherInformation: { | ||
description: 'show the weather in a given city to the user', | ||
parameters: z.object({ city: z.string() }), | ||
// eslint-disable-next-line no-empty-pattern | ||
execute: async ({}: { city: string }) => { | ||
const weatherOptions = ['sunny', 'cloudy', 'rainy', 'snowy', 'windy']; | ||
return weatherOptions[ | ||
Math.floor(Math.random() * weatherOptions.length) | ||
]; | ||
}, | ||
}, | ||
// client-side tool that starts user interaction: | ||
askForConfirmation: { | ||
description: 'Ask the user for confirmation.', | ||
parameters: z.object({ | ||
message: z.string().describe('The message to ask for confirmation.'), | ||
}), | ||
}, | ||
// client-side tool that is automatically executed on the client: | ||
getLocation: { | ||
description: | ||
'Get the user location. Always ask for confirmation before using this tool.', | ||
parameters: z.object({}), | ||
}, | ||
}, | ||
}); | ||
|
||
return result.toDataStreamResponse(); | ||
} |
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,8 +1,8 @@ | ||
import Nylas from "nylas"; | ||
import Nylas from 'nylas'; | ||
|
||
const NylasConfig = { | ||
apiKey: process.env.NYLAS_API_KEY, | ||
apiUri: 'https://api.us.nylas.com', | ||
}; | ||
|
||
export const nylas = new Nylas(NylasConfig) | ||
export const nylas = new Nylas(NylasConfig); |
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,6 +1,5 @@ | ||
import OpenAI from "openai"; | ||
import OpenAI from 'openai'; | ||
|
||
export const openai = new OpenAI({ | ||
apiKey: process.env.OPENAI_API_KEY, | ||
}); | ||
|
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use server'; | ||
|
||
import { openai } from '@ai-sdk/openai'; | ||
import { streamText } from 'ai'; | ||
import { createStreamableValue } from 'ai/rsc'; | ||
|
||
export async function generate(input: string) { | ||
const stream = createStreamableValue(''); | ||
|
||
(async () => { | ||
const { textStream } = await streamText({ | ||
model: openai('gpt-3.5-turbo'), | ||
prompt: input, | ||
}); | ||
|
||
for await (const delta of textStream) { | ||
stream.update(delta); | ||
} | ||
|
||
stream.done(); | ||
})(); | ||
|
||
return { output: stream.value }; | ||
} |
Oops, something went wrong.