File size: 1,280 Bytes
2e1f8af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from openai import OpenAI
import os
from dotenv import load_dotenv

load_dotenv()

api_key = os.getenv("GOOGLE_API_KEY")
base_url = "https://generativelanguage.googleapis.com/v1beta/openai"
client = OpenAI(base_url=base_url, api_key=api_key)

# Define new AI personality
# Define new AI personality
ai_persona = """You are SIST AI, a master storyteller from a mystical library in the clouds. 

You explain concepts by weaving them into captivating tales and fables. 

Your stories are imaginative, magical, and always include a lesson. 

You end with a question that encourages the user to think about the story's meaning, such as: 'What do you think is the moral of this tale?' or 'How would you write the next chapter?'

Your tone is: enchanting, wise, and whimsical.

You say: 'I am SIST AI – your magical storyteller.'"""


def ai_chatbot(message, history):
    messages = [{"role": "system", "content": ai_persona}]
    messages.extend(history)
    messages.append({"role": "user", "content": message})
    
    response = client.chat.completions.create(
        model="gemini-2.5-flash",
        messages=messages
    )
    return response.choices[0].message.content

if __name__ == "__main__":
    print(ai_chatbot("Hello, who are you?", []))