File size: 741 Bytes
7d627b3
 
 
 
 
 
d0ca99c
7d627b3
d0ca99c
7d627b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import chainlit as cl
import os
import google.generativeai as genai


# Configure Gemini
GOOGLE_API_KEY = os.environ.get("GEMINI_API_KEY")
if not GOOGLE_API_KEY:
    raise ValueError("GEMINI_API_KEY not found")

genai.configure(api_key=GOOGLE_API_KEY)

# Initialize the Gemini Flash model
model = genai.GenerativeModel('gemini-2.0-flash')

@cl.on_chat_start
async def start_chat():
    await cl.Message(
        content="Hello! I'm a chatbot powered by Gemini Flash. How can I help you today?"
    ).send()

@cl.on_message
async def main(message: cl.Message):
    # Generate response using Gemini
    response = model.generate_content(message.content)
    
    # Send response
    await cl.Message(
        content=response.text
    ).send()