Commit fb434ec
src/llm/models.py
@@ -1,6 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-from typing import Any
from openai import DefaultAsyncHttpxClient
from pyrogram.types import Message
@@ -59,24 +58,17 @@ def get_model_config_with_contexts(model_type: str, contexts: list[dict], force_
}
-def hooks(client: dict, completions: dict, message_info: dict | None = None, *, for_tools: bool = False):
- openrouter_hook(client, completions, for_tools=for_tools)
+def hooks(client: dict, completions: dict, message_info: dict | None = None):
+ openrouter_hook(client, completions)
helicone_hook(client, message_info)
-def openrouter_hook(client: dict, completions: dict, *, for_tools: bool = False) -> None:
+def openrouter_hook(client: dict, completions: dict) -> None:
"""Add special parameters for OpenRouter."""
if "openrouter" not in client["base_url"]:
return
- params: dict[str, Any] = {"extra_body": {"provider": {"sort": "throughput"}}}
- if for_tools:
- if models := [x.strip() for x in GPT.FALLBACK_TOOLS_MODELS.split(",") if x.strip()]:
- params["extra_body"] |= {"models": models}
- else:
- params["extra_body"] |= {"include_reasoning": True}
- if models := [x.strip() for x in GPT.FALLBACK_MODELS.split(",") if x.strip()]:
- params["extra_body"] |= {"models": models}
- completions |= params
+ if models := [x.strip() for x in GPT.FALLBACK_MODELS.split(",") if x.strip()]:
+ completions["extra_body"] = {"models": models}
def helicone_hook(client: dict, message_info: dict | None) -> None:
src/llm/tools.py
@@ -144,7 +144,7 @@ async def merge_tools_response(config: dict, **kwargs) -> tuple[dict, dict]:
}
tool_completions = add_tools(tool_completions)
tool_client = {k: v for k, v in config["client"].items() if k != "http_client"} | {"base_url": GPT.TOOLS_BASE_URL, "api_key": GPT.TOOLS_API_KEY}
- hooks(tool_client, tool_completions, for_tools=True)
+ hooks(tool_client, tool_completions)
tools_config = {
"friendly_name": config["friendly_name"],
"client": tool_client,
src/config.py
@@ -143,7 +143,6 @@ class GPT: # see `llm/README.md`
TOOLS_MODEL = os.getenv("GPT_TOOLS_MODEL", "gpt-4o-mini") # this model should be fast and cheap
# comma separated fallback models for OpenRouter (e.g. openai/gpt-4o,anthropic/claude-3.5-sonnet)
FALLBACK_MODELS = os.getenv("GPT_FALLBACK_MODELS", "")
- FALLBACK_TOOLS_MODELS = os.getenv("GPT_FALLBACK_TOOLS_MODELS", "") # comma separated fallback tool models for OpenRouter
TEXT_MODEL_NAME = os.getenv("GPT_TEXT_MODEL_NAME", "GPT-4o") # custom name
IMAGE_MODEL_NAME = os.getenv("GPT_IMAGE_MODEL_NAME", "GPT-4o")
VIDEO_MODEL_NAME = os.getenv("GPT_VIDEO_MODEL_NAME", "GLM-4V-Plus")