File size: 1,611 Bytes
0a9d067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from openai import OpenAI
from dotenv import load_dotenv
import os

# Ruta relativa al archivo .env
dotenv_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), ".env")

# Cargar el archivo .env desde la ruta especificada
load_dotenv(dotenv_path)

# Leer la clave API
API_KEY = os.getenv("OPENAI_API_KEY")

client = OpenAI(api_key=API_KEY)

def send_ChatGPT(emotion_face=None, emotion_text=None):
    # Verificar qué parámetros se proporcionaron
    if emotion_face and emotion_text:
        prompt = f"Act like you are a psychologist expert in emotions, i want recommendation of music, fun activities, actions, or advices if the image im receiving shows a {emotion_face} emotion and the text from a chat that the user provide us shows a {emotion_text} emotion"
    elif emotion_face:
        prompt = f"i want recommendation of music, fun activities, actions, or advices because im expiriencing a {emotion_face} emotion"
    elif emotion_text:
        prompt = f"i want recommendation of music, fun activities, actions, or advices because im expiriencing a {emotion_text} emotion"
    else:
        raise ValueError("At least one of 'emotion_face' or 'emotion_text' must be provided.")
    
    # Realizar la llamada al modelo
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[
            {"role": "user", "content": prompt}
        ],
        temperature=0.81,
        max_tokens=2000,
        top_p=1,
        frequency_penalty=0,
        presence_penalty=0
    )
    
    return response.choices[0].message.content