Spaces:
Runtime error
Runtime error
niuyazhe
commited on
Commit
·
4ccff9f
1
Parent(s):
7d0a39c
feature(nyz): add api key env variable
Browse files
app.py
CHANGED
|
@@ -9,7 +9,10 @@ from llmriddles.questions import list_ordered_questions
|
|
| 9 |
_QUESTION_IDS = {}
|
| 10 |
_QUESTIONS = list_ordered_questions()
|
| 11 |
_LANG = os.environ.get('QUESTION_LANG', 'cn')
|
|
|
|
| 12 |
_LLM = os.environ.get('QUESTION_LLM', 'chatgpt')
|
|
|
|
|
|
|
| 13 |
|
| 14 |
if _LANG == "cn":
|
| 15 |
title = "完蛋!我被 LLM 拿捏了"
|
|
@@ -98,7 +101,7 @@ else:
|
|
| 98 |
|
| 99 |
|
| 100 |
def _need_api_key():
|
| 101 |
-
return _LLM == 'chatgpt'
|
| 102 |
|
| 103 |
|
| 104 |
def _get_api_key_cfgs(api_key):
|
|
@@ -117,8 +120,7 @@ if __name__ == '__main__':
|
|
| 117 |
with gr.Row():
|
| 118 |
with gr.Column():
|
| 119 |
gr_question = gr.TextArea(placeholder=question_ph, label=question_label)
|
| 120 |
-
gr_api_key = gr.Text(placeholder=api_ph, label=api_label, type='password',
|
| 121 |
-
visible=_need_api_key())
|
| 122 |
with gr.Row():
|
| 123 |
gr_submit = gr.Button(submit_label, interactive=True)
|
| 124 |
gr_next = gr.Button(next_label)
|
|
@@ -170,7 +172,7 @@ if __name__ == '__main__':
|
|
| 170 |
_qid = _QUESTION_IDS[uuid_]
|
| 171 |
executor = QuestionExecutor(
|
| 172 |
_QUESTIONS[_qid], _LANG,
|
| 173 |
-
llm=_LLM, llm_cfgs=_get_api_key_cfgs(api_key) if _need_api_key() else {}
|
| 174 |
)
|
| 175 |
answer_text, correctness, explanation = executor.check(qs_text)
|
| 176 |
labels = {correct_label: 1.0} if correctness else {wrong_label: 1.0}
|
|
|
|
| 9 |
_QUESTION_IDS = {}
|
| 10 |
_QUESTIONS = list_ordered_questions()
|
| 11 |
_LANG = os.environ.get('QUESTION_LANG', 'cn')
|
| 12 |
+
assert _LANG in ['cn', 'en'], _LANG
|
| 13 |
_LLM = os.environ.get('QUESTION_LLM', 'chatgpt')
|
| 14 |
+
assert _LLM in ['chatgpt', 'llama2-7b'], _LLM
|
| 15 |
+
_LLM_KEY = os.environ.get('QUESTION_LLM_KEY', None)
|
| 16 |
|
| 17 |
if _LANG == "cn":
|
| 18 |
title = "完蛋!我被 LLM 拿捏了"
|
|
|
|
| 101 |
|
| 102 |
|
| 103 |
def _need_api_key():
|
| 104 |
+
return _LLM == 'chatgpt' and _LLM_KEY is None
|
| 105 |
|
| 106 |
|
| 107 |
def _get_api_key_cfgs(api_key):
|
|
|
|
| 120 |
with gr.Row():
|
| 121 |
with gr.Column():
|
| 122 |
gr_question = gr.TextArea(placeholder=question_ph, label=question_label)
|
| 123 |
+
gr_api_key = gr.Text(placeholder=api_ph, label=api_label, type='password', visible=_need_api_key())
|
|
|
|
| 124 |
with gr.Row():
|
| 125 |
gr_submit = gr.Button(submit_label, interactive=True)
|
| 126 |
gr_next = gr.Button(next_label)
|
|
|
|
| 172 |
_qid = _QUESTION_IDS[uuid_]
|
| 173 |
executor = QuestionExecutor(
|
| 174 |
_QUESTIONS[_qid], _LANG,
|
| 175 |
+
llm=_LLM, llm_cfgs=_get_api_key_cfgs(api_key) if _need_api_key() else {'api_key': _LLM_KEY}
|
| 176 |
)
|
| 177 |
answer_text, correctness, explanation = executor.check(qs_text)
|
| 178 |
labels = {correct_label: 1.0} if correctness else {wrong_label: 1.0}
|