From 12a4688ce607f46994b6d0178ff254e547234ccd Mon Sep 17 00:00:00 2001 From: kosarevskiydp Date: Mon, 6 Mar 2023 16:27:43 +0300 Subject: [PATCH] add ai settings --- chat.py | 7 +++++-- src/utils/{helpers.py => tts.py} | 19 +------------------ 2 files changed, 6 insertions(+), 20 deletions(-) rename src/utils/{helpers.py => tts.py} (71%) diff --git a/chat.py b/chat.py index f585f8f..00cf977 100644 --- a/chat.py +++ b/chat.py @@ -1,7 +1,8 @@ from openai.error import AuthenticationError from pathlib import Path -from src.utils.helpers import send_ai_request, lang_selector, speech_speed_radio, show_player +from src.utils.ai import ai_settings, send_ai_request +from src.utils.tts import lang_selector, speech_speed_radio, show_player import streamlit as st @@ -30,9 +31,11 @@ def main() -> None: if st.button("Rerun"): st.cache_data.clear() + model, role = ai_settings() + if user_text: try: - completion = send_ai_request(user_text) + completion = send_ai_request(user_text, model, role) 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/tts.py similarity index 71% rename from src/utils/helpers.py rename to src/utils/tts.py index b04471d..4df0f97 100644 --- a/src/utils/helpers.py +++ b/src/utils/tts.py @@ -3,9 +3,8 @@ from gtts import gTTS, lang from io import BytesIO import streamlit as st -import openai -DEFAULT_SPEECH_LANG = "Russian" +DEFAULT_SPEECH_LANG = "English" def get_dict_key(dictionary: Dict, value: Any) -> Optional[Any]: @@ -44,19 +43,3 @@ def show_player(ai_content: str, lang_code: str, is_speech_slow: bool) -> None: tts.write_to_fp(sound_file) st.write("To hear the voice of AI, press the play button.") st.audio(sound_file) - - -@st.cache_data() -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 - } - ] - ) - return completion