11import OpenAI from 'openai' ;
22export class Chat {
33 private openai : OpenAI ;
4+ private isAzure : boolean ;
5+ private apiVersion ?: string ;
6+ private deployment ?: string ;
47
58 constructor ( apikey : string ) {
9+ this . isAzure = Boolean ( process . env . AZURE_API_VERSION && process . env . AZURE_DEPLOYMENT ) ;
10+ this . apiVersion = process . env . AZURE_API_VERSION || '' ;
11+ this . deployment = process . env . AZURE_DEPLOYMENT || '' ;
12+
13+ const baseURL = this . isAzure
14+ ? `${ process . env . OPENAI_API_ENDPOINT } /openai/deployments/${ this . deployment } /chat/completions?api-version=${ this . apiVersion } `
15+ : process . env . OPENAI_API_ENDPOINT || 'https://api.openai.com/v1' ;
16+
617 this . openai = new OpenAI ( {
718 apiKey : apikey ,
8- baseURL : process . env . OPENAI_API_ENDPOINT || 'https://api.openai.com/v1' ,
19+ baseURL,
920 } ) ;
1021 }
1122
@@ -16,7 +27,7 @@ export class Chat {
1627
1728 const prompt =
1829 process . env . PROMPT ||
19- 'Below is a code patch, please help me do a brief code review on it. Any bug risks and/or improvement suggestions are welcome:' ;
30+ 'Below is a code patch, please help me do a brief code review on it. Any bug risks and/or improvement suggestions are welcome:' ;
2031
2132 return `${ prompt } , ${ answerLanguage } :
2233 ${ patch }
@@ -38,7 +49,8 @@ export class Chat {
3849 content : prompt ,
3950 }
4051 ] ,
41- model : process . env . MODEL || 'gpt-4o-mini' ,
52+ // Use model or deployment name based on the environment
53+ model : this . isAzure ? this . deployment : process . env . MODEL || 'gpt-4' ,
4254 temperature : + ( process . env . temperature || 0 ) || 1 ,
4355 top_p : + ( process . env . top_p || 0 ) || 1 ,
4456 max_tokens : process . env . max_tokens
@@ -52,6 +64,6 @@ export class Chat {
5264 return res . choices [ 0 ] . message . content ;
5365 }
5466
55- return ""
67+ return "" ;
5668 } ;
5769}
0 commit comments