n this walkthrough, you’ll learn how to use FlashLearn’s LearnSkill capability to “learn” a new task. In our example, we’ll use LearnSkill to create a skill that can, for instance, evaluate user comments for potential purchase behavior. This process leverages sample data (if provided) and task instructions to generate a JSON-based skill definition that you can save and use in your workflow.
The code below demonstrates how to initialize LearnSkill, define a new task, and save the resulting skill definition to a file. Although the example task in the code is phrased as “from input create one google query called on key query”, you can easily adapt the task description to evaluate user comments for purchasing potential by modifying the task string.
Below is the complete code example:
import os
from dotenv import load_dotenv
from flashlearn.skills.learn_skill import LearnSkill
load_dotenv()
def main():
# Step 1: Provide your OpenAI key in a .env file
# Make sure you've set OPENAI_API_KEY in your .env file
# Step 2: Initialize the LearnSkill with your desired model and verbosity
learner = LearnSkill(model_name="gpt-4o-mini", verbose=True)
# Step 3: (Optional) Provide example data (here we pass an empty list)
# You can load or prepare data samples as needed.
# Step 4: Learn the skill by providing a task instruction.
# For evaluating user comments for potential purchase behavior, you could
# change the task description accordingly, for example:
# "Evaluate how likely the user is to buy our product based on their comment.
# Return a number (1-100) on key 'likely_to_buy' and a short explanation on key 'reason'."
skill = learner.learn_skill(
df=[], # Sample data can be provided here if available
task='from input create one google query called on key query',
model_name="gpt-4o-mini",
)
# Step 5: Save the learned skill to a JSON file for future use
skill.save('make_query.json')
if __name__ == "__main__":
main()
Walkthrough Summary #
-
Environment Setup:
Make sure you have a.env
file with your OpenAI API key (or other necessary credentials) configured. -
Initializing LearnSkill:
TheLearnSkill
object is initialized with the desired model (e.g.,"gpt-4o-mini"
) and verbosity set toTrue
to provide detailed output during the learning process. -
Learning the Skill:
Thelearn_skill
method is used to define a new task. The task description instructs the LLM on what transformation to perform. In this example, the instruction is to “create one google query” from the input, but you can modify this description to fit other tasks, such as evaluating user comments for purchase behavior. -
Saving the Skill:
The learned skill is saved as a JSON file (make_query.json
), which you can later load and integrate into your workflow.
This process encapsulates how FlashLearn uses a JSON-based approach to define skills, enabling you to quickly prototype, save, and reuse sophisticated LLM-driven transformations. Feel free to modify the task string to match your specific use case (e.g., evaluating purchase behavior) and experiment with different data inputs to see how the learned skill adapts.