This guide will walk you through installing FlashLearn, setting up your environment, and running a simple “Hello World” example using the LearnSkill feature.
Installation #
-
Pip Install Instructions
Install FlashLearn using pip from the command line:pip install flashlearn
-
Dependencies and Environment Requirements
- Python 3.7 or above
- An active internet connection to access LLM APIs
- API keys or credentials for your chosen client (e.g., OpenAI)
- Other dependencies will be installed automatically via pip
Setup and Configuration #
-
API Key Configurations
Ensure you set your API key for your LLM client. For example, if you’re using OpenAI, configure your environment as follows:import os os.environ["OPENAI_API_KEY"] = "YOUR_API_KEY_HERE"
-
Basic Project Setup and Directory Structure
A simple project structure might look like this:my_flashlearn_project/ ├── main.py ├── requirements.txt └── README.md
In
requirements.txt
, list:flashlearn
This structure helps keep your code organized and makes it easier to manage dependencies and configurations.
Quick Start Tutorial using LearnSkill Example #
In this example, we’ll “learn” a custom skill that evaluates the likelihood of a user buying a product based on their comment. The skill returns a score (1–100) and a short reason. This simple example demonstrates the “fit/predict” pattern used within FlashLearn.
Place the following code in your main.py
:
from flashlearn.skills.learn_skill import LearnSkill
from openai import OpenAI
# Configure your API key (adjust as needed)
import os
os.environ["OPENAI_API_KEY"] = "YOUR_API_KEY_HERE" # Replace with your actual API key
# Instantiate your pipeline "estimator" or "transformer" learner
learner = LearnSkill(model_name="gpt-4o-mini", client=OpenAI())
# Define your custom task instructions and sample data (if available)
skill = learner.learn_skill(
df=[], # You can pass an initial dataset here if needed
task=(
"Evaluate how likely the user is to buy my product based on the sentiment in their comment, "
"return an integer 1-100 on key 'likely_to_buy', and a short explanation on key 'reason'."
),
)
# Save the learned skill for future use
skill.save("evaluate_buy_comments_skill.json")
# Example input: list of dictionaries representing user comments
user_inputs = [
{"comment_text": "I love this product, it's everything I wanted!"},
{"comment_text": "Not impressed... wouldn't consider buying this."},
]
# To use the saved skill, load it and run the tasks in parallel
from flashlearn.skills.general_skill import GeneralSkill
with open("evaluate_buy_comments_skill.json", "r", encoding="utf-8") as file:
definition = json.load(file)
# Load the previously saved skill
skill = GeneralSkill.load_skill(definition)
# Create tasks from the list of user inputs
tasks = skill.create_tasks(user_inputs)
# Run tasks in parallel and get structured results
results = skill.run_tasks_in_parallel(tasks)
print("Evaluation Results:")
print(results)
What This Code Does: #
-
Initializing the Learner:
TheLearnSkill
class is instantiated with your selected model (e.g.,"gpt-4o-mini"
) and client (e.g.,OpenAI()
). -
Learning a New Skill:
The learner is provided with a task that instructs it how to evaluate comments. This “learned” skill is then saved as a JSON file. -
Loading and Running the Skill:
The skill is loaded usingGeneralSkill.load_skill
, tasks are created from your input data, and then processed in parallel to produce structured JSON output. -
Results Output:
The results are printed, and you can see each record annotated with a score (likely_to_buy
) and an explanation (reason
).
Now, run your main.py
file:
python main.py
You should see the evaluation results printed in your console, demonstrating how FlashLearn can transform user comments into actionable insights.
This quick start brings you from installation through to a practical, working example leveraging FlashLearn’s LearnSkill functionality. Enjoy building advanced LLM workflows with FlashLearn!