-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_gemini
59 lines (48 loc) · 1.36 KB
/
test_gemini
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
"""
Install the Google AI Python SDK
$ pip install google-generativeai
"""
import os
import google.generativeai as genai
from dotenv import load_dotenv
load_dotenv(".env.local")
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
def upload_to_gemini(path, mime_type=None):
"""Uploads the given file to Gemini.
See https://ai.google.dev/gemini-api/docs/prompting_with_media
"""
file = genai.upload_file(path, mime_type=mime_type)
print(f"Uploaded file '{file.display_name}' as: {file.uri}")
return file
# Create the model
generation_config = {
"temperature": 0.9,
"top_p": 0.95,
"top_k": 64,
"max_output_tokens": 1024,
"response_mime_type": "text/plain",
}
model = genai.GenerativeModel(
model_name="gemini-1.5-flash",
generation_config=generation_config,
# safety_settings = Adjust safety settings
# See https://ai.google.dev/gemini-api/docs/safety-settings
)
# TODO Make these files available on the local file system
# You may need to update the file paths
files = [
upload_to_gemini("test_valo.webp", mime_type="image/webp"),
]
chat_session = model.start_chat(
history=[
{
"role": "user",
"parts": [
files[0],
"What is going on in this valorant moment? I am confused.",
],
},
]
)
response = chat_session.send_message("I am confused. What is going on in this valorant moment?")
print(response.text)