Skip to main content
本指南快速介绍如何开始使用 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_toollangchain-taigaN/A待定PyPI - Version

工具功能

  • 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

凭据

此集成需要将 TAIGA_URLTAIGA_API_URLTAIGA_USERNAMETAIGA_PASSWORDOPENAI_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 中实例化 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()
# 通常由模型生成,此处为演示目的直接创建工具调用。
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)

链式调用

以下是一个更完整的示例,展示如何在链或智能体中结合 LLM 使用 create_entity_toolsearch_entities_tool 工具。本示例假设您有一个(如 create_agent)能够在适当时调用工具的 LangChain 风格智能体设置函数。
# 示例:在智能体中使用 Taiga 工具

from langchain.agents import create_agent
from langchain_taiga.tools.taiga_tools import create_entity_tool, search_entities_tool


# 1. 实例化或配置语言模型
# (替换为您实际的 LLM,例如 ChatOpenAI(temperature=0))
model = ...

# 2. 构建可访问这些工具的智能体
agent_executor = create_agent(model, [create_entity_tool, search_entities_tool])

# 4. 制定可能调用一个或两个工具的用户查询
example_query = "Please create a new user story with the subject 'subject' in slug project: 'slug'"

# 5. 以流式模式执行智能体(或按您的代码结构执行)
events = agent_executor.stream(
    {"messages": [("user", example_query)]},
    stream_mode="values",
)

# 6. 按到达顺序打印模型响应(以及任何工具输出)
for event in events:
    event["messages"][-1].pretty_print()

API 参考

请参阅以下文件中的文档字符串: 了解使用详情、参数和高级配置。