Skip to content

Commit

Permalink
example
Browse files Browse the repository at this point in the history
  • Loading branch information
lgrammel committed Nov 22, 2024
1 parent b607840 commit 1ef4ef0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions examples/agent-server/agents/routing-example/states/chat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { StreamState } from '@ai-sdk/agent-server';
import { openai } from '@ai-sdk/openai';
import { streamText } from 'ai';
import { Context } from '../context';

export default {
type: 'stream',
async execute({ context }) {
const result = streamText({
model: openai('gpt-4o'),
system: 'You are a friendly chatbot. Respond briefly and concisely.',
prompt: context.prompt,
});

return {
// streamText will expose streams specifically for the agent server
// in the future:
// stream: result.toAgentStream()
// for now we need to decode:
stream: result.toDataStream().pipeThrough(new TextDecoderStream()),
nextState: 'END',
};
},
} satisfies StreamState<Context, string>;

0 comments on commit 1ef4ef0

Please sign in to comment.