diff --git a/Seanium_Brain.py b/Seanium_Brain.py index ed0a23d..c275871 100644 --- a/Seanium_Brain.py +++ b/Seanium_Brain.py @@ -15,7 +15,7 @@ if 'SESSION_LANGUAGE' not in st.session_state: st.session_state['SESSION_LANGUAGE'] = util.read_json_at('.user/language.json', 'SESSION_LANGUAGE', 'en_US') st.set_page_config( - page_title='Seanium Brain' + page_title='GPT Brain' ) util.remove_oldest_file('.user/log', 10) @@ -24,8 +24,9 @@ model_options = ['text-davinci-003', 'text-curie-001', 'text-babbage-001', 'text header = st.container() body = st.container() LOG_PATH = '.user/log' -PROMPT_PATH = '.user/prompt' SESSION_TIME = st.session_state['SESSION_TIME'] +SESSION_LANG = st.session_state['SESSION_LANGUAGE'] +PROMPT_PATH = f'.user/prompt/{SESSION_LANG}' CURRENT_LOG_FILE = f'{LOG_PATH}/log_{SESSION_TIME}.log' BRAIN_MEMO = '.user/brain-memo.json' MANIFEST = '.core/manifest.json' @@ -102,11 +103,11 @@ with st.sidebar: prompt_file_names = [util.get_file_name(file) for file in prompt_files] prompt_dictionary = dict(zip(prompt_file_names, prompt_files)) # remove 'my-info' from prompt dictionary - prompt_dictionary.pop('my-info') + prompt_dictionary.pop(_('my-info')) operation_options = list(prompt_dictionary.keys()) - - operations = st.multiselect(_('Operations'), operation_options, default=util.read_json_at(BRAIN_MEMO, 'operations', + print(util.read_json_at(BRAIN_MEMO, f'operations_{SESSION_LANG}', operation_options[0])) + operations = st.multiselect(_('Operations'), operation_options, default=util.read_json_at(BRAIN_MEMO, f'operations_{SESSION_LANG}', operation_options[0])) last_question_model = util.read_json_at(BRAIN_MEMO, 'question_model', model_options[0]) @@ -114,7 +115,7 @@ with st.sidebar: question_model_index = util.get_index(model_options, last_question_model) question_model = st.selectbox(_('Question Model'), model_options, index=question_model_index) - operations_no_question = [op for op in operations if op != 'question'] + operations_no_question = [op for op in operations if op != _('question')] other_models = [] replace_tokens = [] for operation in operations_no_question: @@ -182,7 +183,7 @@ def execute_brain(q): with st.spinner(_('Thinking on Answer')): answer = brain.run_answer(q, question_model, temp, max_tokens, top_p, freq_panl, pres_panl, chunk_count=chunk_count) - if util.contains(operations, 'question'): + if util.contains(operations, _('question')): # displaying results st.header(_('💬Answer')) st.info(f'{answer}') @@ -204,7 +205,7 @@ def execute_brain(q): util.update_json(BRAIN_MEMO, key, value) # write operation to json - util.update_json(BRAIN_MEMO, 'operations', operations) + util.update_json(BRAIN_MEMO, f'operations_{SESSION_LANG}', operations) # write question model to json util.update_json(BRAIN_MEMO, 'question_model', question_model) diff --git a/example_prompt/my-info.txt b/example_prompt/en_US/my-info.txt similarity index 100% rename from example_prompt/my-info.txt rename to example_prompt/en_US/my-info.txt diff --git a/example_prompt/question.txt b/example_prompt/en_US/question.txt similarity index 100% rename from example_prompt/question.txt rename to example_prompt/en_US/question.txt diff --git a/example_prompt/summarize.txt b/example_prompt/en_US/summarize.txt similarity index 100% rename from example_prompt/summarize.txt rename to example_prompt/en_US/summarize.txt diff --git a/example_prompt/zh_CN/总结.txt b/example_prompt/zh_CN/总结.txt new file mode 100644 index 0000000..1d951eb --- /dev/null +++ b/example_prompt/zh_CN/总结.txt @@ -0,0 +1,5 @@ +为以下文章总结成清晰易读的要点, 注意包含所有的重要信息。 + +<> + +要点: \ No newline at end of file diff --git a/example_prompt/zh_CN/我的背景.txt b/example_prompt/zh_CN/我的背景.txt new file mode 100644 index 0000000..dad0109 --- /dev/null +++ b/example_prompt/zh_CN/我的背景.txt @@ -0,0 +1 @@ +我的名字是肖恩,我是一名建筑学学生。 diff --git a/example_prompt/zh_CN/问题.txt b/example_prompt/zh_CN/问题.txt new file mode 100644 index 0000000..bc5625e --- /dev/null +++ b/example_prompt/zh_CN/问题.txt @@ -0,0 +1,4 @@ +根据 <> 的前提, 通过以下信息: <> , 以一个建筑师的角度回答问题: <> 并给予答案, 要求答案文笔清晰,能够容易的阅读,并且避免重复的内容。 +确保答案包含所有关键的内容。 + +答案: \ No newline at end of file diff --git a/modules/utilities.py b/modules/utilities.py index d42e53f..c904719 100644 --- a/modules/utilities.py +++ b/modules/utilities.py @@ -112,8 +112,8 @@ def create_json_not_exist(filepath, initial_value={}): write_json(initial_value, filepath) -def write_json(content, filepath, mode='w'): - with open(filepath, mode) as file: +def write_json(content, filepath, mode='w', encoding='UTF-8'): + with open(filepath, mode, encoding=encoding) as file: json.dump(content, file, indent=2) diff --git a/setup.bat b/setup.bat index c033bc6..11212ab 100644 --- a/setup.bat +++ b/setup.bat @@ -23,9 +23,12 @@ REM if .user\ not exist, create one if not exist .user\ (md .user\) REM Create API KEY file -set /p API_KEYS=[Enter your API keys]: -echo %API_KEYS%> .user\API-KEYS.txt -echo API key written to file! +if not exist .user\API-KEYS.txt ( + set /p API_KEYS=[Enter your API keys]: + echo %API_KEYS%> .user\API-KEYS.txt + echo API key written to file! +) + REM copy example prompt if not exist .user\prompt (md .user\prompt) @@ -35,8 +38,11 @@ REM wait 2 tick ping 127.0.0.1 -n 2 > NUL REM create input txt file -echo.> .user\input.txt -echo input file created! +if not exist .user\input.txt ( + echo.> .user\input.txt + echo input file created! +) + python web_ui/initial_file_creator.py