Spaces:
Paused
Paused
Davide Fiocco
commited on
Commit
·
0068562
1
Parent(s):
8a6b093
update openai and streamlit_authenticator compatibility
Browse files- app.py +1 -1
- requirements.txt +4 -2
- utils.py +10 -11
app.py
CHANGED
|
@@ -11,7 +11,7 @@ authenticator = stauth.Authenticate(
|
|
| 11 |
|
| 12 |
st.title("Le risposte alle tue domande personali")
|
| 13 |
|
| 14 |
-
name, authentication_status, username = authenticator.login(
|
| 15 |
|
| 16 |
if authentication_status:
|
| 17 |
|
|
|
|
| 11 |
|
| 12 |
st.title("Le risposte alle tue domande personali")
|
| 13 |
|
| 14 |
+
name, authentication_status, username = authenticator.login()
|
| 15 |
|
| 16 |
if authentication_status:
|
| 17 |
|
requirements.txt
CHANGED
|
@@ -1,2 +1,4 @@
|
|
| 1 |
-
openai
|
| 2 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
openai==1.11.1
|
| 2 |
+
streamlit-authenticator==0.3.1
|
| 3 |
+
extra-streamlit-components==0.1.60
|
| 4 |
+
streamlit==1.31.0
|
utils.py
CHANGED
|
@@ -3,7 +3,9 @@ import json
|
|
| 3 |
import random
|
| 4 |
|
| 5 |
import streamlit as st
|
| 6 |
-
import
|
|
|
|
|
|
|
| 7 |
import logging
|
| 8 |
|
| 9 |
logger = logging.getLogger(__name__)
|
|
@@ -31,7 +33,7 @@ def get_system():
|
|
| 31 |
)
|
| 32 |
|
| 33 |
system = f"""Giuseppe è amnesico, ecco alcune informazioni su di lui: '{context}' .
|
| 34 |
-
Di seguito, Giuseppe farà domande di cui non sa o non ricorda la risposta. Cerca di aiutarlo con risposte concise.
|
| 35 |
"""
|
| 36 |
|
| 37 |
return system
|
|
@@ -41,17 +43,14 @@ def get_answer(input):
|
|
| 41 |
|
| 42 |
system_content = get_system()
|
| 43 |
|
| 44 |
-
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
| 45 |
|
| 46 |
-
response =
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
],
|
| 52 |
-
)
|
| 53 |
|
| 54 |
-
ans = response
|
| 55 |
|
| 56 |
logger.info(f"Q: {input} - A: {ans}")
|
| 57 |
|
|
|
|
| 3 |
import random
|
| 4 |
|
| 5 |
import streamlit as st
|
| 6 |
+
from openai import OpenAI
|
| 7 |
+
|
| 8 |
+
client = OpenAI(api_key=st.secrets["OPENAI_API_KEY"])
|
| 9 |
import logging
|
| 10 |
|
| 11 |
logger = logging.getLogger(__name__)
|
|
|
|
| 33 |
)
|
| 34 |
|
| 35 |
system = f"""Giuseppe è amnesico, ecco alcune informazioni su di lui: '{context}' .
|
| 36 |
+
Di seguito, Giuseppe farà domande di cui non sa o non ricorda la risposta. Cerca di aiutarlo con risposte concise, in un italiano perfetto.
|
| 37 |
"""
|
| 38 |
|
| 39 |
return system
|
|
|
|
| 43 |
|
| 44 |
system_content = get_system()
|
| 45 |
|
|
|
|
| 46 |
|
| 47 |
+
response = client.chat.completions.create(model="gpt-3.5-turbo",
|
| 48 |
+
messages=[
|
| 49 |
+
{"role": "system", "content": system_content},
|
| 50 |
+
{"role": "user", "content": input},
|
| 51 |
+
])
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
ans = response.choices[0].message.content
|
| 54 |
|
| 55 |
logger.info(f"Q: {input} - A: {ans}")
|
| 56 |
|