Taiga
这个笔记本提供了快速入门 langchain_taiga 中Taiga工具的概览。有关每个工具和配置的详细信息,请参阅您仓库中的文档字符串或相关文档页面。
概览
集成细节
| Class | 包 | 序列化 | JS支持 | Package 最新版本 |
|---|---|---|---|---|
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 |
Tool features
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: 向用户故事、任务或问题添加一个附件。
设置
The integration lives in the langchain-taiga package.
%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.
Credentials
此集成要求您将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()
Instantiation
以下是一个示例,展示了如何在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
Invocation
直接调用带参数
以下是使用字典作为关键字参数调用工具的一个简单示例。
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)
链式调用
以下是一个更完整的示例,展示了你如何在LLM中将create_entity_tool和search_entities_tool工具集成到一个链或代理中。此示例假设您有一个函数(如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 参考
请参阅以下位置的文档字符串:
for usage details, parameters, and advanced configurations.