mirror of
https://github.com/msveshnikov/autocode-ai.git
synced 2026-10-21 05:31:29 +00:00
57 lines
2.3 KiB
JavaScript
57 lines
2.3 KiB
JavaScript
import Anthropic from "@anthropic-ai/sdk";
|
|
import { CONFIG } from "./config.js";
|
|
|
|
const anthropic = new Anthropic({ apiKey: process.env.CLAUDE_KEY });
|
|
|
|
const CodeGenerator = {
|
|
async generate(readme, currentCode, fileName, projectStructure) {
|
|
const prompt = `
|
|
You are CodeCraftAI, an automatic coding tool. Your task is to generate or update the ${fileName} file based on the README.md instructions, the current ${fileName} content (if any), and the project structure.
|
|
|
|
README.md content:
|
|
${readme}
|
|
|
|
Current ${fileName} content (if exists):
|
|
${currentCode || "No existing code"}
|
|
|
|
Project structure:
|
|
${JSON.stringify(projectStructure, null, 2)}
|
|
|
|
Please generate or update the ${fileName} file to implement the features described in the README. Ensure the code is complete, functional, and follows best practices. Consider the project structure when making changes or adding new features. Do not include any explanations or comments in your response, just provide the code.
|
|
`;
|
|
|
|
const response = await anthropic.messages.create({
|
|
model: CONFIG.anthropicModel,
|
|
max_tokens: CONFIG.maxTokens,
|
|
temperature: 0.7,
|
|
messages: [{ role: "user", content: prompt }],
|
|
});
|
|
|
|
return response.content[0].text;
|
|
},
|
|
|
|
async updateReadme(readme, projectStructure) {
|
|
const prompt = `
|
|
You are CodeCraftAI, an automatic coding tool. Your task is to update the README.md file with new design ideas and considerations based on the current content and project structure.
|
|
|
|
Current README.md content:
|
|
${readme}
|
|
|
|
Project structure:
|
|
${JSON.stringify(projectStructure, null, 2)}
|
|
|
|
Please update the README.md file with new design ideas and considerations. Ensure the content is well-structured and follows best practices. Consider the current project structure when suggesting improvements or new features. Do not include any explanations or comments in your response, just provide the updated README.md content.
|
|
`;
|
|
|
|
const response = await anthropic.messages.create({
|
|
model: CONFIG.anthropicModel,
|
|
max_tokens: CONFIG.maxTokens,
|
|
temperature: 0.7,
|
|
messages: [{ role: "user", content: prompt }],
|
|
});
|
|
|
|
return response.content[0].text;
|
|
},
|
|
};
|
|
|
|
export default CodeGenerator;
|