mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +00:00
b2fd41331e
Addded missed docstrings. Fixed inconsistency in docstrings. **Note** CC @efriis There were PR errors on `langchain_experimental/prompt_injection_identifier/hugging_face_identifier.py` But, I didn't touch this file in this PR! Can it be some cache problems? I fixed this error.
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
import json
|
|
import logging
|
|
from typing import Optional
|
|
|
|
from langchain_core.callbacks import CallbackManagerForToolRun
|
|
|
|
from langchain_community.tools.slack.base import SlackBaseTool
|
|
|
|
|
|
class SlackGetChannel(SlackBaseTool):
|
|
"""Tool that gets Slack channel information."""
|
|
|
|
name: str = "get_channelid_name_dict"
|
|
description: str = "Use this tool to get channelid-name dict."
|
|
|
|
def _run(
|
|
self,
|
|
run_manager: Optional[CallbackManagerForToolRun] = None,
|
|
) -> str:
|
|
try:
|
|
logging.getLogger(__name__)
|
|
|
|
result = self.client.conversations_list()
|
|
channels = result["channels"]
|
|
filtered_result = [
|
|
{key: channel[key] for key in ("id", "name", "created", "num_members")}
|
|
for channel in channels
|
|
if "id" in channel
|
|
and "name" in channel
|
|
and "created" in channel
|
|
and "num_members" in channel
|
|
]
|
|
return json.dumps(filtered_result)
|
|
|
|
except Exception as e:
|
|
return "Error creating conversation: {}".format(e)
|