remove api
This commit is contained in:
parent
c643138384
commit
a13c3a5bc6
9
chat.py
9
chat.py
@ -1,7 +1,7 @@
|
|||||||
from openai.error import AuthenticationError
|
from openai.error import AuthenticationError
|
||||||
from pathlib import Path
|
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
|
import streamlit as st
|
||||||
|
|
||||||
@ -26,16 +26,13 @@ st.markdown("---")
|
|||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
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:")
|
user_text = st.text_area(label="Start your conversation with AI:")
|
||||||
if st.button("Rerun"):
|
if st.button("Rerun"):
|
||||||
st.cache_data.clear()
|
st.cache_data.clear()
|
||||||
|
|
||||||
if api_key and user_text:
|
if user_text:
|
||||||
try:
|
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):
|
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")
|
||||||
|
@ -47,12 +47,12 @@ def show_player(ai_content: str, lang_code: str, is_speech_slow: bool) -> None:
|
|||||||
|
|
||||||
|
|
||||||
@st.cache_data()
|
@st.cache_data()
|
||||||
# @st.cache_data(suppress_st_warning=True)
|
def send_ai_request(user_text: str, ) -> Dict:
|
||||||
def send_ai_request(api_key: str, user_text: str, ) -> Dict:
|
openai.api_key = st.secrets.api_credentials.api_key
|
||||||
openai.api_key = api_key
|
|
||||||
completion = openai.ChatCompletion.create(
|
completion = openai.ChatCompletion.create(
|
||||||
model="gpt-3.5-turbo",
|
model="gpt-3.5-turbo",
|
||||||
messages=[
|
messages=[
|
||||||
|
{"role": "system", "content": "You are a helpful assistant."},
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"content": user_text
|
"content": user_text
|
||||||
@ -60,9 +60,3 @@ def send_ai_request(api_key: str, user_text: str, ) -> Dict:
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
return completion
|
return completion
|
||||||
|
|
||||||
|
|
||||||
def api_key_checker(api_key: str) -> str:
|
|
||||||
if api_key == "ZVER":
|
|
||||||
return st.secrets.api_credentials.api_key
|
|
||||||
return api_key
|
|
||||||
|
Loading…
Reference in New Issue
Block a user