Skip to main content

langchain-qwq-modification

魔改langchain-qwq,提高兼容性:

  1. 为api_base设置别名base_url;
  2. 合并reasoning_content到content;
  3. 添加与标签

Installation

pip install -U langchain-qwq-modification

以下为原版langchain-qwq的readme


langchain-qwq

This package contains the LangChain integration with QwQ and Qwen3

Installation

pip install -U langchain-qwq

OR if you want to install additional dependencies when you clone the repo:

pip install -U langchain-qwq[docs]
pip install -U langchain-qwq[test]
pip install -U langchain-qwq[codespell]
pip install -U langchain-qwq[lint]
pip install -U langchain-qwq[typing]

Environment Variables

And you should configure credentials by setting the following environment variables:

Chat Models (QwQ)

ChatQwQ class exposes chat models from QwQ. The integration works directly with a standard API key without requiring the Tongyi dependency.

from langchain_qwq import ChatQwQ

llm = ChatQwQ()
llm.invoke("Sing a ballad of LangChain.")

Advanced Usage

Streaming

llm = ChatQwQ(model="qwq-plus")
for chunk in llm.stream("Write a short poem about AI"):
    print(chunk.content, end="")

Async Support

llm = ChatQwQ(model="qwq-plus")
response = await llm.ainvoke("What is the capital of France?")
print(response.content)

# Streaming
async for chunk in llm.astream("Tell me about quantum computing"):
    print(chunk.content, end="")

Access to Reasoning Content

response = llm.invoke("Explain how photosynthesis works")
content = response.content
reasoning = response.additional_kwargs.get("reasoning_content", "")

Merge Reasoning Content to Content

from langchain_qwq import ChatQwQ
from langchain_qwq.utils import convert_reasoning_to_content
model = ChatQwQ(
    model="qwq-plus"
)
for chunk in convert_reasoning_to_content(model.stream("hello")):
    print(chunk)

also support async

from langchain_qwq.utils import aconvert_reasoning_to_content
async for chunk in aconvert_reasoning_to_content(model.astream("hello")):
    print(chunk)

and you can custom the think tag.

from langchain_qwq.utils import convert_reasoning_to_content

async for chunk in aconvert_reasoning_to_content(
        model.astream("hello"), think_tag=("<Start>", "<End>")
    ):
        print(chunk)

Tool Calls

from langchain_core.tools import tool

@tool
def get_current_weather(location: str, unit: str = "fahrenheit"):
    """Get the current weather in a given location"""
    return f"72 degrees and sunny in {location}"

llm = ChatQwQ(model="qwq-plus")
llm_with_tools = llm.bind_tools([get_current_weather])
response = llm_with_tools.invoke("What's the weather in San Francisco?")

also you can use parallel_tool_calls to enable parallel tool calls

from langchain_qwq import ChatQwQ
from langchain_core.tools import tool


@tool
async def get_data_in_db(db_name: str) -> str:
    """get the data from the database"""
    return f"data from the database {db_name}"


model = ChatQwQ(model="qwq-plus").bind_tools([get_data_in_db])

print(
    model.invoke(
        "please get the data from the database user and animal",
        extra_body={"parallel_tool_calls": True},
    )
)

Chat Models (Qwen3)

You can call Qwen3 through ChatQwQ, but we more strongly recommend using ChatQwen to call Qwen3 as it provides better support.

there is some examples code

from langchain_qwq import ChatQwen


model = ChatQwen(model="qwen3-32b")

for chunk in model.stream("hello!"):
    print(chunk)

Qwen3 is hybrid reasoning, so you can use enable_thinking to turn off the thinking process.

from langchain_qwq import ChatQwen
from dotenv import load_dotenv


model = ChatQwen(model="qwen3-32b", enable_thinking=False)

for chunk in model.stream("hello!"):
    print(chunk)

Qwen3 also supports thinking_budget to control the length of the thinking process.

from langchain_qwq import ChatQwen
from dotenv import load_dotenv

model = ChatQwen(model="qwen3-32b", thinking_budget=100)

for chunk in model.stream("hello!"):
    print(chunk)

Qwen3's integration is through ChatQwen, which inherits from QwQ, so you can use any features supported by ChatQwQ such as async, etc.

Metadata

Release files for langchain-qwq-modification 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-qwq-modification 0.1.0
File Size Uploaded
langchain_qwq_modification-0.1.0.tar.gz 12.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-qwq-modification 0.1.0
File Interpreter ABI Platform
langchain_qwq_modification-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.6 kB

Release files / langchain_qwq_modification-0.1.0.tar.gz

Download URL langchain_qwq_modification-0.1.0.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5ee26b6e059d1c9d31fd2af7b921778048713e75c4f328974391cd763db7356d
BLAKE2b-256 checksum
How to use checksums
4350c10a50ccf6ec0eb182b524bffded29f0fa985c3f438982bf0909a97e7e23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Release files / langchain_qwq_modification-0.1.0-py3-none-any.whl

Download URL langchain_qwq_modification-0.1.0-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0f6d3a983f5559a17e197d71cf4657241f1dc7f5fcd41dff17257ce2e8097b1d
BLAKE2b-256 checksum
How to use checksums
088c6f7604d2f3cde44034b65677b6a176b01ff716da685c248893cbc9947167
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.2

2 release files

0.0.1

2 release 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