-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgemini_client.py
32 lines (24 loc) · 1 KB
/
gemini_client.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
import google.generativeai as genai
import os
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
# Configure API key
key = GEMINI_API_KEY
genai.configure(api_key=key)
model = genai.GenerativeModel('gemini-pro')
def generate_insight(count, runners, pitch_type):
prompt = f"""You are a fun baseball commentator explaining strategy to a first-time fan.
**Situation**:
- Count: {count}
- Runners: {runners}
- Pitch thrown: {pitch_type}
**Task**:
Explain why this pitch was chosen in 1 short sentence. Use a creative analogy from everyday life (e.g., pizza, video games, weather).
**Rules**:
- No technical terms like "spin rate", "exit velocity", or "WHIP".
- Focus on the pitcher's goal (e.g., strikeout, ground ball).
- Make it relatable and fun!
Example: "The pitcher threw a curveball here — like a rollercoaster suddenly dropping, it fools the batter into swinging too early!"""
return model.generate_content(prompt).text