sfcoe-ailabs
Version:
AI-powered code review tool with static analysis integration for comprehensive code quality assessment.
55 lines (54 loc) • 1.96 kB
JavaScript
// Load node modules
import { AzureOpenAI } from 'openai';
// Load local modules
import { Logger } from '../utils/observability.js';
import AIProvider from './aiProvider.js';
export default class AzureOpenAiClient extends AIProvider {
/**
* Reviews code using Azure OpenAI's GPT 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 Azure OpenAI Client review with ${hints.length} hints`, hints.map((h) => `${h.ruleId}: ${h.message}`));
const openai = new AzureOpenAI({
endpoint: this.getAPIEndpoint(),
apiKey: this.getApiKey(),
apiVersion: this.getAPIVersion(),
deployment: this.getModel(),
});
const completion = await openai.chat.completions.create({
model: this.getModel(),
messages: [
{
role: 'assistant',
content: [
{
type: 'text',
text: AzureOpenAiClient.getReviewInstructions(),
},
],
},
{
role: 'user',
content: [
{
type: 'text',
text: AzureOpenAiClient.generatePrompt(codeSnippet, hints),
},
],
},
],
response_format: {
type: 'json_object',
},
});
const content = completion.choices[0].message.content;
if (content === null) {
throw new Error('OpenAI response content is null');
}
return JSON.parse(content);
}
}