-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgemini_client.py
More file actions
63 lines (50 loc) ยท 2.27 KB
/
gemini_client.py
File metadata and controls
63 lines (50 loc) ยท 2.27 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
from dotenv import load_dotenv
from google import genai
# .env ํ์ผ์์ ํ๊ฒฝ ๋ณ์๋ฅผ ๋ก๋ํฉ๋๋ค.
load_dotenv()
PROMPT = """
์ด ์ง์ ์ง์ง.... ์ ๊ฐ์ด ์ด๋ฐ์๋ ํํน ํ ์ ์๋ ๋ฉํธ๋ก ๊ตฌ์ฑํ๊ณ ์์์ ํ๋ณดํ๋ ๋ฆด์ค ๋๋ณธ 100๊ธ์๋ก ๋ฑ ํ๊ธ๋ง ์ค ์ํฉ ์ค๋ช
ํ๋ ๊ดํธ๋ ๋นผ์ค. ํ ์ค์ ํ ๋ฌธ์ฅ์ฉ ์ธ ์ ์๋๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ง๋ค์ด์ฃผ๊ณ , ํ ์ค์ ์ต๋ 20๊ธ์ ์ ๋๋ก
๊ฐ๊ฒ ์ด๋ฆ: <business_name>
๊ฐ๊ฒ ์ค๋ช
: <description>
๊ฐ๊ฒ ๋ถ์๊ธฐ: <mode>
"""
class GeminiClient:
def __init__(self):
"""
GeminiClient๋ฅผ ์ด๊ธฐํํ๊ณ API ํค ์ค์ ๋ฐ ๋ชจ๋ธ์ ์ค๋นํฉ๋๋ค.
"""
# 1. ํ๊ฒฝ ๋ณ์์์ API ํค๋ฅผ ์ฝ์ด์ต๋๋ค.
api_key = os.getenv('GEMINI_API_KEY')
if not api_key:
raise ValueError("GEMINI_API_KEY ํ๊ฒฝ ๋ณ์๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.")
# 2. google-genai ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ API ํค๋ฅผ ์ค์ ํฉ๋๋ค.
self.model = genai.Client(api_key=api_key)
def generate_script(self, business_name: str, description: str, mode: str) -> str:
prompt = PROMPT.replace("<business_name>", business_name)
prompt = prompt.replace("<description>", description)
prompt = prompt.replace("<mode>", mode)
response = self.model.models.generate_content(
model='gemini-2.5-flash', contents=[prompt])
return response.text
if __name__ == '__main__':
# ๐ก ํ
์คํธ ์ , .env ํ์ผ์ ์์ฑํ๊ณ ์๋ ํ์์ผ๋ก ํค๋ฅผ ์ ์ฅํ๊ฑฐ๋
# ์
ธ ํ๊ฒฝ์์ `export GEMINI_API_KEY="your_api_key_here"`๋ฅผ ์คํํด์ผ ํฉ๋๋ค.
# GEMINI_API_KEY="์ฌ๋ฌ๋ถ์์ค์ APIํค"
try:
gemini_client = GeminiClient()
# ์์ ๋ฐ์ดํฐ
business_name = "๋งค์ฝค๋๊น์ค"
description = "์๋กญ๊ฒ ์คํํ ๋๊น์ค ๋ง์ง, ํน๋ณํ ๋งค์ฝค ์์ค๊ฐ ์ผํ์
๋๋ค."
mode = "ํ๊ธฐ์ฐฌ"
script = gemini_client.generate_script(
business_name=business_name,
description=description,
mode=mode
)
if script:
print("๐ค ์์ฑ๋ ๋ฆด์ค ๋๋ณธ:")
print("--------------------")
print(script)
except ValueError as e:
print(e)