Skip to main content

langchain-crynux

PyPI - Version Static Badge

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_url is the Crynux API endpoint. There is no default.
  • vram_limit is 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

langchain_crynux-0.2.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_crynux-0.2.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

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

Hashes for langchain_crynux-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e7c40c92e3c51b6aa5d6b906e6fd8d7a6d5bef9374a1530fa4d8f8ff96388040
MD5 d52cf6461054d26c17feb612490af85f
BLAKE2b-256 998fd24dab3ad3cb66136e3b09c21c81d3dfb32592f51f0da50003e14d2321b2

See more details on using hashes here.

File details

Details for the file langchain_crynux-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_crynux-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1c50aca923f765891de8c6bccd533bc6847327013cc94fb38d7b4aadb0dad2a1
MD5 90c907aa2fcc98508357aaff02d289ee
BLAKE2b-256 0f7d16fe1cbd8f526f2ab087fd9ce71c675e4cf8f06ffc0362882237f4711927

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page