langchain-crynux
Drop-in replacement for langchain-openai ChatOpenAI that lets existing OpenAI-compatible LLM code run on the Crynux network without changes.
Installation
pip install langchain-crynux
Dependencies:
- langchain-openai>=1.0.1
Usage
import os
from langchain_crynux import ChatCrynux
# Option 1: environment variable (same as langchain-openai)
os.environ["OPENAI_API_KEY"] = "your-api-key"
chat = ChatCrynux(
base_url="crynux_base_url",
model="Qwen/Qwen2.5-7B-Instruct",
vram_limit=24,
timeout=60,
# Option 2: pass api_key directly
# api_key="your-api-key",
)
response = chat.invoke("Hello from Crynux.")
print(response.content)
base_urlis the Crynux API endpoint. There is no default.vram_limitis the minimum GPU VRAM (in GB) required for the inference run. Default is 24.
ChatCrynux is a single ChatModel. Call it with invoke / ainvoke / with_structured_output the same way as ChatOpenAI. LangGraph graphs that call ainvoke do not need to change; set the switches on the ChatCrynux constructor.
Responses API and background polling
| Config | Default | Meaning |
|---|---|---|
use_responses_api |
Inherited from ChatOpenAI (None, inferred by the parent class) |
Whether to call /v1/responses |
background |
False |
Whether to send background=true on Responses and poll inside ChatCrynux |
timeout / request_timeout |
Inherited from the parent class | Same parameter, two spellings. background=False: HTTP timeout. background=True: total polling timeout |
http_timeout |
60 when background=True and unset |
Used only when background=True: HTTP timeout for each create / retrieve |
poll_interval |
2.0 |
Used only when background=True: seconds between retrieve calls |
Background example:
from langchain_crynux import ChatCrynux
chat = ChatCrynux(
base_url="crynux_base_url",
model="Qwen/Qwen2.5-7B-Instruct",
use_responses_api=True,
background=True,
timeout=600,
http_timeout=60,
poll_interval=2.0,
)
response = chat.invoke("Hello from Crynux.")
print(response.content)
When background=True, invoke / ainvoke still return a finished AIMessage. ChatCrynux creates the Responses job, polls until completed or failed, and then returns. A failed job or a polling timeout raises an exception.
Synchronous Responses without internal polling:
chat = ChatCrynux(
base_url="crynux_base_url",
model="Qwen/Qwen2.5-7B-Instruct",
use_responses_api=True,
background=False,
)
Structured Output
You can use the with_structured_output method to get structured output from the model.
from typing import Optional
from langchain_crynux import ChatCrynux
from pydantic import BaseModel, Field
class Weather(BaseModel):
"""The weather in a specific location."""
city: str = Field(description="The city to get the weather for")
temperature: float = Field(description="The temperature in celsius")
condition: Optional[str] = Field(description="The weather condition (e.g., sunny, rainy)")
chat = ChatCrynux(
base_url="crynux_base_url",
model="Qwen/Qwen2.5-7B-Instruct",
temperature=0
)
structured_llm = chat.with_structured_output(Weather)
response = structured_llm.invoke("The weather in Tokyo is 25.5 degrees celsius and sunny.")
print(response)
# Weather(city='Tokyo', temperature=25.5, condition='sunny')
The same with_structured_output call works with background=True.
ChatCrynux defaults with_structured_output to method="function_calling". ChatOpenAI defaults to method="json_schema". Many models on Crynux do not support OpenAI json mode, so ChatCrynux uses function calling instead.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_crynux-0.2.0.tar.gz.
File metadata
- Download URL: langchain_crynux-0.2.0.tar.gz
- Upload date:
- Size: 17.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7c40c92e3c51b6aa5d6b906e6fd8d7a6d5bef9374a1530fa4d8f8ff96388040
|
|
| MD5 |
d52cf6461054d26c17feb612490af85f
|
|
| BLAKE2b-256 |
998fd24dab3ad3cb66136e3b09c21c81d3dfb32592f51f0da50003e14d2321b2
|
File details
Details for the file langchain_crynux-0.2.0-py3-none-any.whl.
File metadata
- Download URL: langchain_crynux-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c50aca923f765891de8c6bccd533bc6847327013cc94fb38d7b4aadb0dad2a1
|
|
| MD5 |
90c907aa2fcc98508357aaff02d289ee
|
|
| BLAKE2b-256 |
0f7d16fe1cbd8f526f2ab087fd9ce71c675e4cf8f06ffc0362882237f4711927
|