forked from reworkd/AgentGPT
-
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
Showing
2 changed files
with
31 additions
and
25 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 |
---|---|---|
@@ -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(); | ||
}; |