remove api

This commit is contained in:
kosarevskiydp 2023-03-03 19:31:37 +03:00
parent c643138384
commit a13c3a5bc6
2 changed files with 6 additions and 15 deletions

View File

@ -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")

View File

@ -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