File size: 2,642 Bytes
4e6be8b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'''from openai import OpenAI

from dotenv import load_dotenv

import os

from prompts import ai_motivational_speaker



load_dotenv()

api_key = os.getenv("GEMINI_API_KEY")

model="gemini-2.5-flash-lite"

base_url="https://generativelanguage-googleapis.com/v1beta/openai/" 



client= OpenAI(base_url=base_url, api_key=api_key)



ai_motivational_speaker = ai_motivational_speaker

'''
'''

def get_response(message, history):

    messages=({"role":"system","content":ai_motivational_speaker})

    messages.extend(history)

    messages.append({"role":"user","content":message})

    response = client.chat.completions.create(

    model=model,

    messages = messages)



    ai_response = response.choices[0].message.content

    return ai_response



print(get_response("   hh  h   hhh  h  ", []))*'''
'''

def get_response(message, history):

    # Start messages with the system prompt to set the AI's persona

    messages = [{"role": "system", "content": ai_motivational_speaker}]



    # Extend the messages list with the existing chat history

    messages.extend(history)



    # Add the current user's message to the conversation

    messages.append({"role": "user", "content": message})



    # Call the OpenAI API to get a completion from the Gemini model

    response = client.chat.completions.create(model="gemini-2.5-flash", messages=messages)

    # Extract the AI's response content

    ai_response = response.choices[0].message.content

    

    # Return the AI's generated response

    return ai_response



# Main execution block to test the chatbot function

if __name__ == "__main__":

    # Print a test conversation with the chatbot

    print(get_response("Hello, Caramel AI! Can you tell me what AI is?", []))'''


from openai import OpenAI
from dotenv import load_dotenv
import os
from prompts import ai_motivational_speaker

load_dotenv()
api_key = os.getenv("GEMINI_API_KEY")
model ="gemini-2.5-flash-lite"
base_url = "https://generativelanguage.googleapis.com/v1beta/openai/"

client = OpenAI(api_key=api_key, base_url=base_url)

ai_motivational_speaker = ai_motivational_speaker


def get_response(message, history):
    messages = [{"role": "system", "content": ai_motivational_speaker}] 
    messages.extend(history)
    messages.append({"role": "user", "content": message})
    response  = client.chat.completions.create(
        model=model,
        messages=messages
    )
    Ai_response = response.choices[0].message.content
    return Ai_response

#if __name__ == "__main__":
   
   # print(get_response("Hello, Caramel AI! Can you tell me what AI is?", []))