Skip to content

Commit a111dbf

Browse files
Initial commit
0 parents  commit a111dbf

File tree

5 files changed

+97
-0
lines changed

5 files changed

+97
-0
lines changed

Diff for: .gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
node_modules
2+
.env
3+
coverage
4+
coverage.json
5+
yarn.lock
6+
keys
7+
8+
#Build outputs
9+
cache
10+
artifacts
11+

Diff for: askZoidberg.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const sendToClaude = require("./sendToClaude");
2+
3+
async function askZoidberg(userQuestion) {
4+
try {
5+
// Step 2: Build Prompt
6+
let prompt = `This is the user request: ${userQuestion}.`;
7+
8+
// Step 3: Send Data to the Antrhopic API
9+
const code = await sendToClaude(prompt);
10+
11+
// Step 4: Return code
12+
return code;
13+
} catch (error) {
14+
console.error("An error occurred:", error);
15+
throw error;
16+
}
17+
}
18+
19+
module.exports = askZoidberg;

Diff for: index.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require("dotenv").config();
2+
const askZoidberg = require("./askZoidberg.js");
3+
4+
exports.zoidbergAssistant = async (req, res) => {
5+
const apiKey = req.headers["x-api-key"] || req.query.api_key;
6+
7+
if (!apiKey || apiKey !== process.env.ENDPOINT_API_KEY) {
8+
res.status(401).send({ error: "Unauthorized" });
9+
return;
10+
}
11+
12+
try {
13+
const userInstruction =
14+
req.query.instruction ||
15+
res.status(400).send({
16+
error:
17+
"Please provide an instruction for Zoidberg in your query parameters.",
18+
});
19+
const answer = await askZoidberg(userInstruction);
20+
res.status(200).send({ answer });
21+
} catch (error) {
22+
console.error("Error:", error);
23+
res.status(500).send({ error: "An error occurred" });
24+
}
25+
};

Diff for: package.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "aecworks-chatbot",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"@anthropic-ai/sdk": "^0.19.0",
6+
"@google-cloud/bigquery": "^7.5.1",
7+
"@google-cloud/functions-framework": "^3.0.0",
8+
"@types/node": "^20.11.30",
9+
"express": "^4.19.2"
10+
},
11+
"scripts": {
12+
"start": "functions-framework --target=aecWorksChatbot"
13+
},
14+
"devDependencies": {
15+
"dotenv": "^16.4.5"
16+
}
17+
}

Diff for: sendToClaude.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const { Anthropic } = require("@anthropic-ai/sdk");
2+
require("dotenv").config();
3+
4+
async function sendToClaude(prompt) {
5+
const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
6+
7+
try {
8+
const response = await anthropic.messages.create({
9+
model: process.env.ANTHROPIC_MODEL,
10+
max_tokens: 4096,
11+
temperature: 0,
12+
system:
13+
"You're Zoidberg, an expert in AEC technology and BIM development that helps with Revit requests. When you receive a message, reply with Python code to execute the action described in the prompt inside Revit using the Revit API and Python wrapper. Don't add anything that isn't code, not a single character.",
14+
messages: [{ role: "user", content: prompt }],
15+
});
16+
console.log(response);
17+
18+
return response.content[0].text;
19+
} catch (error) {
20+
console.error("Error sending message to Claude:", error);
21+
throw error;
22+
}
23+
}
24+
25+
module.exports = sendToClaude;

0 commit comments

Comments
 (0)