10
10
import requests
11
11
12
12
13
- def get_suggestion (issue_body : str ) -> str :
14
- payload = json .dumps ({'integration_id' : os .environ ['BOT_INTEGRATION_ID' ], 'query' : issue_body })
13
+ def get_suggestion (query : str , instructions : str , behavior : str ) -> str :
14
+ payload = json .dumps (
15
+ {
16
+ 'integration_id' : os .environ ['BOT_INTEGRATION_ID' ],
17
+ 'messages' : [
18
+ {'role' : 'system' , 'content' : behavior },
19
+ {'role' : 'context' },
20
+ {'role' : 'user' , 'content' : instructions },
21
+ {'role' : 'query' , 'content' : query },
22
+ {
23
+ 'role' : 'user' ,
24
+ 'content' : 'Output your response in Github markdown. Do not use e-mail template and do not sign the output.' ,
25
+ },
26
+ ],
27
+ }
28
+ )
29
+
30
+ endpoint = os .environ ['BOT_API_ENDPOINT' ]
31
+
32
+ if endpoint .endswith ('chat/' ):
33
+ # Switch to "custom chat" feature if the URL is for simple chat
34
+ endpoint = f'{ endpoint } custom/'
15
35
16
36
headers = {'content-type' : 'application/json' , 'X-API-KEY' : os .environ ['BOT_API_KEY' ]}
17
- r = requests .post (os . environ [ 'BOT_API_ENDPOINT' ] , data = payload , headers = headers )
37
+ r = requests .post (endpoint , data = payload , headers = headers )
18
38
19
39
r .raise_for_status ()
20
40
j = r .json ()
@@ -30,12 +50,17 @@ def get_suggestion(issue_body: str) -> str:
30
50
31
51
def main ():
32
52
parser = argparse .ArgumentParser ()
33
- parser .add_argument ('input_file' , type = str , default = None )
53
+ parser .add_argument ('query_file' , type = str , default = None )
54
+ parser .add_argument ('--instructions' , type = str , required = True )
55
+ parser .add_argument ('--behavior' , type = str , required = True )
34
56
args = parser .parse_args ()
35
57
36
- if args .input_file :
37
- with open (args .input_file , 'r' , encoding = 'utf-8' ) as f :
38
- print (get_suggestion (f .read ()))
58
+ with (
59
+ open (args .query_file , 'r' , encoding = 'utf-8' ) as q ,
60
+ open (args .instructions , 'r' , encoding = 'utf-8' ) as inst ,
61
+ open (args .behavior , 'r' , encoding = 'utf-8' ) as behav ,
62
+ ):
63
+ print (get_suggestion (q .read (), inst .read (), behav .read ()))
39
64
40
65
41
66
if __name__ == '__main__' :
0 commit comments