checkpoint: massive refactor
This commit is contained in:
34
gemini.py
34
gemini.py
@@ -8,28 +8,28 @@ _client = None
|
||||
_chat = None
|
||||
|
||||
def _load_key() -> str:
|
||||
with open("credentials.toml", "rb") as f:
|
||||
return tomllib.load(f)["gemini"]["api_key"]
|
||||
with open("credentials.toml", "rb") as f:
|
||||
return tomllib.load(f)["gemini"]["api_key"]
|
||||
|
||||
def _ensure_client():
|
||||
global _client
|
||||
if _client is None:
|
||||
_client = genai.Client(api_key=_load_key())
|
||||
global _client
|
||||
if _client is None:
|
||||
_client = genai.Client(api_key=_load_key())
|
||||
|
||||
def _ensure_chat():
|
||||
global _chat
|
||||
if _chat is None:
|
||||
_ensure_client()
|
||||
_chat = _client.chats.create(model="gemini-2.0-flash")
|
||||
global _chat
|
||||
if _chat is None:
|
||||
_ensure_client()
|
||||
_chat = _client.chats.create(model="gemini-2.0-flash")
|
||||
|
||||
def send(md_content: str, user_message: str) -> str:
|
||||
global _chat
|
||||
_ensure_chat()
|
||||
full_message = f"<context>\n{md_content}\n</context>\n\n{user_message}"
|
||||
response = _chat.send_message(full_message)
|
||||
return response.text
|
||||
global _chat
|
||||
_ensure_chat()
|
||||
full_message = f"<context>\n{md_content}\n</context>\n\n{user_message}"
|
||||
response = _chat.send_message(full_message)
|
||||
return response.text
|
||||
|
||||
def reset_session():
|
||||
global _client, _chat
|
||||
_client = None
|
||||
_chat = None
|
||||
global _client, _chat
|
||||
_client = None
|
||||
_chat = None
|
||||
|
||||
Reference in New Issue
Block a user