A practical utility library for LangChain and LangGraph development
Project description
LangChain Dev Utils
This toolkit is designed to provide encapsulated utility functions for developers building applications with large language models using LangChain and LangGraph, helping developers work more efficiently.
Installation and Usage
- Using pip
pip install -U langchain-dev-utils
- Using poetry
poetry add langchain-dev-utils
- Using uv
uv add langchain-dev-utils
Usage
1. Model Management ⭐
(1) ChatModel
from langchain_dev_utils import register_model_provider, load_chat_model
from langchain_qwq import ChatQwen
from dotenv import load_dotenv
load_dotenv()
# Register custom model providers
register_model_provider("dashscope", ChatQwen)
register_model_provider("openrouter", "openai", base_url="https://openrouter.ai/api/v1")
# Load models
model = load_chat_model(model="dashscope:qwen-flash")
print(model.invoke("Hello"))
model = load_chat_model(model="openrouter:moonshotai/kimi-k2-0905")
print(model.invoke("Hello"))sh", temperature=0.7)
emb = load_embeddings("zai:zai-embed")
(2) Embedding
from langchain_dev_utils import register_embeddings_provider, load_embeddings
register_embeddings_provider(
"dashscope", "openai", base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"
)
embeddings = load_embeddings("dashscope:text-embedding-v4")
print(embeddings.embed_query("hello world"))
2. Message Utilities
from langchain_dev_utils import (
convert_reasoning_content_for_ai_message,
convert_reasoning_content_for_chunk_iterator,
aconvert_reasoning_content_for_chunk_iterator,
merge_ai_message_chunk,
has_tool_calling,
parse_tool_calling,
message_format
)
# merge reasoning tags into content
msg = convert_reasoning_content_for_ai_message(ai_msg, think_tag=("<think>","</think>"))
# streaming (sync / async)
for chunk in convert_reasoning_content_for_chunk_iterator(model.stream("hi")):
print(chunk.content, end="")
# re-assemble chunks
full = merge_ai_message_chunk(chunks)
# tool-call helpers
if has_tool_calling(msg):
name, args = parse_tool_calling(msg, first_tool_call_only=True)
# pretty print mixed items
text = message_format([human_msg, doc, "note"], separator="\n", with_num=True)
3. Tool Enhancement
from langchain_dev_utils import human_in_the_loop, human_in_the_loop_async
@human_in_the_loop # sync
@tool
def danger(x: int) -> str: ...
@human_in_the_loop_async # async
@tool
async def danger_async(x: int) -> str: ...
Testing
All utility functions in this project have been tested. You can also clone the repository to run the tests:
git clone https://github.com/TBice123123/langchain-dev-utils.git
cd langchain-dev-utils
uv sync --group test
uv run pytest .
For more information, please refer to the following documents.
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_dev_utils-0.1.5.tar.gz.
File metadata
- Download URL: langchain_dev_utils-0.1.5.tar.gz
- Upload date:
- Size: 64.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7241d9d4e0670be7fdea9f1020502714ea88c190c4a41d9e70c629ae8d6913b
|
|
| MD5 |
991accc658ad1957420e307132353f85
|
|
| BLAKE2b-256 |
59d02c5af3333d20bd32315add2e6137bb5c0e32341315b3b7017950707346fc
|
File details
Details for the file langchain_dev_utils-0.1.5-py3-none-any.whl.
File metadata
- Download URL: langchain_dev_utils-0.1.5-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3eb0fb4585965edcace72bf0573359c9885e20f71646b4d413d3a6001f7518f
|
|
| MD5 |
e86e3a561085b70d0e97dc22eb6c2435
|
|
| BLAKE2b-256 |
e3e6eff9d934efb296219772fa3b03fefff053e2d3d7c4dac16a06530fcb2dfa
|