Spaces:
Paused
Paused
File size: 1,459 Bytes
dcf6f0c 4bed6fd b39f806 46152dd 21b7e19 feabab6 be64225 4bed6fd b37eabc 53e30d5 dcf6f0c 5d92ad1 d8d8f1a 5d92ad1 dcf6f0c 34129b5 7bdd50b 5d92ad1 d8d8f1a f74ef39 34129b5 dcf6f0c 53e30d5 21b7e19 53e30d5 21b7e19 53e30d5 46152dd 1630497 46152dd 53e30d5 46152dd 53e30d5 4d5fcf9 feabab6 4d5fcf9 feabab6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
import datetime
import json
import random
import streamlit as st
import openai
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
def get_system():
BIRTHYEAR = 1952
BIRTHMONTH = 5
OTHERBIRTHYEAR = 1984
now = datetime.datetime.now()
with open("context.json") as f:
context = (
json.load(f)["info"]
.replace("[YEAR]", str(now.year))
.replace("[TODAY]", f"{now:%d-%m-%Y}")
.replace("[BIRTHYEAR]", str(BIRTHYEAR))
.replace(
"[AGE]",
str((now - datetime.datetime(BIRTHYEAR, BIRTHMONTH, 1)).days // 365),
)
.replace("[OTHERAGE]", str(now.year - OTHERBIRTHYEAR))
)
system = f"""Il mio nome utente è Giuseppe, ed ecco alcune informazioni su di me: '{context}' .
Di seguito, ti farò alcune domande di cui non ricordo la risposta, perché sono amnesico, e tu dovrai rispondermi in modo conciso.
"""
return system
def get_answer(input):
system_content = get_system()
openai.api_key = st.secrets["OPENAI_API_KEY"]
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": system_content},
{"role": "user", "content": input},
],
)
ans = response["choices"][0]["message"]["content"]
logger.info(f"Q: {input} - A: {ans}")
return ans
|