Skip to main content

Description

Project description

EasyLLM -

EasyLLM is an open source project that provides helpful tools and methods for working with large language models (LLMs), both open source and closed source. Get immediataly started or check out the documentation.

EasyLLM implements clients that are compatible with OpenAI's Completion API. This means you can easily replace openai.ChatCompletion, openai.Completion, openai.Embedding with, for example, huggingface.ChatCompletion, huggingface.Completion or huggingface.Embedding by changing one line of code.

Supported Clients

  • huggingface - HuggingFace models
    • huggingface.ChatCompletion - Chat with LLMs
    • huggingface.Completion - Text completion with LLMs
    • huggingface.Embedding - Create embeddings with LLMs
  • sagemaker - Open LLMs deployed on Amazon SageMaker
    • sagemaker.ChatCompletion - Chat with LLMs
    • sagemaker.Completion - Text completion with LLMs
    • sagemaker.Embedding - Create embeddings with LLMs
  • bedrock - Amazon Bedrock LLMs

Check out the Examples to get started.

🚀 Getting Started

Install EasyLLM via pip:

pip install easyllm

Then import and start using the clients:

from easyllm.clients import huggingface

# helper to build llama2 prompt
huggingface.prompt_builder = "llama2"

response = huggingface.ChatCompletion.create(
    model="meta-llama/Llama-2-70b-chat-hf",
    messages=[
        {"role": "system", "content": "\nYou are a helpful assistant speaking like a pirate. argh!"},
        {"role": "user", "content": "What is the sun?"},
    ],
    temperature=0.9,
    top_p=0.6,
    max_tokens=256,
)

print(response)

the result will look like

{
  "id": "hf-lVC2iTMkFJ",
  "object": "chat.completion",
  "created": 1690661144,
  "model": "meta-llama/Llama-2-70b-chat-hf",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": " Arrrr, the sun be a big ol' ball o' fire in the sky, me hearty! It be the source o' light and warmth for our fair planet, and it be a mighty powerful force, savvy? Without the sun, we'd be sailin' through the darkness, lost and cold, so let's give a hearty \"Yarrr!\" for the sun, me hearties! Arrrr!"
      },
      "finish_reason": null
    }
  ],
  "usage": {
    "prompt_tokens": 111,
    "completion_tokens": 299,
    "total_tokens": 410
  }
}

Check out other examples:

See the documentation for more detailed usage and examples.

💪🏻 Migration from OpenAI to HuggingFace

Migrating from OpenAI to HuggingFace is easy. Just change the import statement and the client you want to use and optionally the prompt builder.

- import openai
+ from easyllm.clients import huggingface
+ huggingface.prompt_builder = "llama2"


- response = openai.ChatCompletion.create(
+ response = huggingface.ChatCompletion.create(
-    model="gpt-3.5-turbo",
+    model="meta-llama/Llama-2-70b-chat-hf",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Knock knock."},
    ],
)

Make sure when you switch your client that your hyperparameters are still valid. For example, temperature of GPT-3 might be different than temperature of Llama-2.

☑️ Key Features

🤝 Compatible Clients

  • Implementation of clients compatible with OpenAI API format of openai.ChatCompletion, openai.Completion, openai.Embedding.
  • Easily switch between different LLMs like openai.ChatCompletion and huggingface.ChatCompletion by changing one line of code.
  • Support for streaming of completions, checkout example How to stream completions.

⚙️ Helper Modules ⚙️

  • evol_instruct (work in progress) - Use evolutionary algorithms create instructions for LLMs.

  • prompt_utils - Helper methods to easily convert between prompt formats like OpenAI Messages to prompts for open source models like Llama 2.

🙏 Contributing

EasyLLM is an open source project and welcomes contributions of all kinds.

The project uses hatch for development. To get started, fork the repository and clone it to your local machine.

  1. Confirm hatch is installed (pipx is great to make it available globally on your machine)
  2. Once in the project directory, run hatch env create to create a default virtual environment for development.
  3. Activate the virtual environment with hatch shell
  4. Start developing! 🤩

📔 Citation & Acknowledgements

If you use EasyLLM, please share it with me on social media or email. I would love to hear about it! You can also cite the project using the following BibTeX:

@software{Philipp_Schmid_EasyLLM_2023,
author = {Philipp Schmid},
license = {Apache-2.0},
month = juj,
title = {EasyLLM: Streamlined Tools for LLMs},
url = {https://github.com/philschmid/easyllm},
year = {2023}
}

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

easyllm-0.6.0.tar.gz (55.0 kB view details)

Uploaded Source

Built Distribution

easyllm-0.6.0-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

Details for the file easyllm-0.6.0.tar.gz.

File metadata

  • Download URL: easyllm-0.6.0.tar.gz
  • Upload date:
  • Size: 55.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.6

File hashes

Hashes for easyllm-0.6.0.tar.gz
Algorithm Hash digest
SHA256 398795c04dcb65ba219e23401d3e89839d02e9a75d32e6a93de5d76e7da1f454
MD5 6642637ace9d9c2ded391c29a3bd64e7
BLAKE2b-256 734a4d3621d5ffa265a5bb4ba4b2847d3a1c0c3258fb46a9da92cfd4e7a0602a

See more details on using hashes here.

File details

Details for the file easyllm-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: easyllm-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 29.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.6

File hashes

Hashes for easyllm-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63bf951273c68a24c3d0518e376218aa682b06b681bbbb6e2bd6afb705ee7762
MD5 fe7f12d31cbe617062f5d3f78cce1947
BLAKE2b-256 675d8d27176c2d72786d60d2881dfe14f5cc1e440f7a8e1f3e4edaaa348f0a8c

See more details on using hashes here.

Supported by

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