diff --git a/docs/docs/integrations/providers/discord-shikenso.mdx b/docs/docs/integrations/providers/discord-shikenso.mdx new file mode 100644 index 00000000000..32b5a576cc7 --- /dev/null +++ b/docs/docs/integrations/providers/discord-shikenso.mdx @@ -0,0 +1,65 @@ +# Discord + +> [Discord](https://discord.com/) is an instant messaging, voice, and video communication platform widely used by communities of all types. + +## Installation and Setup + +Install the `langchain-discord-shikenso` package: + +```bash +pip install langchain-discord-shikenso +``` + +You must provide a bot token via environment variable so the tools can authenticate with the Discord API: + +```bash +export DISCORD_BOT_TOKEN="your-discord-bot-token" +``` + +If `DISCORD_BOT_TOKEN` is not set, the tools will raise a `ValueError` when instantiated. + +--- + +## Tools + +Below is a snippet showing how you can read and send messages in Discord. For more details, see the [documentation for Discord tools](/docs/integrations/tools/discord). + +```python +from langchain_discord.tools.discord_read_messages import DiscordReadMessages +from langchain_discord.tools.discord_send_messages import DiscordSendMessage + +# Create tool instances +read_tool = DiscordReadMessages() +send_tool = DiscordSendMessage() + +# Example: Read the last 3 messages from channel 1234567890 +read_result = read_tool({"channel_id": "1234567890", "limit": 3}) +print(read_result) + +# Example: Send a message to channel 1234567890 +send_result = send_tool({"channel_id": "1234567890", "message": "Hello from Markdown example!"}) +print(send_result) +``` + +--- + +## Toolkit + +`DiscordToolkit` groups multiple Discord-related tools into a single interface. For a usage example, see [the Discord toolkit docs](/docs/integrations/tools/discord). + +```python +from langchain_discord.toolkits import DiscordToolkit + +toolkit = DiscordToolkit() +tools = toolkit.get_tools() + +read_tool = tools[0] # DiscordReadMessages +send_tool = tools[1] # DiscordSendMessage +``` + +--- + +## Future Integrations + +Additional integrations (e.g., document loaders, chat loaders) could be added for Discord. +Check the [Discord Developer Docs](https://discord.com/developers/docs/intro) for more information, and watch for updates or advanced usage examples in the [langchain_discord GitHub repo](https://github.com/Shikenso-Analytics/langchain-discord). \ No newline at end of file diff --git a/docs/docs/integrations/providers/discord.mdx b/docs/docs/integrations/providers/discord.mdx index 34c286fa618..17b87229031 100644 --- a/docs/docs/integrations/providers/discord.mdx +++ b/docs/docs/integrations/providers/discord.mdx @@ -1,4 +1,4 @@ -# Discord +# Discord (community loader) >[Discord](https://discord.com/) is a VoIP and instant messaging social platform. Users have the ability to communicate > with voice calls, video calls, text messaging, media and files in private chats or as part of communities called diff --git a/docs/docs/integrations/tools/discord.ipynb b/docs/docs/integrations/tools/discord.ipynb new file mode 100644 index 00000000000..7d3027ca449 --- /dev/null +++ b/docs/docs/integrations/tools/discord.ipynb @@ -0,0 +1,257 @@ +{ + "cells": [ + { + "cell_type": "raw", + "id": "10238e62-3465-4973-9279-606cbb7ccf16", + "metadata": {}, + "source": [ + "---\n", + "sidebar_label: Discord\n", + "---" + ] + }, + { + "cell_type": "markdown", + "id": "a6f91f20", + "metadata": {}, + "source": [ + "# Discord\n", + "\n", + "This notebook provides a quick overview for getting started with Discord tooling in [langchain_discord](/docs/integrations/tools/). For more details on each tool and configuration, see the docstrings in your repository or relevant doc pages.\n", + "\n", + "## Overview\n", + "\n", + "### Integration details\n", + "\n", + "| Class | Package | Serializable | [JS support](https://js.langchain.com/docs/integrations/tools/langchain_discord) | Package latest |\n", + "| :--- |:------------------------------------------------------------------------| :---: | :---: |:-------------------------------------------------------------------------------------------------------:|\n", + "| `DiscordReadMessages`, `DiscordSendMessage` | [langchain-discord-shikenso](https://github.com/Shikenso-Analytics/langchain-discord) | N/A | TBD | ![PyPI - Version](https://img.shields.io/pypi/v/langchain-discord-shikenso?style=flat-square&label=%20) |\n", + "\n", + "### Tool features\n", + "\n", + "- **`DiscordReadMessages`**: Reads messages from a specified channel.\n", + "- **`DiscordSendMessage`**: Sends messages to a specified channel.\n", + "\n", + "## Setup\n", + "\n", + "The integration is provided by the `langchain-discord-shikenso` package. Install it as follows:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f85b4089", + "metadata": {}, + "outputs": [], + "source": [ + "%pip install --quiet -U langchain-discord-shikenso" + ] + }, + { + "cell_type": "markdown", + "id": "b15e9266", + "metadata": {}, + "source": [ + "### Credentials\n", + "\n", + "This integration requires you to set `DISCORD_BOT_TOKEN` as an environment variable to authenticate with the Discord API.\n", + "\n", + "```bash\n", + "export DISCORD_BOT_TOKEN=\"your-bot-token\"\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e0b178a2-8816-40ca-b57c-ccdd86dde9c9", + "metadata": {}, + "outputs": [], + "source": [ + "import getpass\n", + "import os\n", + "\n", + "# Example prompt to set your token if not already set:\n", + "# if not os.environ.get(\"DISCORD_BOT_TOKEN\"):\n", + "# os.environ[\"DISCORD_BOT_TOKEN\"] = getpass.getpass(\"DISCORD Bot Token:\\n\")" + ] + }, + { + "cell_type": "markdown", + "id": "bc5ab717-fd27-4c59-b912-bdd099541478", + "metadata": {}, + "source": "You can optionally set up [LangSmith](https://smith.langchain.com/) for tracing or observability:" + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a6c2f136-6367-4f1f-825d-ae741e1bf281", + "metadata": {}, + "outputs": [], + "source": [ + "# os.environ[\"LANGCHAIN_TRACING_V2\"] = \"true\"\n", + "# os.environ[\"LANGCHAIN_API_KEY\"] = getpass.getpass()" + ] + }, + { + "cell_type": "markdown", + "id": "1c97218f-f366-479d-8bf7-fe9f2f6df73f", + "metadata": {}, + "source": [ + "## Instantiation\n", + "\n", + "Below is an example showing how to instantiate the Discord tools in `langchain_discord`. Adjust as needed for your specific usage." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8b3ddfe9-ca79-494c-a7ab-1f56d9407a64", + "metadata": {}, + "outputs": [], + "source": [ + "from langchain_discord.tools.discord_read_messages import DiscordReadMessages\n", + "from langchain_discord.tools.discord_send_messages import DiscordSendMessage\n", + "\n", + "read_tool = DiscordReadMessages()\n", + "send_tool = DiscordSendMessage()\n", + "\n", + "# Example usage:\n", + "# response = read_tool({\"channel_id\": \"1234567890\", \"limit\": 5})\n", + "# print(response)\n", + "#\n", + "# send_result = send_tool({\"message\": \"Hello from notebook!\", \"channel_id\": \"1234567890\"})\n", + "# print(send_result)" + ] + }, + { + "cell_type": "markdown", + "id": "74147a1a", + "metadata": {}, + "source": [ + "## Invocation\n", + "\n", + "### Direct invocation with args\n", + "\n", + "Below is a simple example of calling the tool with keyword arguments in a dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "65310a8b-eb0c-4d9e-a618-4f4abe2414fc", + "metadata": {}, + "outputs": [], + "source": [ + "invocation_args = {\"channel_id\": \"1234567890\", \"limit\": 3}\n", + "response = read_tool(invocation_args)\n", + "response" + ] + }, + { + "cell_type": "markdown", + "id": "d6e73897", + "metadata": {}, + "source": [ + "### Invocation with ToolCall\n", + "\n", + "If you have a model-generated `ToolCall`, pass it to `tool.invoke()` in the format shown below." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f90e33a7", + "metadata": {}, + "outputs": [], + "source": [ + "tool_call = {\n", + " \"args\": {\"channel_id\": \"1234567890\", \"limit\": 2},\n", + " \"id\": \"1\",\n", + " \"name\": read_tool.name,\n", + " \"type\": \"tool_call\",\n", + "}\n", + "\n", + "tool.invoke(tool_call)" + ] + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": [ + "## Chaining\n", + "\n", + "Below is a more complete example showing how you might integrate the `DiscordReadMessages` and `DiscordSendMessage` tools in a chain or agent with an LLM. This example assumes you have a function (like `create_react_agent`) that sets up a LangChain-style agent capable of calling tools when appropriate.\n", + "\n", + "```python\n", + "# Example: Using Discord Tools in an Agent\n", + "\n", + "from langgraph.prebuilt import create_react_agent\n", + "from langchain_discord.tools.discord_read_messages import DiscordReadMessages\n", + "from langchain_discord.tools.discord_send_messages import DiscordSendMessage\n", + "\n", + "# 1. Instantiate or configure your language model\n", + "# (Replace with your actual LLM, e.g., ChatOpenAI(temperature=0))\n", + "llm = ...\n", + "\n", + "# 2. Create instances of the Discord tools\n", + "read_tool = DiscordReadMessages()\n", + "send_tool = DiscordSendMessage()\n", + "\n", + "# 3. Build an agent that has access to these tools\n", + "agent_executor = create_react_agent(llm, [read_tool, send_tool])\n", + "\n", + "# 4. Formulate a user query that may invoke one or both tools\n", + "example_query = \"Please read the last 5 messages in channel 1234567890\"\n", + "\n", + "# 5. Execute the agent in streaming mode (or however your code is structured)\n", + "events = agent_executor.stream(\n", + " {\"messages\": [(\"user\", example_query)]},\n", + " stream_mode=\"values\",\n", + ")\n", + "\n", + "# 6. Print out the model's responses (and any tool outputs) as they arrive\n", + "for event in events:\n", + " event[\"messages\"][-1].pretty_print()\n", + "```" + ], + "id": "659f9fbd-6fcf-445f-aa8c-72d8e60154bd" + }, + { + "cell_type": "markdown", + "id": "4c01b53ad063d2c", + "metadata": {}, + "source": [ + "## API reference\n", + "\n", + "See the docstrings in:\n", + "- [discord_read_messages.py](https://github.com/Shikenso-Analytics/langchain-discord/blob/main/langchain_discord/tools/discord_read_messages.py)\n", + "- [discord_send_messages.py](https://github.com/Shikenso-Analytics/langchain-discord/blob/main/langchain_discord/tools/discord_send_messages.py)\n", + "- [toolkits.py](https://github.com/Shikenso-Analytics/langchain-discord/blob/main/langchain_discord/toolkits.py)\n", + "\n", + "for usage details, parameters, and advanced configurations." + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "poetry-venv-311", + "language": "python", + "name": "poetry-venv-311" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/libs/packages.yml b/libs/packages.yml index c5a9f86f74c..469eea889ef 100644 --- a/libs/packages.yml +++ b/libs/packages.yml @@ -429,3 +429,8 @@ packages: repo: langchain-ai/langchain downloads: 9521 downloads_updated_at: '2025-02-13T23:35:48.490391+00:00' +- name: langchain-discord-shikenso + path: . + repo: Shikenso-Analytics/langchain-discord + downloads: 1 + downloads_updated_at: '2025-02-15T16:00:00.000000+00:00'