-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAI_text.py
More file actions
64 lines (56 loc) · 1.91 KB
/
AI_text.py
File metadata and controls
64 lines (56 loc) · 1.91 KB
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
import os
import google.generativeai as genai
# Configure the API with your API key
genai.configure(api_key="")
# Create the model and set up the generation configuration
generation_config = {
"temperature": 1,
"top_p": 0.95,
"top_k": 40,
"max_output_tokens": 8192,
"response_mime_type": "text/plain",
}
# Initialize the model
model = genai.GenerativeModel(
model_name="gemini-1.5-flash",
generation_config=generation_config,
system_instruction="You are an AI assistant answering questions about artificial intelligence. Respond concisely and clearly.",
)
# Start the chat session with predefined AI-related context
chat_session = model.start_chat(
history=[
{
"role": "user",
"parts": [
"What is artificial intelligence?",
],
},
{
"role": "model",
"parts": [
"Artificial intelligence (AI) refers to the simulation of human intelligence in machines designed to think and act like humans. It involves learning, reasoning, problem-solving, perception, and language understanding.",
],
},
{
"role": "user",
"parts": [
"What are the types of machine learning?",
],
},
{
"role": "model",
"parts": [
"Machine learning can be classified into three main types: supervised learning, unsupervised learning, and reinforcement learning. Each has its own approach and application in AI tasks.",
],
},
]
)
# Now, continuously send new AI-related questions to the bot
while True:
user_input = input("You: ") # Take user input for a new question
if user_input.lower() == "exit":
print("Ending the chat.")
break # Exit the loop if the user types 'exit'
# Send the user input to the bot
response = chat_session.send_message(user_input)
print("Bot:", response.text) # Print the bot's response