Taiga
此筆記本快速概述了如何開始使用 langchain_taiga
中的 Taiga 工具。 有關每個工具和配置的更多詳細資訊,請參閱您儲存庫中的 langchain_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 | 不適用 | 待定 |
工具功能
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
中實例化 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_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 參考文檔
請參閱文檔字串:
以獲取使用細節、參數和進階配置。