Skip to main content

Add your description here

Project description

langroid-examples

Examples of using the Langroid Multi-Agent Programming framework to build LLM applications.

:warning: Many of the examples in the examples folder in this repo are copied from the corresponding folder in the core langroid repo, although the core repo is generally more updated. We occasionally update this repo with the latest versions from the langroid repo. However, there are some examples in this repo that are not in the core langroid repo.

Set up various keys in the .env file or as environment variables

Many of the examples require API keys for LLMs, vector-stores, redis-cache, etc. Follow the instructions in the main langroid repo to set up these keys in the .env file, or explicitly set the environment variables in your shell using, e.g., export GEMINI_API_KEY=your_key.

Use uv to run the examples

Install uv, see here

Then run any of the examples as in the examples below:

uv run examples/basic/chat.py
uv run examples/docqa/chat.py

The chainlit examples can be run using:

uv run chainlit run examples/basic/simplest.py

This auto-installs a virtual env with the right dependencies and runs the example. The first run may take a little bit of time as it installs the dependencies.

Many of the non-chainlit scripts take additional flags such as the following, but see the specific scripts for details:

  • -m to specify an LLM, e.g. -m ollama/mistral.
  • -nc turn off cache retrieval for LLM responses, i.e., get fresh (rather than cached) responses each time you run it.
  • -d turns on debug mode, showing more detail such as prompts etc.

All of the examples are best run on the command-line, preferably in a nice terminal like Iterm2.

For developers/contributors

First-time set up of the project with uv

To set up the project the first time using uv, we did the following (it was only needed one time, but recording it here for future reference):

Initialize the project as an application named examples with Python 3.11:

uv init --app --name examples --python 3.11

This creates a pyproject.toml with the appropriate entries.

Create virtual env and install dependencies

Then create a virtual env, activate it and install the dependencies:

uv venv --python 3.11
. ./.venv/bin/activate 
uv pip install -r pyproject.toml 

Ubuntu

On ubuntu, for the SQL applications, you'll need to make sure a few dependencies are installed including:

  • postgresql
sudo apt-get install libpq-dev
  • mysql dev
sudo apt install libmysqlclient-dev
  • and if you are on an earlier version of ubuntu, then python11
sudo apt install python3.11-dev build-essential

Docker Instructions

We provide a containerized version of this repo via this Docker Image. All you need to do is set up environment variables in the .env file. Please follow these steps to setup the container:

# get the .env file template from `langroid` repo
wget https://github.com/langroid/langroid/blob/main/.env-template .env

# Edit the .env file with your favorite editor (here nano):
# add API keys as explained above
nano .env

# launch the container
docker run -it  -v ./.env:/.env langroid/langroid

# Use this command to run any of the examples
python examples/<Path/To/Example.py> 

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langroid_examples-0.1.0.tar.gz (44.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langroid_examples-0.1.0-py3-none-any.whl (84.6 kB view details)

Uploaded Python 3

File details

Details for the file langroid_examples-0.1.0.tar.gz.

File metadata

  • Download URL: langroid_examples-0.1.0.tar.gz
  • Upload date:
  • Size: 44.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.8

File hashes

Hashes for langroid_examples-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2107b5dd6930eca065679c9ea05001a8d71c90e4fb0f0007f90c4200b2ae0452
MD5 4b879eaac180b996a5ebd9a1b382fc81
BLAKE2b-256 d3b154877d0748ff7b1b51cba8add2093496295d6a25c0f4b31765729877d5ca

See more details on using hashes here.

File details

Details for the file langroid_examples-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langroid_examples-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 10a53762283290e20f6e450c138343f508efb5c3c9311f40374a80115a1687fd
MD5 dd051a84eff53e16ed2a07e5d0dc1083
BLAKE2b-256 3a3b6e42cc61bc71ee81d2b8ccfff0ea71c453845088ca912bdf2ce8061a466f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page