-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathai_chatbot.py
64 lines (52 loc) · 1.83 KB
/
ai_chatbot.py
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
"""
Install the Google AI Python SDK
$ pip install google-generativeai
See the getting started guide for more information:
https://ai.google.dev/gemini-api/docs/get-started/python
"""
import os
from google.generativeai.types import HarmCategory, HarmBlockThreshold
import google.generativeai as genai
genai.configure(api_key="AIzaSyAdhHba59C82frkiMmR0U1a5YzfFuYm8DM")
# Create the model
# See https://ai.google.dev/api/python/google/generativeai/GenerativeModel
generation_config = {
"temperature": 1,
"top_p": 0.95,
"top_k": 64,
"max_output_tokens": 8192,
"response_mime_type": "text/plain",
}
model = genai.GenerativeModel(
model_name="gemini-1.5-pro",
generation_config=generation_config,
safety_settings = {
HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE,
},
# See https://ai.google.dev/gemini-api/docs/safety-settings
system_instruction = "you are a character from gta 5 and now chat with me like that character\n, also do not reply to any questions that are not related to game, instead just say something like you think i am an idiot asking such obvious questions."
)
chat_session = model.start_chat(
history=[]
)
def ask():
i = input("You: ")
# add_his(i,"user")
return i
def get_response():
response = chat_session.send_message(ask())
response = response.text.strip()
# add_his(response,"model")
print("character: " + response)
return response
def add_his(content,role):
chat_session.history.append({
"role":role,
"parts":content
})
while input("int: ")!='0':
get_response().strip()
print(chat_session.history)