-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
42 lines (38 loc) · 1.38 KB
/
models.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
"""Load models to use them as a narrator and a common-sense oracle in the PAYADOR pipeline."""
import google.generativeai as genai
class GeminiModel():
def __init__ (self, api_key_file:str) -> None:
""""Initialize the Gemini model using an API key."""
self.safety_settings = [
{
"category": "HARM_CATEGORY_DANGEROUS",
"threshold": "BLOCK_NONE",
},
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "BLOCK_NONE",
},
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"threshold": "BLOCK_NONE",
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "BLOCK_NONE",
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "BLOCK_NONE",
},
]
genai.configure(api_key=get_api_key(api_key_file))
self.model = genai.GenerativeModel("gemini-pro")
def prompt_model(self,prompt: str) -> str:
"""Prompt the Gemini model."""
return self.model.generate_content(prompt, safety_settings=self.safety_settings).text
def get_api_key(path: str) -> str:
"""Load an API key from path."""
key = ""
with open(path) as f:
key = f.readline()
return key