-
Notifications
You must be signed in to change notification settings - Fork 0
/
gemini.py
24 lines (19 loc) · 880 Bytes
/
gemini.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
from PIL import Image
import google.generativeai as genai
def load_gemini_pro_model():
gemini_pro_model = genai.GenerativeModel("gemini-pro")
return gemini_pro_model
# get response from Gemini-Pro-Vision model - image/text to text
def gemini_pro_vision_response(prompt, image):
gemini_pro_vision_model = genai.GenerativeModel("gemini-pro-vision")
response = gemini_pro_vision_model.generate_content([prompt, image])
result = response.text
return result
# get response from embeddings model - text to embeddings
def embeddings_model_response(input_text):
embedding_model = "models/embedding-001"
embedding = genai.embed_content(model=embedding_model,
content=input_text,
task_type="retrieval_document")
embedding_list = embedding["embedding"]
return embedding_list