本指南提供快速概览,帮助您开始使用 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 | !PyPI - 版本 |
工具功能
- - **
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 package.
pip install --quiet -U langchain-taiga
凭据
此集成需要您将 TAIGA_URL, TAIGA_API_URL, TAIGA_USERNAME, TAIGA_PASSWORD 和 OPENAI_API_KEY 设置为环境变量以向 Taiga 进行身份验证。
设置 LangSmith 也很有帮助(但非必需),以便获得一流的可观测性:
os.environ["LANGSMITH_TRACING"] = "true"
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass()
实例化
以下是展示如何实例化 Taiga 工具的示例 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
调用
使用参数直接调用
以下是使用字典中的关键字参数调用工具的简单示例。
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_agent)用于设置 LangChain 风格的代理,能够在适当时机调用工具。
# Example: Using Taiga Tools in an Agent
from langchain.agents import create_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))
model = ...
# 2. Build an agent that has access to these tools
agent_executor = create_agent(model, [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)
stream = agent_executor.stream_events(
{"messages": [("user", example_query)]},
version="v3",
)
# 6. Print out the model's responses (and any tool outputs) as they arrive
for snapshot in stream.values:
snapshot["messages"][-1].pretty_print()
API 参考
请参阅以下文档中的文档字符串:
了解使用详情、参数和高级配置。