-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgemini_api.py
41 lines (26 loc) · 996 Bytes
/
gemini_api.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
#!/usr/bin/python3
"""
Class MyGeminiApi is responsible for the gemini api
"""
import google.generativeai as genai
from writePrompt import write_file
from util import Util
genai.configure(api_key= "your_gemini_api_key")
util = Util()
class MyGeminiApi():
"""
Class MyGeminiApi is responsible for the gemini api
"""
def __init__(self):
self.generativeModel = genai.GenerativeModel('gemini-pro')
def generate(self, text):
response = self.generativeModel.generate_content(text)
title = self.generativeModel.generate_content(
"generate a title and the title should not be more than 5 words in text for " + response.text
)
promptTitle = util.replace_whitespace_with_underscore(title.text)
if "**" in promptTitle:
promptTitle = promptTitle.replace("**", "")
util.write_file(promptTitle + ".md", response.text)
responseText = response.text
return responseText