File size: 1,435 Bytes
dcf6f0c
4bed6fd
b39f806
 
46152dd
0068562
 
 
feabab6
 
 
be64225
4bed6fd
b37eabc
53e30d5
dcf6f0c
5d92ad1
d8d8f1a
5d92ad1
dcf6f0c
 
 
34129b5
 
 
7bdd50b
5d92ad1
d8d8f1a
 
 
 
f74ef39
34129b5
dcf6f0c
0e93022
0068562
53e30d5
21b7e19
53e30d5
21b7e19
 
 
 
53e30d5
46152dd
 
0068562
 
 
 
 
46152dd
0068562
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
import datetime
import json
import random

import streamlit as st
from openai import OpenAI

client = OpenAI(api_key=st.secrets["OPENAI_API_KEY"])
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"""Giuseppe è amnesico, ecco alcune informazioni su di lui: '{context}' . 
    Di seguito, Giuseppe farà domande di cui non sa o non ricorda la risposta. Cerca di aiutarlo con risposte concise, in un italiano perfetto.
    """

    return system


def get_answer(input):

    system_content = get_system()


    response = client.chat.completions.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