Skip to main content

Client-side tools for using large language models, full service (e.g. ChatGPT & Bard) or locally hosted (e.g. LLaMA derivatives)

Project description

OgbujiPT

Toolkit for using self-hosted large language models (LLMs), but also with support for full-service such as ChatGPT.

Includes demos with RAG ("chat your documents") and AGI/AutoGPT/privateGPT-style capabilities, via streamlit, Discord, command line, etc.

There are some helper functions for common LLM tasks, such as those provided by projects such as langchain, but not yet as extensive. The OgbujiPT versions, however, emphasize simplicity and transparency.

Tested back ends are llama-cpp-python or text-generation-webui (AKA Oobabooga or Ooba). In our own practice we use both of these with Nvidia GPU and Apple M1/M2. We've also tested with OpenAI's full service ChatGPT (and use it in our practice).

OgbujiPT is primarily developed by the crew at Oori Data. We offer software engineering services around LLM applications.

PyPI - Version PyPI - Python Version

Quick links


Getting started

pip install ogbujipt

Just show me some code, dammit!

from ogbujipt.config import openai_emulation
from ogbujipt import oapi_first_choice_text
from ogbujipt.prompting import format, ALPACA_INSTRUCT_DELIMITERS

llm_api = openai_emulation(host='http://localhost', port=8000)  # Update with your LLM host
# Change the delimiters to a prompting style that suits the LLM you're using
prompt = format('Write a short birthday greeting for my star employee',
                delimiters=ALPACA_INSTRUCT_DELIMITERS)

# Just using pyopenai directly, for simplicity, setting params as needed
response = llm_api.Completion.create(prompt=prompt, model='', temperature=0.1, max_tokens=100)
# Extract just the response text, but the entire structure is available
print(oapi_first_choice_text(response))

The Nous-Hermes 13B LLM offered the following response:

Dear [Employee's Name], I hope this message finds you well on your special day! I wanted to take a moment to wish you a very happy birthday and express how much your contributions have meant to our team. Your dedication, hard work, and exceptional talent have been an inspiration to us all. On this occasion, I want you to know that you are appreciated and valued beyond measure. May your day be filled with joy and laughter.

For more examples see the demo directory

A bit more explanation

Many self-hosted AI large language models are now astonishingly good, even running on consumer-grade hardware, which provides an alternative for those of us who would rather not be sending all our data out over the network to the likes of ChatGPT & Bard. OgbujiPT provides a toolkit for using and experimenting with LLMs via llama-cpp-python or text-generation-webui (AKA Oobabooga or Ooba), a popular tool for self-hosting such models. OgbujiPT can invoke these to complete prompted tasks on self-hosted LLMs. It can also be used for building front end to ChatGPT and Bard, if these are suitable for you.

Right now OgbujiPT requires a bit of Python development on the user's part, but more general capabilities are coming.

Bias to sound software engineering

I've seen many projects taking stabs at something like this one, but they really just seem to be stabs, usually by folks interested in LLM who admit they don't have strong coding backgrounds. This not only leads to a lumpy patchwork of forks and variations, as people try to figure out the narrow, gnarly paths that cater to their own needs, but also hampers maintainability just at a time when everything seems to be changing drastically every few days.

I have a strong Python and software engineering background, and I'm looking to apply that in this project, to hopefully create something more easily speclailized for other needs, built-upon, maintained and contributed to.

This project is packaged using hatch, a modern Python packaging tool. I plan to write tests as I go along, and to incorporate continuous integration. Admit I may be slow to find the cycles for all that, but at least the intent and architecture is there from the beginning.

Prompting patterns

Different LLMs have different conventions you want to use in order to get high quality responses. If you've looked into self-hosted LLMs you might have heard of the likes of alpaca, vicuña or even airoboros. OgbujiPT includes some shallow tools in order to help construct prompts according to the particular conventions that would be best for your choice of LLM. This makes it easier to quickly launch experiments, adapt to and adopt other models.

Contributions

For reasons I'm still investigating (some of the more recent developments and issues in Python packaging are quite esoteric), some of the hatch tools such as hatch run are problematic. I suspect they might not like the way I rename directories during build, but I won't be compromising on that. So, for example, to run tests, just stick to:

pytest test

More notes for contributors in the wiki.

License

Apache 2. For tha culture!

Credits

Some initial ideas & code were borrowed from these projects, but with heavy refactoring:

FAQ

What's unique about this toolkit?

I mentioned the bias to software engineering, but what does this mean?

  • Emphasis on modularity, but seeking as much consistency as possible
  • Support for multitasking
  • Finding ways to apply automated testing

Does this support GPU for locally-hosted models

Yes, but you have to make sure you set up your back end LLm server (llama.cpp or text-generation-webui) with GPU, and properly configure the model you load into it. If you can use the webui to query your model and get GPU usage, that will also apply here in OgbujiPT.

Many install guides I've found for Mac, Linux and Windows touch on enabling GPU, but the ecosystem is still in its early days, and helpful resouces can feel scattered.

What's with the crazy name?

Enh?! Yo mama! 😝 My surname is Ogbuji, so it's a bit of a pun. This is the notorious OGPT, ya feel me?

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

ogbujipt-0.4.1.tar.gz (47.6 kB view details)

Uploaded Source

Built Distribution

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

ogbujipt-0.4.1-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

Details for the file ogbujipt-0.4.1.tar.gz.

File metadata

  • Download URL: ogbujipt-0.4.1.tar.gz
  • Upload date:
  • Size: 47.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for ogbujipt-0.4.1.tar.gz
Algorithm Hash digest
SHA256 2cf13dec68e2f09e030b010f64959e2a1121c122f5c895f6dca138a84d94f8c0
MD5 0bfd376b8f0c4c61600c0a2d0ddaf4e5
BLAKE2b-256 12070885745706c1b4cb20f6a18c4b516cad0c4f489d018d3b0be5adca892b0b

See more details on using hashes here.

File details

Details for the file ogbujipt-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: ogbujipt-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 24.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for ogbujipt-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8aed214dc4969492db1d98d66a573dcc7fd19fa39474903b9648ebcc496f5131
MD5 48123339bc0b2dd3bfa0972d22523192
BLAKE2b-256 a144389e1b060510562f740c9722bc30f473bf914e281c05e85833852dae8682

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