diff --git a/requirements.txt b/requirements.txt index baf82d8..94b6737 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ streamlit-chat==0.0.2.2 streamlit_option_menu==0.3.2 openai==0.27.4 gtts==2.3.1 -pip==23.0.1 +pip==23.1 bokeh==2.4.2 streamlit-bokeh-events==0.1.2 watchdog==3.0.0 diff --git a/requirements_dev.txt b/requirements_dev.txt index 09e499a..14d17e9 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,4 +1,4 @@ -pytest==7.3.0 +pytest==7.3.1 ruff==0.0.261 pre_commit==3.2.2 pytest-cov==4.0.0 diff --git a/src/utils/agi/chat_gpt.py b/src/utils/agi/chat_gpt.py index 7326394..87d35ea 100644 --- a/src/utils/agi/chat_gpt.py +++ b/src/utils/agi/chat_gpt.py @@ -1,5 +1,5 @@ import logging -from typing import List +from typing import List # NOQA: UP035 import openai import streamlit as st @@ -7,7 +7,10 @@ import streamlit as st @st.cache_data() def create_gpt_completion(ai_model: str, messages: List[dict]) -> dict: - openai.api_key = st.secrets.api_credentials.api_key + try: + openai.api_key = st.secrets.api_credentials.api_key + except (KeyError, AttributeError): + st.error(st.session_state.locale.empty_api_handler) logging.info(f"{messages=}") completion = openai.ChatCompletion.create( model=ai_model, diff --git a/src/utils/lang.py b/src/utils/lang.py index 3f9b6d0..5af79bc 100644 --- a/src/utils/lang.py +++ b/src/utils/lang.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -from typing import List +from typing import List # NOQA: UP035 @dataclass @@ -36,6 +36,7 @@ class Locale: footer_channel: str responsibility_denial: str donates_info: str + empty_api_handler: str AI_ROLE_OPTIONS_EN = [ @@ -71,6 +72,9 @@ AI_ROLE_OPTIONS_RU = [ "переводчик корпоративного жаргона на простой русский", ] +readme_url = "https://github.com/dKosarevsky/AI-Talks#readme" +ai_talks_url = "https://ai-talks.streamlit.app/" + en = Locale( ai_role_options=AI_ROLE_OPTIONS_EN, ai_role_prefix="You are a female", @@ -113,6 +117,10 @@ en = Locale( This allows you to provide access to communication with AI for all users. Support us for joint development and interaction with the intelligence of the future! """, + empty_api_handler=f""" + API key not found. Create `.streamlit/secrets.toml` with your API key. + See [README.md]({readme_url}) for instructions or use the original [AI Talks]({ai_talks_url}). + """, ) ru = Locale( ai_role_options=AI_ROLE_OPTIONS_RU, @@ -157,4 +165,8 @@ ru = Locale( Это позволяет обеспечить доступ к общению с ИИ для всех желающих пользователей. Поддержите нас для совместного развития и взаимодействия с интеллектом будущего! """, + empty_api_handler=f""" + Ключ API не найден. Создайте `.streamlit/secrets.toml` с вашим ключом API. + Инструкции см. в [README.md]({readme_url}) или используйте оригинальный [AI Talks]({ai_talks_url}). + """, )