1
1
import OpenAI from 'openai' ;
2
2
export class Chat {
3
3
private openai : OpenAI ;
4
+ private isAzure : boolean ;
5
+ private apiVersion ?: string ;
6
+ private deployment ?: string ;
4
7
5
8
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
+
6
17
this . openai = new OpenAI ( {
7
18
apiKey : apikey ,
8
- baseURL : process . env . OPENAI_API_ENDPOINT || 'https://api.openai.com/v1' ,
19
+ baseURL,
9
20
} ) ;
10
21
}
11
22
@@ -16,7 +27,7 @@ export class Chat {
16
27
17
28
const prompt =
18
29
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:' ;
20
31
21
32
return `${ prompt } , ${ answerLanguage } :
22
33
${ patch }
@@ -38,7 +49,8 @@ export class Chat {
38
49
content : prompt ,
39
50
}
40
51
] ,
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' ,
42
54
temperature : + ( process . env . temperature || 0 ) || 1 ,
43
55
top_p : + ( process . env . top_p || 0 ) || 1 ,
44
56
max_tokens : process . env . max_tokens
@@ -52,6 +64,6 @@ export class Chat {
52
64
return res . choices [ 0 ] . message . content ;
53
65
}
54
66
55
- return ""
67
+ return "" ;
56
68
} ;
57
69
}
0 commit comments