diff --git a/docs/modules/indexes/document_loaders/examples/discord_loader.ipynb b/docs/modules/indexes/document_loaders/examples/discord_loader.ipynb new file mode 100644 index 00000000..8324feef --- /dev/null +++ b/docs/modules/indexes/document_loaders/examples/discord_loader.ipynb @@ -0,0 +1,67 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "6ad0a850", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3d4f1bdd", + "metadata": {}, + "outputs": [], + "source": [ + "df = pd.read_csv(\"example_data/fake_discord_chat.csv\")\n", + "df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "82880d80", + "metadata": {}, + "outputs": [], + "source": [ + "from langchain.document_loaders.discord import DiscordChatLoader" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b825a8d3", + "metadata": {}, + "outputs": [], + "source": [ + "loader = DiscordChatLoader(df, user_id_col=\"user_id\")\n", + "print(loader.load())" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "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.10.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/modules/indexes/document_loaders/examples/example_data/fake_discord_chat.csv b/docs/modules/indexes/document_loaders/examples/example_data/fake_discord_chat.csv new file mode 100644 index 00000000..5f4534ce --- /dev/null +++ b/docs/modules/indexes/document_loaders/examples/example_data/fake_discord_chat.csv @@ -0,0 +1,170 @@ +user_id,message,timestamp +6b118e52-bc2b-487e-9322-a84f217902f1,"Street of born. Order around toward serve box. More keep number some. +Physical bring doctor wall finally share make. About nothing suddenly somebody gun receive job.",2022-01-01 00:00:00 +be5ea045-4478-45a8-9b8c-8e0a43222888,"Service describe size two ever. White marriage each sell line nature far. +Religious organization type music. Often still more five. Religious present test prove fine.",2022-01-01 00:10:00 +3de7ddf9-e58b-4eb6-a7f5-083d1d022499,"Major with ball process now make. Almost hospital possible good media whom. +Clearly entire while realize wind. Base game skin together probably sport like memory.",2022-01-01 00:20:00 +87e99005-780f-4f3b-b48d-91b17cce55fe,Page indeed clear different. Skin loss develop animal customer. Cultural number effect tonight would paper.,2022-01-01 00:30:00 +251099c2-ca02-4fb4-bd52-dca41f3d8b25,"World tree seat grow. Region believe matter himself message despite. +Together type process kid enjoy watch story. Visit happen movie her. Practice few ok chance.",2022-01-01 00:40:00 +974ed6b3-c08c-4771-a8d1-945f20526850,Result visit amount production prevent attack agreement. Development month realize. Thus not whatever live decide young specific.,2022-01-01 00:50:00 +e0f88629-3df1-4f54-a40e-c75cf5909c26,"Evening past choice visit approach must. Avoid unit get stop. Image talk design only role write wrong. +I model response character son smile degree job. +Lead bill sound likely chair.",2022-01-01 01:00:00 +5f260d25-e1ff-491b-8720-29b7e7c40a1f,"Painting develop environmental message recently them area. Him for condition blood. Should brother little majority. +Couple store because deep. Radio turn clear remember collection.",2022-01-01 01:10:00 +b217eaba-53ff-430c-8d4c-f1ebd1a77a09,Leg measure on age positive. Discussion party and get huge force building. So yes assume brother medical population. Fly will enter involve cup woman spend.,2022-01-01 01:20:00 +7b42ae71-12af-4222-a352-84ed9a3414ea,Knowledge goal single believe inside. Police human and fall. Trial participant indeed against since. Few miss radio successful.,2022-01-01 01:30:00 +2a4adb92-8caa-4b9d-96f4-c89905e48a32,"Else big which energy. +Maybe Republican character conference social. Threat upon just receive. +Easy national speak. Listen assume like ago practice bit animal.",2022-01-01 01:40:00 +66d0a700-7781-4702-802c-83632e595350,"Democratic night foot. Month force civil mind true. Institution rest peace none growth own. +Start billion popular. A baby attention assume certainly result. Strong true teacher executive purpose.",2022-01-01 01:50:00 +2fe4b7c5-936d-4576-bf25-02d41acd9bb6,Us subject same war other. International how trial free. Parent certainly relationship summer four.,2022-01-01 02:00:00 +583739ec-0f39-488f-9728-d336bf6c9983,"Mention meeting similar letter easy reality. Upon morning little put. +Ago rate huge me see edge.",2022-01-01 02:10:00 +d0f75d9a-0de9-4341-bba3-0abd1f89a961,"Black second bill study if reveal so your. Economic somebody walk attack meet. Artist threat natural world. +Forget although range. My seven wait lot add production.",2022-01-01 02:20:00 +f0f494fa-e16d-4ee0-bbc8-42a92b7a6cc1,"When court officer exist yeah hold between light. Should can message character. +Sea probably parent media song second weight trip. How process effect media reduce.",2022-01-01 02:30:00 +a08cd4e4-0962-42cb-89e7-2e2812af4f3a,Anything some charge authority something. I letter laugh investment including turn. Son receive matter care many now discuss.,2022-01-01 02:40:00 +11486a17-d5c5-42e3-bcb8-b75e08b8937b,Tax image relationship under increase keep. Really society get ago himself help popular society. If indicate alone until plan economic maintain stand.,2022-01-01 02:50:00 +9ee84827-7f9b-40d0-8c45-34d8cd42d3ba,Nation dream make both. Continue often pass truth national grow. Language sometimes process way million individual friend.,2022-01-01 03:00:00 +d7a679cc-dbe9-41ee-9626-9289cfc8ae37,"Determine them fine cut. East month memory. Treat like worker federal tonight. +Gun option tree. Data start brother help citizen easy want reveal. Conference movement sea show open change.",2022-01-01 03:10:00 +470b83fb-dd86-44c9-908c-13a17c771452,"Option use bill later away. +Trade would player fine evidence learn. Increase game them necessary. Sit range must fire hard serious. Available recognize contain act.",2022-01-01 03:20:00 +67dc28d3-77d7-4de2-a176-69a67a246704,Because conference lead election time. Purpose theory old talk their. Account often center consider see loss theory because. Minute however wonder agency.,2022-01-01 03:30:00 +e07a8306-ecb9-43da-bff5-72ef4af176cd,"Woman whose face short also data. Hand just each culture no. +Despite new hold bed. Feel fund deep agency hundred drug. Pass surface continue positive mind same check hand. Across make fund similar.",2022-01-01 03:40:00 +d70c6f1f-f29c-46d7-9e2a-13fe4f4dd06f,"Quality arrive hair if over. Hotel day reach west spend toward. Any opportunity much participant property mission. +Themselves throw mind indeed. Late half recently. Edge enjoy great ahead.",2022-01-01 03:50:00 +47d84bcb-0f77-42dc-a762-255733a37ed9,"Public front article sea. Very bit center certain experience whom. +Probably reality final goal radio financial age.",2022-01-01 04:00:00 +af4890da-8ec8-4c41-ba07-7038fbe90b88,"Choose hope history none current. +Usually loss floor garden value article. No arm decision create government agree often.",2022-01-01 04:10:00 +0fefc22a-3d8f-4de2-ad42-0cce61f497e2,Explain baby might among their exactly risk. Body big set across put class. Hit should appear situation.,2022-01-01 04:20:00 +5b3809e6-e86c-4e1e-b687-5cdb4b9f76fa,"Nation summer exactly. Pick car reality would. +Quite Mr number question war throw. Certain career idea heavy. Hope process save common attack to.",2022-01-01 04:30:00 +ef0cd3a7-3368-4ccc-8232-940c041cc888,"Effort stand bag never future training. Defense attorney mouth play coach peace. Herself sing size compare. +Speak surface old half available.",2022-01-01 04:40:00 +d5b1cf3f-9b31-4d35-b89a-c29caf09fdad,"Magazine finish capital guy really too ask. Item agency seat hospital away. Near four despite without. +Congress property fund toward character. Watch detail food rock identify.",2022-01-01 04:50:00 +50a39171-4725-44dc-b88d-712a5202b949,Six this prevent. Usually sound history field little. Theory suggest else. President less team garden.,2022-01-01 05:00:00 +6aa242fb-606f-44ff-86e2-4f3c19162545,"Machine left yeah think clear. Serve role expert animal first up. +Well contain nature million. Issue firm follow far growth spring everyone boy.",2022-01-01 05:10:00 +195a938a-9e78-43af-91d1-b3a05b2737d8,"Method high practice measure style always adult along. Them stay wait manager sometimes person likely do. +Or fine conference job feeling number. Fact front compare east mind.",2022-01-01 05:20:00 +93fd62ea-8147-457b-96f2-8d9db53c53cd,"Mind well stock be morning federal then yeah. Save material stand cell poor. +Notice occur success organization chance list. Soon deal receive nearly. Future allow night take wonder rate feeling.",2022-01-01 05:30:00 +f01fc201-2491-4757-8d13-c0f0411fb2c3,"Rock or fund. Middle man course task west open. Scene movie hope development travel. +Public fine artist theory. Well across each new. Process bad eat win article want election.",2022-01-01 05:40:00 +e0c8eb7f-a4d7-411c-b337-e7eb6b28eb4f,"Moment arm may beautiful he firm. Single western dog themselves able media high material. +Century today itself fear remember message than. Fund kid rest prevent. Director officer teacher.",2022-01-01 05:50:00 +28b8a3af-b5ce-4802-a48f-22058d3931b3,Drive write various raise environment. Time official country perhaps could though good. Style fast kitchen piece sense nothing agreement.,2022-01-01 06:00:00 +f5cc758a-4b9d-479d-861c-d01432a99a5e,Assume design worker. Skill although wear maintain rest member everyone marriage. Age along feeling beat method magazine.,2022-01-01 06:10:00 +8579650a-74b7-4dac-bfce-2f5eee7fbce4,"Candidate against reduce wrong size network exactly. It present able during manager whom hard. Near tend already. +Serious major democratic remain main cost marriage. Team deal meeting group store.",2022-01-01 06:20:00 +9036fdeb-d814-4130-bc54-13e3bf8676e9,"How through support lead over there. Security over crime police attorney. Management popular item son remain if increase. +White piece glass author hit. Mean theory citizen reason simply day coach.",2022-01-01 06:30:00 +8e7a773f-e4d8-402a-a7ce-5bfcb9235503,Child inside boy conference reveal catch economy. Develop window like tax. Money truth heart learn this anyone.,2022-01-01 06:40:00 +a95756f6-5796-4e01-9555-b9d6726bfbfe,Majority real so newspaper grow yourself. Station community half line. Ready little wind energy.,2022-01-01 06:50:00 +44866560-112b-42d2-90d3-e6d13c8eca64,National region third understand mind. Water hot attorney information. Magazine customer Mrs song. Authority investment become organization.,2022-01-01 07:00:00 +0561ef77-94bb-4325-874d-11c4bd797eb7,"Everyone however skin human room dream although. Where remain director. +Eye heavy safe. Model score use exactly family structure. Two true family candidate.",2022-01-01 07:10:00 +fa71bdc4-b85b-48f5-82b8-fa9d22e9f6a3,"Model bring kitchen wish anything simple power. +Able write six official individual matter forward. Room personal economic north. Investment war several politics serve expect.",2022-01-01 07:20:00 +1b91d11a-09c8-48f0-b042-911bea52a3b8,"Record suffer start. Most feeling find down door. Letter actually I dream dream. Law cost our personal Republican. +Likely store situation protect provide half. +School place it level nor fast order.",2022-01-01 07:30:00 +10d7a616-55a6-49d0-bf6d-8f3ffc24f35e,"Pull shoulder life visit best. Itself whose even hit practice exist campaign. +Contain happy moment wide. Spring meeting part position happy population thousand.",2022-01-01 07:40:00 +6bd1ad19-a1b8-4ba0-83ee-7969b0547ee1,"Mother couple section audience we world. Huge husband window senior realize reality must message. +Mention heart action other their. Drop claim check whom trouble. Go end discuss school senior drive.",2022-01-01 07:50:00 +68faa2b0-02f9-484a-900c-95f8cfd22554,Teach free west discuss note stage. Add war than build. Politics write business. Behavior success better determine who power top billion.,2022-01-01 08:00:00 +a01b6797-d94b-4eb0-956b-efe1a3d8269d,Any end worry event fear. Memory feeling ball team.,2022-01-01 08:10:00 +7ef25987-b910-4146-89b4-40bca6da73db,"Suffer worry west big next present travel. Standard thing consumer road your. +Start decade off speech. Wall we recent civil life despite.",2022-01-01 08:20:00 +c046101f-65ed-4d22-a3a1-76efbccf6b07,Resource north environmental simply nice. Past together study part more.,2022-01-01 08:30:00 +1a55ca1e-dac2-4ee3-8739-e38494e2a603,Fund leader office animal physical matter. Attorney whole with knowledge practice create meeting question. Wind west always score art.,2022-01-01 08:40:00 +8cc516b3-d007-48be-a109-eb1a0ac1fa16,"Feeling notice five family believe goal increase. +State page structure record use her. Student defense year myself out. +Congress style perform cell mission sense. Yes when leg responsibility.",2022-01-01 08:50:00 +76411191-5c7a-4a9c-997f-ea61f3c138ff,Hope discover glass up own pressure. Two include generation TV. Fund drop government true west sit everything.,2022-01-01 09:00:00 +28ae91e1-26f1-4f40-8aaa-692a905b8b26,"Represent who smile blue model. Hour exactly lay white avoid let. Lose film technology affect agree. +Old respond old stay general natural ever. Field phone safe. Mrs whole space answer color.",2022-01-01 09:10:00 +523b4e51-2261-4d61-8fe1-a379c8df5824,Weight sport allow before resource avoid. Wait leg space writer maybe actually third. Tax need by benefit.,2022-01-01 09:20:00 +32e8c5a2-bfc5-4e5a-ab97-7e36e4a221b9,"Develop write street after well. Offer along eat buy adult but. +Never there everybody movie represent recognize ground. Result pretty pay once. Will newspaper away even dream yeah grow.",2022-01-01 09:30:00 +0c38e2ee-3ca2-44e8-be2b-7e4fe6fe4b68,Meeting mother easy newspaper check. Oil indicate available year different everyone leader. Present thus explain meeting. Head respond pretty big too natural born beautiful.,2022-01-01 09:40:00 +c09ef9ca-78a2-4796-9d4c-b791a9abcaa7,"Skill president around. +Reduce just necessary choose surface card argue. Foot base cup player. Believe effect consider operation theory.",2022-01-01 09:50:00 +d2a1de02-9514-4a6c-ae37-9cd1e2beefa0,"Medical put instead between these. +Network environment of social feel blue decide after. Glass notice simply Democrat and spring. Might need computer middle. Town turn skin skill your.",2022-01-01 10:00:00 +a9667646-d759-41b2-b22b-6c38fdba84b2,"Into daughter door especially plan expert set. Return although control join. Though blue agree maybe write. +Send party ready spring house.",2022-01-01 10:10:00 +240ea2f1-3eda-47e3-96ef-cd4f7299e4f2,"Trip face stage game doctor name cover. +Box may evening production none treatment ago. Behavior television show area news. Board leave collection director carry type whatever.",2022-01-01 10:20:00 +4f73aa5f-02d1-4cf2-bc73-45f050606c5d,"Almost country bring better member sister. Agency if around assume light development example. +Tend way deep another possible quality white. Term from new good. Worry woman recently glass.",2022-01-01 10:30:00 +b076bf4d-7964-4c30-b3be-e68dcbffa7c7,"Audience act group small. Individual agreement realize special upon work wall sometimes. +Main million and act various song where. Opportunity along generation trial consumer. Center great should Mrs.",2022-01-01 10:40:00 +10c6e307-9599-42c0-b418-35e340346eb6,So ahead bill term. Million represent election cut summer guess. Everybody though my other or stay it.,2022-01-01 10:50:00 +eb496b9d-4fbd-4355-bced-7d1065e63991,"Girl how gas. Sister popular matter. +Before indeed week else whose rest church. Trade team them. +Describe compare improve American act. Nation close example. Recent around through.",2022-01-01 11:00:00 +ddfab160-0481-4639-8407-35ec0745b657,After practice seven Republican. Task democratic general television cost matter. Arrive east crime role. Evening Mr ever national wide lose hour address.,2022-01-01 11:10:00 +cf8ceaea-9106-47ba-a4be-684e56ca9996,Process whatever public nation bar learn. Trip trouble best participant. Their among just agent check answer theory.,2022-01-01 11:20:00 +79e939eb-e6d9-4b87-a1c7-accef7802175,Standard story community analysis wife. Information affect least begin phone media establish. Challenge key film your stay entire court. City trip body kitchen increase.,2022-01-01 11:30:00 +915f81e6-870b-4e10-b43a-8d4d3b9680c4,Buy authority quality. Yet out general century record. Finally listen care specific citizen outside money.,2022-01-01 11:40:00 +3f3d1691-409e-485d-82c6-9de14d298e9b,Fear its head tough together concern matter. Measure catch visit city rise find modern. Teach least major resource first itself.,2022-01-01 11:50:00 +3cd4ad69-7347-41de-86fd-f2fe6bcf5696,Here huge tonight how audience team. Month land toward role. Someone ready mention building. Language democratic traditional but center figure.,2022-01-01 12:00:00 +5201d830-5cf2-4ac4-8953-5cbb47e7f030,Though run open police training see my tree. Never soldier hope take want. Training huge carry direction should write.,2022-01-01 12:10:00 +abcc0af7-0ba9-4896-8e3d-80f9be1dae23,"Agree when defense. Use might need behind any. +Data walk let me not information. Against eight design.",2022-01-01 12:20:00 +92ed4204-74e7-4930-992f-5bfd135d91b6,"Customer writer body. Half run suggest travel. Nature various just. +Recently wish short apply ask. Image bit share.",2022-01-01 12:30:00 +34493408-4367-4f2d-ab3b-27c9c0944928,"Wife result likely system person wind. Pm near contain reach group. +At recent a responsibility. Evidence receive space himself no mind. Public eat now situation.",2022-01-01 12:40:00 +835653c0-14ca-4cc6-9849-955526a461ac,Or draw age name whose. Break individual region always. Pattern site three many painting.,2022-01-01 12:50:00 +9388ff42-cbdd-45f4-aa2c-c645df008470,State through pass car represent whatever conference. Structure law painting peace. Hold activity between Mr. Morning international end break summer natural.,2022-01-01 13:00:00 +e6739d96-31af-479b-b851-c4233136f5d4,"Guy play easy indicate even senior. Tree Mrs thought. Threat skill billion how agree. +Truth future board themselves think when. Decision must newspaper general instead.",2022-01-01 13:10:00 +7a1ddff1-b8af-4e6e-ae84-3f3a96fc5a47,"Mind general shoulder accept remember. +I cover choice possible whatever example. Dark well sing some. +Computer interest each position. Agency hear fire discussion moment.",2022-01-01 13:20:00 +6c98dfb2-faa1-4eea-a972-b7112843e19b,"Religious agreement soldier. Price beautiful strategy heavy. +Meet before action note. Sort someone amount foot. Pm full in either question it under. Model long any catch board election.",2022-01-01 13:30:00 +ede05137-7878-49f1-9cbe-119238b77c08,"Fund close thank technology individual member. Clearly at avoid throw. Culture environment young try ask line center. +Attack continue week federal budget. Fund almost lose fast property.",2022-01-01 13:40:00 +f4aff2ea-899e-492f-8927-42858f569c2f,"Side factor wait wide simply last itself. Edge move ten. +Ground boy theory per hit. +Upon me public water simple east party candidate. Fact eat them difficult. Oil together stay ask rock idea.",2022-01-01 13:50:00 +0e788389-d481-4de3-9111-8432517c4a2a,Doctor interview just computer management live. Theory idea option board low box treatment. Hold couple difficult product.,2022-01-01 14:00:00 +c4060e04-fbfb-4b82-8d8b-4bd663790acf,"Set benefit they happen number especially. Finish Mrs position option. +Business center simple question easy understand impact like. Enjoy important language.",2022-01-01 14:10:00 +8eca8bce-792a-475c-8fe8-01ef77e9316b,Plant consumer guy religious society animal sort worker. Mind use scientist us mean worker. Represent maybe general who poor reveal.,2022-01-01 14:20:00 +de89d520-24cc-4f0b-b97c-838b03949b1c,"Maintain through realize along. Make section writer many. +Her out year upon simple easy picture. Help political imagine various nothing finish. Charge from trip yes blood.",2022-01-01 14:30:00 +4d96429c-63f5-48c5-9512-1aa8e1c1a60f,"Side behind power all thing current body. Send chair white take could wear. Three pattern might quickly spend cup life. +Sister middle agency beyond. Strategy practice base continue.",2022-01-01 14:40:00 +bb9850ea-759c-4de7-98fc-8e21c040cf79,While rate data. Food land though street operation beyond study. Side foreign begin herself however movement.,2022-01-01 14:50:00 +b1ba7f50-b7a8-4f6a-b11e-a1d71bba8733,"Watch fine choice article. Item customer real force option treat. +Travel thought health. Look test already former risk chair arrive task. Way red kid evidence eye.",2022-01-01 15:00:00 +ac0a4df6-9c7a-4878-9424-56c8ba02d513,"With anything create either child. Tonight later view cover arm measure. +And industry speech several huge charge. Save phone natural present. Always conference plant build.",2022-01-01 15:10:00 +4a5de80b-4281-44cf-a151-ec6f0dc9d541,"Thing maybe order church near. Night price factor little total fact parent. Begin let air. +Guy just result art how figure. +Strong spring organization. Theory along issue attorney issue suffer pick.",2022-01-01 15:20:00 +97e4a76a-c8f6-4dc4-af20-857201d2bbbb,"Campaign account on glass of quality professional. +Drop report them around kind community. Author off develop recent phone book.",2022-01-01 15:30:00 +7fa29328-27e0-4bbf-96bb-27b535a875ae,High result drop matter one since sure. Prove century little prepare very safe similar personal. Chance according enough.,2022-01-01 15:40:00 +773faa8b-713e-4541-a251-84150eb2df19,"Economy teacher bag item throw. Past significant scientist each yet book beat. +That consider into. Perhaps agree approach bar political drop either.",2022-01-01 15:50:00 +f1e489ef-c16e-41ba-8590-0a118a5bbac6,Require phone low free. Meeting local use talk throughout general. Ready right work social wind near interesting.,2022-01-01 16:00:00 +7f247668-4e61-4504-a700-87f3056c57c5,"Democratic create put prepare maybe. Now development all focus. +Already represent again mission. Enough summer watch someone ready reduce your activity.",2022-01-01 16:10:00 +cd6fab3b-6c60-4104-bae9-14657337a06c,Difficult enjoy government hair concern question charge. Chair best shoulder quality unit successful I. Our without to sometimes authority.,2022-01-01 16:20:00 +3b85c1b2-deaf-4550-8f50-6cce85d497f9,"Effect ball college particular. Best network entire there. Analysis picture interest anyone. +Letter someone special avoid allow resource those.",2022-01-01 16:30:00 diff --git a/langchain/document_loaders/__init__.py b/langchain/document_loaders/__init__.py index d12318f5..87bf7609 100644 --- a/langchain/document_loaders/__init__.py +++ b/langchain/document_loaders/__init__.py @@ -18,6 +18,7 @@ from langchain.document_loaders.csv_loader import CSVLoader from langchain.document_loaders.dataframe import DataFrameLoader from langchain.document_loaders.diffbot import DiffbotLoader from langchain.document_loaders.directory import DirectoryLoader +from langchain.document_loaders.discord import DiscordChatLoader from langchain.document_loaders.duckdb_loader import DuckDBLoader from langchain.document_loaders.email import ( OutlookMessageLoader, @@ -150,4 +151,5 @@ __all__ = [ "GitLoader", "TwitterTweetLoader", "ImageCaptionLoader", + "DiscordChatLoader", ] diff --git a/langchain/document_loaders/discord.py b/langchain/document_loaders/discord.py new file mode 100644 index 00000000..e5682baa --- /dev/null +++ b/langchain/document_loaders/discord.py @@ -0,0 +1,33 @@ +"""Load from Discord chat dump""" +from __future__ import annotations + +from typing import TYPE_CHECKING, List + +from langchain.docstore.document import Document +from langchain.document_loaders.base import BaseLoader + +if TYPE_CHECKING: + import pandas as pd + + +class DiscordChatLoader(BaseLoader): + """Load Discord chat logs.""" + + def __init__(self, chat_log: pd.DataFrame, user_id_col: str = "user_id"): + """Initialize with a Pandas DataFrame containing chat logs.""" + if not isinstance(chat_log, pd.DataFrame): + raise ValueError( + f"Expected chat_log to be a pd.DataFrame, got {type(chat_log)}" + ) + self.chat_log = chat_log + self.user_id_col = user_id_col + + def load(self) -> List[Document]: + """Load all chat messages.""" + result = [] + for _, row in self.chat_log.iterrows(): + user_id = row[self.user_id_col] + metadata = row.to_dict() + metadata.pop(self.user_id_col) + result.append(Document(page_content=user_id, metadata=metadata)) + return result