- Introduction
- About the Hackathon
- Repository Structure
- Background and Key Libraries
- Installation
- Using the Poetry Shell
- Installing and Using Ollama
- Downloading GGUF Models
- Example Script: Snowball Chain for Blog Post Generation
- Contributing
- License
This repository contains the Agentic Workflow project for the ABACBS 2024 Hackathon. The project demonstrates how to work with local Large Language Models (LLMs) in GGUF format using Python. It includes an example script that showcases a lightweight approach to constructing a prompt chain for generating blog posts.
The ABACBS 2024 Hackathon is an event organized by the Australian Bioinformatics and Computational Biology Society. This project serves as a starting point for participants interested in exploring agentic workflows with local LLMs. For more information, please visit the ABACBS website.
src/
: Contains the main project code, including the example scriptsnowball_chain.py
.models/
: Directory for storing downloaded GGUF model files.snippets/
: Personal code snippets and examples (optional, not intended for hackathon use).
This project leverages two main Python packages:
- llama-cpp-python: A Python binding for the llama.cpp library, enabling efficient inference of LLaMA models locally. GitHub Repository
- instructor: A library for structured outputs with LLMs, simplifying the handling of complex data structures. GitHub Repository
These libraries allow for working with large language models on your local machine and extracting structured information from their outputs.
- Python 3.8 or higher: Ensure you have Python installed. You can check your version with:
python3 --version
- Git: To clone the repository.
- System Dependencies: Depending on your operating system, you may need to install additional libraries for llama-cpp-python. Refer to the llama-cpp-python installation guide for details.
Poetry is a dependency management and packaging tool for Python. Install Poetry by running:
curl -sSL https://install.python-poetry.org | python3 -
After installation, ensure Poetry is added to your system's PATH. You may need to restart your terminal or follow any additional instructions provided by the installer.
For alternative installation methods, visit the official Poetry documentation.
Clone this repository and navigate to the project directory:
git clone https://github.com/TimoLassmann/ABACBS_2024_hackathon_agentic_wf.git
cd ABACBS_2024_hackathon_agentic_wf
Install the project dependencies using Poetry:
poetry install
This command creates a virtual environment and installs all necessary dependencies specified in the pyproject.toml
file.
Activate the virtual environment and run a test script:
poetry shell
python -c "import llama_cpp; import instructor; print('Installation successful!')"
If you see "Installation successful!", you're all set.
Troubleshooting:
- Poetry Not Found: Ensure that Poetry is added to your PATH.
- Python Version: Confirm you're using Python 3.8 or higher.
- Compilation Errors: If you encounter errors related to llama-cpp-python, install the required system libraries. Refer to the installation guide for assistance.
Enter the virtual environment:
poetry shell
You'll see your shell prompt change to indicate you're now inside the virtual environment.
To exit the virtual environment:
- Type
exit
and press Enter, or - Press Ctrl+D.
Note: The deactivate
command is not applicable when using Poetry's shell.
Ollama is a framework for running large language models locally, providing an alternative to using GGUF models directly.
For macOS and Linux:
curl https://ollama.ai/install.sh | bash
Note: Always review scripts before running them to ensure they're safe.
For more details, visit the official Ollama documentation.
ollama serve
This command starts the Ollama server, which handles model inference requests.
Download a model compatible with Ollama:
-
Mistral Model:
ollama pull mistral
Note: The example script is currently hard-coded to use the Mistral model.
-
Llama 2 (9B):
ollama pull llama3.2:3b
- Models vary in size; ensure your system has enough RAM.
- The 7B and 9B models typically require at least 16GB of RAM.
- Larger models (e.g., 70B) require significantly more resources.
Run the snowball_chain.py
script without specifying a model path to use Ollama:
poetry run python src/snowball_chain.py --topic "Your blog topic"
If you prefer to use local GGUF models with llama-cpp-python, follow these steps:
-
Select a GGUF Model:
Note: Choose a model compatible with your system's RAM.
-
Place the Model in the
models/
Directory:mkdir -p models mv /path/to/downloaded/model.gguf models/
-
Run the Script with the Model Path:
poetry run python src/snowball_chain.py --model_path models/model.gguf --topic "Your blog topic"
Replace
model.gguf
with the actual filename of the model you downloaded.
This project includes an example script (src/snowball_chain.py
) demonstrating how to build a prompt chain using either a local LLM or an Ollama endpoint.
- Lightweight Prompt Chain: Creates a "snowball effect" by feeding the output of one LLM call into the next.
- Structured Outputs with Instructor: Uses the
instructor
library to capture outputs in structured Python classes. - Flexible Model Integration: Supports both local GGUF models and Ollama inference endpoints.
With Ollama:
poetry run python src/snowball_chain.py --topic "Your blog topic"
With a Local GGUF Model:
poetry run python src/snowball_chain.py --model_path models/model.gguf --topic "Your blog topic"
- Generate a Blog Post Title: Based on the provided topic.
- Create a Hook: Develop a compelling introduction.
- Generate Full Content: Includes sections like introduction, background, main content, and conclusion.
Feel free to modify the script to suit your needs:
- Adjust Prompts: Customize the prompts to change how the LLM generates content.
- Change Models: Experiment with different models to see how outputs vary.
- Extend Functionality: Add new steps to the prompt chain for more complex workflows.
This project was created for the ABACBS 2024 Hackathon and is provided as-is for educational purposes. You're welcome to use, modify, and extend the code for your projects.
Please note:
- Maintenance: This repository is not actively maintained post-hackathon.
- Issues: You can open issues, but they may not be addressed promptly.
[Insert your chosen license here]