expose tunings.
This commit is contained in:
27
ai_client.py
27
ai_client.py
@@ -19,7 +19,14 @@ import file_cache
|
||||
import mcp_client
|
||||
|
||||
_provider: str = "gemini"
|
||||
_model: str = "gemini-2.0-flash"
|
||||
_model: str = "gemini-2.5-flash"
|
||||
_temperature: float = 0.0
|
||||
_max_tokens: int = 8192
|
||||
|
||||
def set_model_params(temp: float, max_tok: int):
|
||||
global _temperature, _max_tokens
|
||||
_temperature = temp
|
||||
_max_tokens = max_tok
|
||||
|
||||
_gemini_client = None
|
||||
_gemini_chat = None
|
||||
@@ -445,7 +452,13 @@ def _send_gemini(md_content: str, user_message: str, base_dir: str, file_items:
|
||||
_append_comms("OUT", "request", {"message": "[CONTEXT CHANGED] Rebuilding cache and chat session..."})
|
||||
|
||||
if not _gemini_chat:
|
||||
chat_config = types.GenerateContentConfig(system_instruction=sys_instr, tools=tools_decl)
|
||||
chat_config = types.GenerateContentConfig(
|
||||
system_instruction=sys_instr,
|
||||
tools=tools_decl,
|
||||
temperature=_temperature,
|
||||
max_output_tokens=_max_tokens,
|
||||
safety_settings=[types.SafetySetting(category="HARM_CATEGORY_DANGEROUS_CONTENT", threshold="BLOCK_ONLY_HIGH")]
|
||||
)
|
||||
try:
|
||||
# Gemini requires 1024 (Flash) or 4096 (Pro) tokens to cache.
|
||||
_gemini_cache = _gemini_client.caches.create(
|
||||
@@ -456,7 +469,12 @@ def _send_gemini(md_content: str, user_message: str, base_dir: str, file_items:
|
||||
ttl="3600s",
|
||||
)
|
||||
)
|
||||
chat_config = types.GenerateContentConfig(cached_content=_gemini_cache.name)
|
||||
chat_config = types.GenerateContentConfig(
|
||||
cached_content=_gemini_cache.name,
|
||||
temperature=_temperature,
|
||||
max_output_tokens=_max_tokens,
|
||||
safety_settings=[types.SafetySetting(category="HARM_CATEGORY_DANGEROUS_CONTENT", threshold="BLOCK_ONLY_HIGH")]
|
||||
)
|
||||
_append_comms("OUT", "request", {"message": f"[CACHE CREATED] {_gemini_cache.name}"})
|
||||
except Exception as e:
|
||||
# Fallback if under token limit or API error
|
||||
@@ -771,7 +789,8 @@ def _send_anthropic(md_content: str, user_message: str, base_dir: str, file_item
|
||||
|
||||
response = _anthropic_client.messages.create(
|
||||
model=_model,
|
||||
max_tokens=16384,
|
||||
max_tokens=_max_tokens,
|
||||
temperature=_temperature,
|
||||
system=system_blocks,
|
||||
tools=_build_anthropic_tools(),
|
||||
messages=_anthropic_history,
|
||||
|
||||
Reference in New Issue
Block a user