- Download your messenger data to disk.
- Create the Chat Loader and call
loader.load()
(orloader.lazy_load()
) to perform the conversion. - Optionally use
merge_chat_runs
to combine message from the same sender in sequence, and/ormap_ai_messages
to convert messages from the specified sender to the “AIMessage” class. Once you’ve done this, callconvert_messages_for_finetuning
to prepare your data for fine-tuning.
- Upload your messages to OpenAI and run a fine-tuning job.
- Use the resulting model in your LangChain app!
1. Download Data
To download your own messenger data, follow the instructions here. IMPORTANT - make sure to download them in JSON format (not HTML). We are hosting an example dump at this google drive link that we will use in this walkthrough.2. Create Chat Loader
We have 2 differentFacebookMessengerChatLoader
classes, one for an entire directory of chats, and one to load individual files. We
3. Prepare for fine-tuning
Callingload()
returns all the chat messages we could extract as human messages. When conversing with chat bots, conversations typically follow a more strict alternating dialogue pattern relative to real conversations.
You can choose to merge message “runs” (consecutive messages from the same sender) and select a sender to represent the “AI”. The fine-tuned LLM will learn to generate these AI messages.
Now we can convert to OpenAI format dictionaries
4. Fine-tune the model
It’s time to fine-tune the model. Make sure you haveopenai
installed
and have set your OPENAI_API_KEY
appropriately
5. Use in LangChain
You can use the resulting model ID directly theChatOpenAI
model class.