泰加林
此笔记本提供了在 langchain_taiga 中开始使用 Taiga 工具的快速概述。有关每个工具和配置的更多详细信息,请参阅存储库中的文档字符串或相关文档页面。
概述
集成详细信息
| 类 | 包 | 序列 化 | JS 支持 | 最新包装 |
|---|---|---|---|---|
create_entity_tool, search_entities_tool, get_entity_by_ref_tool, update_entity_by_ref_tool , add_comment_by_ref_tool, add_attachment_by_ref_tool | langchain-taiga | N/A | TBD |
工具特点
create_entity_tool:在 Taiga 中创建用户故事、任务和问题。search_entities_tool:在 Taiga 中搜索用户故事、任务和问题。get_entity_by_ref_tool:通过引用获取用户情景、任务或问题。update_entity_by_ref_tool:通过引用更新用户情景、任务或问题。add_comment_by_ref_tool:向用户故事、任务或问题添加评论。add_attachment_by_ref_tool:将附件添加到用户情景、任务或问题。
设置
集成位于langchain-taiga包。
%pip install --quiet -U langchain-taiga
/home/henlein/Workspace/PyCharm/langchain/.venv/bin/python: No module named pip
Note: you may need to restart the kernel to use updated packages.
凭据
此集成要求您设置TAIGA_URL,TAIGA_API_URL,TAIGA_USERNAME,TAIGA_PASSWORD和OPENAI_API_KEY作为环境变量来使用 Taiga 进行身份验证。
export TAIGA_URL="https://taiga.xyz.org/"
export TAIGA_API_URL="https://taiga.xyz.org/"
export TAIGA_USERNAME="username"
export TAIGA_PASSWORD="pw"
export OPENAI_API_KEY="OPENAI_API_KEY"
设置 LangSmith 以实现一流的可观测性也很有帮助(但不是必需的):
# os.environ["LANGSMITH_TRACING"] = "true"
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass()
实例
下面是一个示例,展示了如何在langchain_taiga.根据您的特定用途进行调整。
from langchain_taiga.tools.discord_read_messages import create_entity_tool
from langchain_taiga.tools.discord_send_messages import search_entities_tool
create_tool = create_entity_tool
search_tool = search_entities_tool
调用
使用 args 直接调用
下面是一个在字典中使用 keyword 参数调用工具的简单示例。
from langchain_taiga.tools.taiga_tools import (
add_attachment_by_ref_tool,
add_comment_by_ref_tool,
create_entity_tool,
get_entity_by_ref_tool,
search_entities_tool,
update_entity_by_ref_tool,
)
response = create_entity_tool.invoke(
{
"project_slug": "slug",
"entity_type": "us",
"subject": "subject",
"status": "new",
"description": "desc",
"parent_ref": 5,
"assign_to": "user",
"due_date": "2022-01-01",
"tags": ["tag1", "tag2"],
}
)
response = search_entities_tool.invoke(
{"project_slug": "slug", "query": "query", "entity_type": "task"}
)
response = get_entity_by_ref_tool.invoke(
{"entity_type": "user_story", "project_id": 1, "ref": "1"}
)
response = update_entity_by_ref_tool.invoke(
{"project_slug": "slug", "entity_ref": 555, "entity_type": "us"}
)
response = add_comment_by_ref_tool.invoke(
{"project_slug": "slug", "entity_ref": 3, "entity_type": "us", "comment": "new"}
)
response = add_attachment_by_ref_tool.invoke(
{
"project_slug": "slug",
"entity_ref": 3,
"entity_type": "us",
"attachment_url": "url",
"content_type": "png",
"description": "desc",
}
)
使用 ToolCall 调用
如果您有模型生成的ToolCall,将其传递给tool.invoke()格式如下所示。
# This is usually generated by a model, but we'll create a tool call directly for demo purposes.
model_generated_tool_call = {
"args": {"project_slug": "slug", "query": "query", "entity_type": "task"},
"id": "1",
"name": search_entities_tool.name,
"type": "tool_call",
}
tool.invoke(model_generated_tool_call)
链接
下面是一个更完整的示例,展示了如何集成create_entity_tool和search_entities_tool具有 LLM 的链中的工具或代理。此示例假定您有一个函数(如create_react_agent),它设置一个 LangChain 风格的代理,能够在适当的时候调用工具。
# Example: Using Taiga Tools in an Agent
from langgraph.prebuilt import create_react_agent
from langchain_taiga.tools.taiga_tools import create_entity_tool, search_entities_tool
# 1. Instantiate or configure your language model
# (Replace with your actual LLM, e.g., ChatOpenAI(temperature=0))
llm = ...
# 2. Build an agent that has access to these tools
agent_executor = create_react_agent(llm, [create_entity_tool, search_entities_tool])
# 4. Formulate a user query that may invoke one or both tools
example_query = "Please create a new user story with the subject 'subject' in slug project: 'slug'"
# 5. Execute the agent in streaming mode (or however your code is structured)
events = agent_executor.stream(
{"messages": [("user", example_query)]},
stream_mode="values",
)
# 6. Print out the model's responses (and any tool outputs) as they arrive
for event in events:
event["messages"][-1].pretty_print()
API 参考:create_react_agent
API 参考
请参阅以下文档字符串:
了解使用情况详细信息、参数和高级配置。