sfcoe-ailabs
Version:
AI-powered code review tool with static analysis integration for comprehensive code quality assessment.
43 lines (42 loc) • 1.68 kB
JavaScript
import { Anthropic } from '@anthropic-ai/sdk';
import { Logger } from '../utils/observability.js';
import AIProvider from './aiProvider.js';
export default class AnthropicAiClient extends AIProvider {
/**
* Reviews code using Anthropic's Claude model
*
* @param codeSnippet - The code to be reviewed
* @param hints - Array of review hints from static analysis tools
* @returns Promise that resolves to the AI review response
*/
async reviewCode(codeSnippet, hints) {
Logger.debug(`Starting Anthropic Client review with ${hints.length} hints`, hints.map((h) => `${h.ruleId}: ${h.message}`));
const anthropic = new Anthropic({ apiKey: this.getApiKey() });
const message = await anthropic.messages.create({
model: this.getModel(),
max_tokens: this.getMaxTokens(),
system: AnthropicAiClient.getReviewInstructions(),
messages: [
{
role: 'assistant',
content: [
{
type: 'text',
text: AnthropicAiClient.getReviewInstructions(),
},
],
},
{
role: 'user',
content: AnthropicAiClient.generatePrompt(codeSnippet, hints),
},
],
});
// get result from message response and return it
const content = message.content[0].text;
if (content === null) {
throw new Error('Anthropic response content is null');
}
return JSON.parse(content);
}
}