Skip to main content

An integration package connecting QwQ and LangChain

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_qwq_modification-0.1.0.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

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

langchain_qwq_modification-0.1.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file langchain_qwq_modification-0.1.0.tar.gz.

File metadata

File hashes

Hashes for langchain_qwq_modification-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5ee26b6e059d1c9d31fd2af7b921778048713e75c4f328974391cd763db7356d
MD5 f1bca46a856e7dabeb6db48a2b37aa0e
BLAKE2b-256 4350c10a50ccf6ec0eb182b524bffded29f0fa985c3f438982bf0909a97e7e23

See more details on using hashes here.

File details

Details for the file langchain_qwq_modification-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_qwq_modification-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0f6d3a983f5559a17e197d71cf4657241f1dc7f5fcd41dff17257ce2e8097b1d
MD5 c993aad79a59052be1d7c21aea6a3aed
BLAKE2b-256 088c6f7604d2f3cde44034b65677b6a176b01ff716da685c248893cbc9947167

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page