Last active
November 1, 2023 18:59
-
-
Save homanp/a2a948b0851d899682214643be7d700c to your computer and use it in GitHub Desktop.
Superagent Github Researcher
This file contains hidden or 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
// npm i superagentai-js | |
import { SuperAgentClient } from "superagentai-js"; | |
const GITHUB_REPO_URL = "https://github.com/homanp/nagato"; | |
const PROMPT = `You are a helpful AI assistant that's an expert at answering questions about the following Github repository: ${GITHUB_REPO_URL}\n\nAlways use the functions provided to answer all questions by the user.`; | |
interface Agent { | |
id: string; | |
name: string; | |
description: string; | |
isActive: boolean; | |
llmProvider: string; | |
prompt: string; | |
} | |
interface Tool { | |
id: string; | |
name: string; | |
description: string; | |
type: string; | |
returnDirect: boolean; | |
} | |
interface Output { | |
output: string; | |
} | |
const superagent = new SuperAgentClient({ | |
token: process.env.SUPERAGENT_API_TOKEN as string, | |
environment: "https://api.beta.superagent.sh" | |
}); | |
// Create the agent | |
const { data: agent } = await superagent.agent.create<Agent>({ | |
name: "Github Assistant", | |
description: "An assistant that can chat with a Github repo.", | |
isActive: true, | |
llmProvider: "GPT_3_5_TURBO_16K_0613", | |
prompt: PROMPT, | |
}); | |
// Create the tool | |
const { data: tool } = await superagent.tool.create<Tool>({ | |
name: "Browser", | |
description: "A portal to the internet. Use this when you need to get specific content from a website.", | |
type: "BROWSER", | |
returnDirect: false, | |
}); | |
// Add tool to agent | |
await superagent.agent.addTool(agent.id, { | |
toolId: tool.id | |
}); | |
// Invoke the agent | |
const { data } = await superagent.agent.invoke<Output>(agent.id, { | |
input: "Summarize the README", | |
enableStreaming: false, | |
sessionId: "" // Optional session id | |
}); | |
console.log(data.output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment