import random
|
import google.generativeai as genai
|
from auto_media_publisher.config.conf_base import GOOGLE_API_KEY,GOOGLE_MODEL
|
from auto_media_publisher.config.conf_base import GOOGLE_GEMINI_TEMPERATURE_MIN,GOOGLE_GEMINI_TEMPERATURE_MAX,GOOGLE_GEMINI_TOPN_MIN,GOOGLE_GEMINI_TOPN_MAX
|
|
def init_gemini_model(proxy=None):
|
if isinstance(proxy, str) and proxy.strip().lower().startswith(('http://', 'https://')):
|
import os
|
os.environ['HTTP_PROXY'] = proxy
|
os.environ['HTTPS_PROXY'] = proxy
|
|
genai.configure(api_key=GOOGLE_API_KEY)
|
temperature = round(random.uniform(GOOGLE_GEMINI_TEMPERATURE_MIN, GOOGLE_GEMINI_TEMPERATURE_MAX), 2)
|
top_n = round(random.uniform(GOOGLE_GEMINI_TOPN_MIN, GOOGLE_GEMINI_TOPN_MAX), 2)
|
model = genai.GenerativeModel(GOOGLE_MODEL,
|
generation_config=genai.types.GenerationConfig(
|
temperature=temperature,
|
top_p=top_n,
|
top_k=random.choice([40, 50, 80, 100])
|
)
|
)
|
return model
|