From a13c3a5bc677d093f1d48954f825645751d8a0d8 Mon Sep 17 00:00:00 2001 From: kosarevskiydp Date: Fri, 3 Mar 2023 19:31:37 +0300 Subject: [PATCH] remove api --- chat.py | 9 +++------ src/utils/helpers.py | 12 +++--------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/chat.py b/chat.py index 472fac1..f585f8f 100644 --- a/chat.py +++ b/chat.py @@ -1,7 +1,7 @@ from openai.error import AuthenticationError from pathlib import Path -from src.utils.helpers import api_key_checker, send_ai_request, lang_selector, speech_speed_radio, show_player +from src.utils.helpers import send_ai_request, lang_selector, speech_speed_radio, show_player import streamlit as st @@ -26,16 +26,13 @@ st.markdown("---") def main() -> None: - api_key = st.text_input(label="Input OpenAI API key:") - api_key = api_key_checker(api_key) - user_text = st.text_area(label="Start your conversation with AI:") if st.button("Rerun"): st.cache_data.clear() - if api_key and user_text: + if user_text: try: - completion = send_ai_request(api_key, user_text) + completion = send_ai_request(user_text) if st.checkbox(label="Show Full API Response", value=False): st.json(completion) ai_content = completion.get("choices")[0].get("message").get("content") diff --git a/src/utils/helpers.py b/src/utils/helpers.py index 78299d7..f72a194 100644 --- a/src/utils/helpers.py +++ b/src/utils/helpers.py @@ -47,12 +47,12 @@ def show_player(ai_content: str, lang_code: str, is_speech_slow: bool) -> None: @st.cache_data() -# @st.cache_data(suppress_st_warning=True) -def send_ai_request(api_key: str, user_text: str, ) -> Dict: - openai.api_key = api_key +def send_ai_request(user_text: str, ) -> Dict: + openai.api_key = st.secrets.api_credentials.api_key completion = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[ + {"role": "system", "content": "You are a helpful assistant."}, { "role": "user", "content": user_text @@ -60,9 +60,3 @@ def send_ai_request(api_key: str, user_text: str, ) -> Dict: ] ) return completion - - -def api_key_checker(api_key: str) -> str: - if api_key == "ZVER": - return st.secrets.api_credentials.api_key - return api_key