Skip to content

Python scraper based on AI

feat(models): add Cheaper Inference OpenAI-compatible model wrapper

aiapienthusiastb6dd13e57aa3
diff --git a/scrapegraphai/models/cheaperinference.py b/scrapegraphai/models/cheaperinference.py
new file mode 100644
index 00000000..423d2cfe
--- /dev/null
+++ b/scrapegraphai/models/cheaperinference.py
@@ -0,0 +1,22 @@
+"""
+Cheaper Inference Module
+"""
+
+from langchain_openai import ChatOpenAI
+
+
+class CheaperInference(ChatOpenAI):
+ """
+ A wrapper for ChatOpenAI configured for Cheaper Inference's OpenAI-compatible
+ LLM API. Each model costs 15–60% less than the list price of its lab.
+
+ Args:
+ llm_config (dict): Configuration parameters for the language model.
+ """
+
+ 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://api.cheaperinference.com/v1"
+
+ super().__init__(**llm_config)