LangChain
Il ChatOpenAI di LangChain (da langchain-openai) punta a UberLLM con un
base_url e api_key. Tutto il resto — chains, agents, tools, streaming —
funziona senza modifiche.
Installazione
pip install langchain langchain-openai
Python
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="deepseek/deepseek-v4-flash",
base_url="https://api.uberllm.dev/v1",
api_key=os.environ["UBERLLM_API_KEY"],
)
print(llm.invoke("Say hello in one sentence.").content)
base_url ha la precedenza sulle variabili d'ambiente OPENAI_API_BASE / OPENAI_BASE_URL, quindi un kwarg esplicito è il più affidabile.
Streaming
for chunk in llm.stream("Count to five."):
print(chunk.content, end="", flush=True)
Strumenti / agenti
Poiché ChatOpenAI supporta il formato di chiamata degli strumenti di OpenAI, bind_tools e gli esecutori di agenti funzionano così come sono con qualsiasi modello UberLLM in grado di utilizzare strumenti:
from langchain_core.tools import tool
@tool
def get_weather(city: str) -> str:
"Return the weather for a city."
return f"Sunny in {city}."
agent_llm = llm.bind_tools([get_weather])
print(agent_llm.invoke("What's the weather in Paris?").tool_calls)
JavaScript / TypeScript
import { ChatOpenAI } from "@langchain/openai";
const llm = new ChatOpenAI({
model: "deepseek/deepseek-v4-flash",
apiKey: process.env.UBERLLM_API_KEY,
configuration: { baseURL: "https://api.uberllm.dev/v1" },
});
const res = await llm.invoke("Say hello in one sentence.");
console.log(res.content);
Note
- Ogni chiamata viene inviata a un fornitore terzo disponibile per il modello (Modelli e instradamento).
- Ogni chiamata viene fatturata al costo addebitato dal fornitore, senza alcuna commissione UberLLM (Prezzi).