From d0790dcb22ca2fc6612e0030cebf5c0d3d33662a Mon Sep 17 00:00:00 2001 From: 9qeklajc Date: Wed, 3 Dec 2025 19:36:06 +0100 Subject: [PATCH] use openrouter model matching --- routstr/upstream/gemini.py | 72 ++++---------------------------------- 1 file changed, 7 insertions(+), 65 deletions(-) diff --git a/routstr/upstream/gemini.py b/routstr/upstream/gemini.py index 0b3acc46..21283386 100644 --- a/routstr/upstream/gemini.py +++ b/routstr/upstream/gemini.py @@ -67,8 +67,6 @@ class GeminiUpstreamProvider(BaseUpstreamProvider): def transform_model_name(self, model_id: str) -> str: return model_id.removeprefix("gemini/") - - async def forward_request( self, request: Request, @@ -259,72 +257,16 @@ class GeminiUpstreamProvider(BaseUpstreamProvider): model_obj, ) - - - async def fetch_models(self) -> list[Model]: - from ..payment.models import Architecture, Model, Pricing, TopProvider - + async def _fetch_provider_models(self) -> dict: + """Fetch models from Gemini API.""" try: models_data = await self.client.list_models() - models_list = [] - for model_data in models_data: - model_id = model_data.get("id", "") - if not model_id: - continue - - display_name = model_id - description = f"Google {display_name} model" - - context_length = 128000 - output_token_limit = 8192 - - pricing_config = Pricing( - prompt=0.000003, - completion=0.000003, - request=0.0, - image=0.0, - web_search=0.0, - internal_reasoning=0.0, - max_prompt_cost=0.001, - max_completion_cost=0.001, - max_cost=0.001, - ) - - models_list.append( - Model( - id=model_id, - name=display_name, - created=0, - description=description, - context_length=context_length, - architecture=Architecture( - modality="text", - input_modalities=["text"], - output_modalities=["text"], - tokenizer="gemini", - instruct_type=None, - ), - pricing=pricing_config, - sats_pricing=None, - per_request_limits=None, - top_provider=TopProvider( - context_length=context_length, - max_completion_tokens=output_token_limit, - is_moderated=True, - ), - enabled=True, - upstream_provider_id=None, - canonical_slug=None, - ) - ) - - logger.info( - f"Fetched {len(models_list)} models from Gemini", - extra={"model_count": len(models_list), "base_url": self.base_url}, - ) - return models_list + for model in models_data: + if "id" in model and model["id"].startswith("models/"): + model["id"] = model["id"].removeprefix("models/") + return {"data": models_data} except Exception as e: logger.error( f"Failed to fetch models from Gemini API: {e}", @@ -334,7 +276,7 @@ class GeminiUpstreamProvider(BaseUpstreamProvider): "base_url": self.base_url, }, ) - return [] + return {"data": []} async def refresh_models_cache(self) -> None: try: