LangChain ChatOpenAI wrapper for Crynux.
Project description
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="https://bridge.crynux-as.xyz/v1/llm",
model="Qwen/Qwen-2.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_urldefaults tohttps://bridge.crynux-as.xyz/v1/llm. -
vram_limitis the minimum GPU VRAM (in GB) required for the inference run. Default is 24.
Structured Output
You can use the with_structured_output method to get structured output from the model. This is useful for extraction or function calling tasks.
Why Function Calling?
langchain-crynux defaults to method="function_calling" automatically. This is because many open-source models (like Qwen) running on the decentralized Crynux Network do not fully support OpenAI's native strict json_mode or response_format. Using tool calling is the most reliable way to strictly enforce the output schema on these models. See Crynux Structured Output Docs for details.
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(
model="Qwen/Qwen-2.5-7B-Instruct",
temperature=0
)
# Automatically uses method="function_calling" for reliability
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')
Project details
Release history Release notifications | RSS feed
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.1.2.tar.gz.
File metadata
- Download URL: langchain_crynux-0.1.2.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89352f350f04880fcdcf4adacf245c009f7a45ec73eadce1f17ba5505ff96a35
|
|
| MD5 |
1ca44091a47e45eae890de40ff4f3359
|
|
| BLAKE2b-256 |
f2f4e6b273dc25b5a2ef53042e54f678d85297b8dead4a7d00c4c64ca4550e9c
|
File details
Details for the file langchain_crynux-0.1.2-py3-none-any.whl.
File metadata
- Download URL: langchain_crynux-0.1.2-py3-none-any.whl
- Upload date:
- Size: 11.4 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 |
3004e07a940b845554074b085a30252a9dd1f07369e53ac1e0bf274378d6e074
|
|
| MD5 |
2f35f85611d5e00ddbd378bf702c858a
|
|
| BLAKE2b-256 |
7092e31e69547f928f7fe4798d6037ccc074167926bb1f5da3dbffec31755f3b
|