-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsynth.py
More file actions
39 lines (31 loc) · 1.26 KB
/
Copy pathsynth.py
File metadata and controls
39 lines (31 loc) · 1.26 KB
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
import google.generativeai as genai
import os
class GeminiGenerator:
def __init__(self, api_key, system_instruction=None):
"""Initializes the GeminiGenerator."""
if not api_key:
raise ValueError("API key not provided")
genai.configure(api_key=api_key)
self.model = genai.GenerativeModel(
model_name='gemini-2.5-pro',
system_instruction=system_instruction
)
def generate(self, prompt):
"""Generates text from a given prompt."""
response = self.model.generate_content(prompt)
return response.text
if __name__ == "__main__":
# Fetch the API key from an environment variable
api_key = os.getenv("GOOGLE_API_KEY")
# Ensure the API key is set
if not api_key:
raise ValueError("GOOGLE_API_KEY environment variable not set")
# Add a system instruction
system_instruction = "You are a helpful assistant that provides concise and accurate answers."
# Create an instance of the generator
generator = GeminiGenerator(api_key=api_key, system_instruction=system_instruction)
# Get a prompt from the user
prompting = input("Prompt: ")
# Generate and print the text
generated_text = generator.generate(prompting)
print(generated_text)