Skip to content
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

await is only valid in async functions and the top level bodies of modules error when you use the agentic sdk in server actions #669

Open
mundume opened this issue Aug 29, 2024 · 0 comments

Comments

@mundume
Copy link

mundume commented Aug 29, 2024

when i try run the agentic ai example on nextjs app router v14.2.6 on a server action i get this error Error: await is only valid in async functions and the top level bodies of modules here is my code

"use server";
import { createStreamableValue } from "ai/rsc";

import { createOpenAI, openai } from "@ai-sdk/openai";
import { streamText, tool } from "ai";
import { z } from "zod";
import { createAISDKTools } from "@agentic/ai-sdk";
import { WeatherClient } from "@agentic/weather";

const groq = createOpenAI({
  baseURL: "https://api.groq.com/openai/v1",
  apiKey: process.env.GROQ_API_KEY,
});


export async function tryGroq({ input }: { input: string }) {
  const stream = createStreamableValue("");
  const weather = new WeatherClient();

  (async () => {
    const { textStream } = await streamText({
      model: groq("llama3-8b-8192"),
      system: `you are a helpful assistant. Be as concise as possible and straightforward as possible`,
      tools: createAISDKTools(weather),
      toolChoice: "none",
      prompt: input,
    }).catch((error) => {
      console.error(error);
      throw error;
    });
    for await (const delta of textStream) {
      stream.update(delta);
    }

    stream.done();
  })();

  return {
    output: stream.value,
  };
}

Been trying to debug but im getting no help. any leads will be highly appreciated. thank you

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

No branches or pull requests

1 participant