Skip to content

Commit

Permalink
⚡ excute chain on edge
Browse files Browse the repository at this point in the history
  • Loading branch information
awtkns committed Apr 12, 2023
1 parent 9eb8021 commit 9c247c5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
4 changes: 4 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ const config = {
locales: ["en"],
defaultLocale: "en",
},
webpack: function (config, options) {
config.experiments = { asyncWebAssembly: true, layers: true };
return config;
}
};
export default config;
52 changes: 27 additions & 25 deletions src/pages/api/execute.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
import type { NextApiRequest } from "next";
import type { NextApiResponse } from "next";
import { createModel, executeTaskAgent } from "../../utils/chain";
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";

export interface ExecuteAPIRequest extends NextApiRequest {
body: {
customApiKey: string;
goal: string;
task: string;
};
interface RequestBody {
customApiKey: string;
goal: string;
task: string;
}
export const config = {
runtime: "edge",
};

export interface ExecuteAPIResponse extends NextApiResponse {
body: {
response: string;
};
}
export default async (request: NextRequest) => {
let data: RequestBody | null = null;
try {
data = (await request.json()) as RequestBody;
console.log(data);

export default async function handler(
req: ExecuteAPIRequest,
res: ExecuteAPIResponse
) {
const completion = await executeTaskAgent(
createModel(req.body.customApiKey),
req.body.goal,
req.body.task
);
console.log(completion.text);
res.status(200).json({ response: completion.text as string });
}
const completion = await executeTaskAgent(
createModel(data.customApiKey),
data.goal,
data.task
);

return NextResponse.json({
response: completion.text as string,
});
} catch (e) {}

// return NextResponse();
};

0 comments on commit 9c247c5

Please sign in to comment.