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 modelshuggingface.ChatCompletion- Chat with LLMshuggingface.Completion- Text completion with LLMshuggingface.Embedding- Create embeddings with LLMs
sagemaker- Open LLMs deployed on Amazon SageMakersagemaker.ChatCompletion- Chat with LLMssagemaker.Completion- Text completion with LLMssagemaker.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:
- Detailed ChatCompletion Example
- Example how to stream chat requests
- Example how to stream text requests
- Detailed Completion Example
- Create Embeddings
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.ChatCompletionandhuggingface.ChatCompletionby 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.
- Confirm hatch is installed (pipx is great to make it available globally on your machine)
- Once in the project directory, run
hatch env createto create a default virtual environment for development. - Activate the virtual environment with
hatch shell - 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}
}
Metadata
Release files for easyllm 0.6.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| easyllm-0.6.2.tar.gz | 55.1 kB | Without provenance | Details for easyllm-0.6.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| easyllm-0.6.2-py3-none-any.whl | Python 3 | none | any | Details for easyllm-0.6.2-py3-none-any.whl |
Total release size: 84.4 kB
Release files / easyllm-0.6.2.tar.gz
| Download URL | easyllm-0.6.2.tar.gz |
|---|---|
| Size | 55.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5e24450a6f321a331f80d46e1cf67f9d1706fb8a26fa8a6a03bd333a0267364d
|
|
BLAKE2b-256 checksum How to use checksums |
bf3d15f8ac8a9a225b64c6494301bee8063a44ef8ee898dba038cb2f758ac76d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.6
|
Release files / easyllm-0.6.2-py3-none-any.whl
| Download URL | easyllm-0.6.2-py3-none-any.whl |
|---|---|
| Size | 29.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
71f9b0af00a5afc25bdda9e93a98c1a8263bbf0aa093e2596532172b0eb3e054
|
|
BLAKE2b-256 checksum How to use checksums |
a75490b799798a6ad410234c1cb310c14d353e36315cc43b9f6f67c8c90e2d15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.6
|
Security for easyllm 0.6.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.