diff --git a/scrapegraphai/models/__init__.py b/scrapegraphai/models/__init__.py index db01cd2e..98c956de 100644 --- a/scrapegraphai/models/__init__.py +++ b/scrapegraphai/models/__init__.py @@ -2,6 +2,7 @@ This module contains the model definitions used in the ScrapeGraphAI application. """ +from .apiroute import APIRoute from .atlascloud import AtlasCloud from .cheaperinference import CheaperInference from .clod import CLoD @@ -13,4 +14,4 @@ from .openai_tts import OpenAITextToSpeech from .xai import XAI -__all__ = ["AtlasCloud", "CheaperInference", "DeepSeek", "MiniMax", "OneApi", "OpenAIImageToText", "OpenAITextToSpeech", "CLoD", "XAI", "Nvidia"] +__all__ = ["APIRoute", "AtlasCloud", "CheaperInference", "DeepSeek", "MiniMax", "OneApi", "OpenAIImageToText", "OpenAITextToSpeech", "CLoD", "XAI", "Nvidia"] diff --git a/scrapegraphai/models/apiroute.py b/scrapegraphai/models/apiroute.py new file mode 100644 index 00000000..edbaf29c --- /dev/null +++ b/scrapegraphai/models/apiroute.py @@ -0,0 +1,14 @@ +"""API Route OpenAI-compatible chat model wrapper.""" + +from langchain_openai import ChatOpenAI + + +class APIRoute(ChatOpenAI): + """Use API Route models through its fixed OpenAI-compatible endpoint.""" + + def __init__(self, **llm_config): + if "api_key" in llm_config: + llm_config["openai_api_key"] = llm_config.pop("api_key") + llm_config["openai_api_base"] = "https://global.api-route.com/v1" + + super().__init__(**llm_config) diff --git a/tests/test_apiroute_model.py b/tests/test_apiroute_model.py new file mode 100644 index 00000000..10e0cc97 --- /dev/null +++ b/tests/test_apiroute_model.py @@ -0,0 +1,19 @@ +"""Tests for the API Route model wrapper.""" + +import importlib.util +from pathlib import Path + + +def test_apiroute_uses_fixed_endpoint_and_api_key(): + """The wrapper should configure ChatOpenAI without making a network call.""" + model_path = ( + Path(__file__).resolve().parents[1] / "scrapegraphai/models/apiroute.py" + ) + spec = importlib.util.spec_from_file_location("apiroute", model_path) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + + model = module.APIRoute(api_key="test-key", model="gpt-5.5") + + assert str(model.openai_api_base).rstrip("/") == "https://global.api-route.com/v1" + assert model.openai_api_key.get_secret_value() == "test-key"