Skip to content

Instantly share code, notes, and snippets.

@RafalWilinski
Created April 6, 2023 19:07
Show Gist options
  • Save RafalWilinski/7e031fa7ace88bbd2e6e75390f157461 to your computer and use it in GitHub Desktop.
Save RafalWilinski/7e031fa7ace88bbd2e6e75390f157461 to your computer and use it in GitHub Desktop.
const awsTool = new DynamicTool({
name: "aws-cli",
description:
"This is AWS CLI. You can call this to send commands to the AWS Cloud. Use AWS CLI format like `aws s3api list-buckets`",
async func(command) {
const args = command.split(" ").filter((x) => x !== "aws");
const result = spawnSync("aws", args, {
env: {
...process.env,
AWS_REGION: "eu-central-1",
AWS_DEFAULT_REGION: "eu-central-1",
},
});
return JSON.stringify(JSON.parse(result.stdout.toString()));
},
});
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
const model = new OpenAI({ temperature: 0.5, modelName: "gpt-4" });
const tools = [awsTool];
const executor = await initializeAgentExecutor(
tools,
model,
"chat-zero-shot-react-description",
true
);
const input = req.query["input"];
if (!input) {
res.status(400).write("Missing input parameter");
return;
}
const result = await executor.call({ input });
return res.status(200).json({ result, input });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment