Skip to content

feat: vercel/ai binding #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

feat: vercel/ai binding #76

wants to merge 1 commit into from

Conversation

himself65
Copy link
Member

@himself65 himself65 commented Apr 24, 2025

basic example:

import { createWorkflow, workflowEvent } from "@llama-flow/core";
import { mergeToWorkflow } from "@llama-flow/core/ai";
import { streamText } from "ai";
import { openai } from "@ai-sdk/openai";

const chatWorkflow = createWorkflow();

const startChatEvent = workflowEvent<string>();
const stopChatEvent = workflowEvent();

chatWorkflow.handle([startChatEvent], async () => {
  const result = streamText({
    model: openai("gpt-4.1"),
    prompt: "You are a helpful assistant.",
  });
  await mergeToWorkflow(result.fullStream);
  return stopChatEvent.with();
});

export { startChatEvent, stopChatEvent, chatWorkflow };
app.post("/chat", async (context) => {
  const { messages } = await context.req.json();
  const { stream, sendEvent } = chatWorkflow.createContext();
  sendEvent(startChatEvent.with(messages));
  return new Response(dataStream(stream));
});
// frontend
import { useChat } from 'ai/react'

useChat({
  api: '/chat'
})

Copy link

pkg-pr-new bot commented Apr 24, 2025

Open in StackBlitz

npm i https://pkg.pr.new/run-llama/llama-flow/@llama-flow/core@76
npm i https://pkg.pr.new/run-llama/llama-flow/@llama-flow/llamaindex@76

commit: da20c69

Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant