1- # Copyright 2023 parkminwoo
21import bardapi
3- from os import environ
2+ import os
43
54
65def receive_bard_advice (bard_api_key : str , error_message : str ) -> str :
@@ -12,91 +11,47 @@ def receive_bard_advice(bard_api_key: str, error_message: str) -> str:
1211 :return: Returns a description and example of the code, the location of the error, and a debugging code example.
1312 :rtype: str
1413 """
15- environ ["_BARD_API_KEY" ] = bard_api_key
16-
17- if environ .get ("_PROMPT_COMMAND" ) is None :
18- if environ .get ("_BARD_ADVICE_LANG" ) is None :
14+ prompt_command = os .environ .get ("_PROMPT_COMMAND" )
15+ bard_advice_lang = os .environ .get ("_BARD_ADVICE_LANG" )
16+
17+ if prompt_command is None :
18+ if bard_advice_lang == "ko" :
1919 input_text = (
20- f"Give me more explanation for the following error."
21- f" And if you have a code example and a way to solve it, please suggest it. "
22- f"Please provide as much information as possible. error is { error_message } ."
20+ "다음 에러와 관련된 더 많은 설명을 알려줘. "
21+ "그리고 만약 이 오류와 관련된 코드 예제 및 유용한 자료가 있다면 가능한 많이 알려줘. "
22+ f"오류는 { error_message } 입니다."
23+ )
24+ elif bard_advice_lang == "jp" :
25+ input_text = (
26+ "いくつかのリンクまたはコード例を見つけてください。"
27+ "このエラーに関する詳細情報と、この問題に関連する StackOverflow URL を教えてください。 "
28+ f"エラーは { error_message } です。"
2329 )
2430 else :
25- if environ ["_BARD_ADVICE_LANG" ] == "ko" :
26- input_text = (
27- f"다음 에러와 관련된 더 많은 설명을 알려줘. "
28- f"그리고 만약 이 오류와 관련된 코드 예제 및 유용한 자료가 있다면 가능한 많이 알려줘. "
29- f"오류는 { error_message } 입니다."
30- )
31- elif environ ["_BARD_ADVICE_LANG" ] == "jp" :
32- input_text = (
33- f"いくつかのリンクまたはコード例を見つけてください。"
34- f"このエラーに関する詳細情報と、この問題に関連する StackOverflow URL を教えてください。 "
35- f"エラーは { error_message } です。"
36- )
37- else :
38- print (
39- "You can only use ko or jp for the _BARD_ADVICE_LANG variable. "
40- "Hence, answers will be provided in English."
41- )
42- input_text = (
43- f"Give me more explanation for the following error. "
44- f"And if you have a code example and a way to solve it, please suggest it. "
45- f"Please provide as much information as possible. error is { error_message } ."
46- )
31+ input_text = (
32+ "Give me more explanation for the following error. "
33+ "And if you have a code example and a way to solve it, please suggest it. "
34+ f"Please provide as much information as possible. error is { error_message } ."
35+ )
4736 else :
48- input_text = f"{ environ [ '_PROMPT_COMMAND' ] } error=={ error_message } "
37+ input_text = f"{ prompt_command } error=={ error_message } "
4938
50- response = bardapi . core . Bard (). get_answer ( input_text )
51- advice_msg = response [ "content" ]
39+ bard_api_key = os . environ . get ( "_BARD_API_KEY" , bard_api_key )
40+ bard_lang = os . environ . get ( "_BARD_ADVICE_LANG" , "" )
5241
53- return advice_msg
42+ response = bardapi . core . Bard ( token = bard_api_key , language = bard_lang ). get_answer ( input_text )
5443
44+ return response ["content" ]
5545
56- def get_response_bard_advice (bard_api_key : str , error_message : str ) -> dict :
46+
47+ def get_response_bard_advice () -> dict :
5748 """
58- :param bard_api_key:__Secure-1PSID value of Google bard
59- :type bard_api_key: str
60- :param error_message: Error message
61- :type error_message: str
6249 :return: Returns a response
6350 :rtype: str
6451 """
65- environ ["_BARD_API_KEY" ] = bard_api_key
66-
67- if environ .get ("_PROMPT_COMMAND" ) is None :
68- if environ .get ("_BARD_ADVICE_LANG" ) is None :
69- input_text = (
70- f"Give me more explanation for the following error."
71- f" And if you have a code example and a way to solve it, please suggest it. "
72- f"Please provide as much information as possible. error is { error_message } ."
73- )
74- else :
75- if environ ["_BARD_ADVICE_LANG" ] == "ko" :
76- input_text = (
77- f"다음 에러와 관련된 더 많은 설명을 알려줘. "
78- f"그리고 만약 이 오류와 관련된 코드 예제 및 유용한 자료가 있다면 가능한 많이 알려줘. "
79- f"오류는 { error_message } 입니다."
80- )
81- elif environ ["_BARD_ADVICE_LANG" ] == "jp" :
82- input_text = (
83- f"いくつかのリンクまたはコード例を見つけてください。"
84- f"このエラーに関する詳細情報と、この問題に関連する StackOverflow URL を教えてください。 "
85- f"エラーは { error_message } です。"
86- )
87- else :
88- print (
89- "You can only use ko or jp for the _BARD_ADVICE_LANG variable. "
90- "Hence, answers will be provided in English."
91- )
92- input_text = (
93- f"Give me more explanation for the following error. "
94- f"And if you have a code example and a way to solve it, please suggest it. "
95- f"Please provide as much information as possible. error is { error_message } ."
96- )
97- else :
98- input_text = f"{ environ ['_PROMPT_COMMAND' ]} error=={ error_message } "
52+ bard_api_key = os .environ .get ("_BARD_API_KEY" , "" )
53+ bard_lang = os .environ .get ("_BARD_ADVICE_LANG" , "" )
9954
100- response = bardapi .core .Bard ().get_answer (input_text )
55+ response = bardapi .core .Bard (token = bard_api_key , language = bard_lang ).get_answer ("test_message" )
10156
10257 return response
0 commit comments