add ai settings
This commit is contained in:
parent
e301f4dff8
commit
12a4688ce6
7
chat.py
7
chat.py
@ -1,7 +1,8 @@
|
|||||||
from openai.error import AuthenticationError
|
from openai.error import AuthenticationError
|
||||||
from pathlib import Path
|
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
|
import streamlit as st
|
||||||
|
|
||||||
@ -30,9 +31,11 @@ def main() -> None:
|
|||||||
if st.button("Rerun"):
|
if st.button("Rerun"):
|
||||||
st.cache_data.clear()
|
st.cache_data.clear()
|
||||||
|
|
||||||
|
model, role = ai_settings()
|
||||||
|
|
||||||
if user_text:
|
if user_text:
|
||||||
try:
|
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):
|
if st.checkbox(label="Show Full API Response", value=False):
|
||||||
st.json(completion)
|
st.json(completion)
|
||||||
ai_content = completion.get("choices")[0].get("message").get("content")
|
ai_content = completion.get("choices")[0].get("message").get("content")
|
||||||
|
@ -3,9 +3,8 @@ from gtts import gTTS, lang
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
import streamlit as st
|
import streamlit as st
|
||||||
import openai
|
|
||||||
|
|
||||||
DEFAULT_SPEECH_LANG = "Russian"
|
DEFAULT_SPEECH_LANG = "English"
|
||||||
|
|
||||||
|
|
||||||
def get_dict_key(dictionary: Dict, value: Any) -> Optional[Any]:
|
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)
|
tts.write_to_fp(sound_file)
|
||||||
st.write("To hear the voice of AI, press the play button.")
|
st.write("To hear the voice of AI, press the play button.")
|
||||||
st.audio(sound_file)
|
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
|
|
Loading…
Reference in New Issue
Block a user