# ⚪ SimplerLLM (Beta)
⚡ Your Easy Pass to Advanced AI ⚡
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Join the Discord chat!](https://img.shields.io/badge/Join-Discord-7289DA.svg)](https://discord.gg/HUrtZXyp3j)
## 🤔 What is SimplerLLM?
SimplerLLM is an open-source Python library designed to simplify interactions with Large Language Models (LLMs) for researchers and beginners. It offers a unified interface for different LLM providers and a suite of tools to enhance language model capabilities and make it Super easy for anyone to develop AI-powered tools and apps.
## Easy Installation
With pip:
```bash
pip install simplerllm
```
## Features
- **Unified LLM Interface**: Define an LLM instance in one line for providers like OpenAI and Google Gemini. Future versions will support more APIs and LLM providers.
- **Generic Text Loader**: Load text from various sources like DOCX, PDF, TXT files, YouTube scripts, or blog posts.
- **RapidAPI Connector**: Connect with AI services on RapidAPI.
- **SERP Integration**: Perform searches using DuckDuckGo, with more search engines coming soon.
- **Prompt Template Builder**: Easily create and manage prompt templates.
And Much More Coming Soon!
### Setting Up Environment Variables
To use this library, you need to set several API keys in your environment. Start by creating a .env file in the root directory of your project and adding your API keys there.
🔴 This file should be kept private and not committed to version control to protect your keys.
Here is an example of what your .env file should look like:
```
OPENAI_API_KEY="your_openai_api_key_here"
GEMENI_API_KEY="your_gemeni_api_key_here"
CLAUDE_API_KEY="your_claude_api_key_here"
RAPIDAPI_API_KEY="your_rapidapi_key_here" # for accessing APIs on RapidAPI
VALUE_SERP_API_KEY="your_value_serp_api_key_here" #for Google search
SERPER_API_KEY="your_serper_api_key_here" #for Google search
STABILITY_API_KEY="your_stability_api_key_here" #for image generation
```
### Creating an LLM Instance
```python
from SimplerLLM.language.llm import LLM, LLMProvider
# For OpenAI
llm_instance = LLM.create(provider=LLMProvider.OPENAI, model_name="gpt-3.5-turbo")
# For Google Gemini
#llm_instance = LLM.create(provider=LLMProvider.GEMINI,model_name="gemini-pro")
# For Anthropic Claude
#llm_instance = LLM.create(LLMProvider.ANTHROPIC, model_name="claude-3-opus-20240229")
response = llm_instance.generate_response(prompt="generate a 5 words sentence")
```
### Using Tools
#### SERP
```python
from SimplerLLM.tools.serp import search_with_serper_api
search_results = search_with_serper_api("your search query", num_results=3)
# use the search results the way you want!
```
#### Generic Text Loader
```python
from SimplerLLM.tools.generic_loader import load_content
text_file = load_content("file.txt")
print(text_file.content)
```
#### Calling any RapidAPI API
```python
from SimplerLLM.tools.rapid_api import RapidAPIClient
api_url = "https://domain-authority1.p.rapidapi.com/seo/get-domain-info"
api_params = {
'domain': 'learnwithhasan.com',
}
api_client = RapidAPIClient() # API key read from environment variable
response = api_client.call_api(api_url, method='GET', params=api_params)
```
#### Prompt Template Builder
```python
from SimplerLLM.prompts.prompt_builder import create_multi_value_prompts,create_prompt_template
basic_prompt = "Generate 5 titles for a blog about {topic} and {style}"
prompt_template = pr.create_prompt_template(basic_prompt)
prompt_template.assign_parms(topic = "marketing",style = "catchy")
print(prompt_template.content)
## working with multiple value prompts
multi_value_prompt_template = """Hello {name}, your next meeting is on {date}.
and bring a {object} wit you"""
params_list = [
{"name": "Alice", "date": "January 10th", "object" : "dog"},
{"name": "Bob", "date": "January 12th", "object" : "bag"},
{"name": "Charlie", "date": "January 15th", "object" : "pen"}
]
multi_value_prompt = create_multi_value_prompts(multi_value_prompt_template)
generated_prompts = multi_value_prompt.generate_prompts(params_list)
print(generated_prompts[0])
```
## Chunking Functions
We have introduced new functions to help you split texts into manageable chunks based on different criteria. These functions are part of the chunker tool.
### chunk_by_max_chunk_size
This function splits text into chunks with a maximum size, optionally preserving sentence structure.
### chunk_by_sentences
This function splits the text into chunks based on sentences.
### chunk_by_paragraphs
This function splits text into chunks based on paragraphs.
### chunk_by_semantics
This functions splits text into chunks based on semantics.
Example
```python
from SimplerLLM.tools import text_chunker as chunker
blog_url = "https://www.semrush.com/blog/digital-marketing/"
blog_post = loader.load_content(blog_url)
text = blog_post.content
chunks = chunker.chunk_by_max_chunk_size(text, 100, True)
```
### Next Updates
- Adding More Tools
- Interacting With Local LLMs
- Prompt Optimization
- Response Evaluation
- GPT Trainer
- Document Chunker
- Advanced Document Loader
- Integration With More Providers
- Simple RAG With SimplerVectors
- Integration with Vector Databases
- Agent Builder
- LLM Server
Raw data
{
"_id": null,
"home_page": "https://github.com/hassancs91/SimplerLLM",
"name": "SimplerLLM",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "text generation, openai, LLM, RAG",
"author": "Hasan Aboul Hasan",
"author_email": "hasan@learnwithhasan.com",
"download_url": "https://files.pythonhosted.org/packages/f4/21/b8add966711d72648d74e0c8e0c5e1507d113206037980ea80270528cb63/simplerllm-0.3.1.1.tar.gz",
"platform": null,
"description": "# \u26aa SimplerLLM (Beta)\r\n\r\n\u26a1 Your Easy Pass to Advanced AI \u26a1\r\n\r\n\r\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\r\n[![Join the Discord chat!](https://img.shields.io/badge/Join-Discord-7289DA.svg)](https://discord.gg/HUrtZXyp3j)\r\n\r\n\r\n\r\n\r\n## \ud83e\udd14 What is SimplerLLM?\r\n\r\nSimplerLLM is an open-source Python library designed to simplify interactions with Large Language Models (LLMs) for researchers and beginners. It offers a unified interface for different LLM providers and a suite of tools to enhance language model capabilities and make it Super easy for anyone to develop AI-powered tools and apps.\r\n\r\n## Easy Installation\r\n\r\nWith pip:\r\n\r\n```bash\r\npip install simplerllm\r\n```\r\n\r\n## Features\r\n\r\n- **Unified LLM Interface**: Define an LLM instance in one line for providers like OpenAI and Google Gemini. Future versions will support more APIs and LLM providers.\r\n- **Generic Text Loader**: Load text from various sources like DOCX, PDF, TXT files, YouTube scripts, or blog posts.\r\n- **RapidAPI Connector**: Connect with AI services on RapidAPI.\r\n- **SERP Integration**: Perform searches using DuckDuckGo, with more search engines coming soon.\r\n- **Prompt Template Builder**: Easily create and manage prompt templates.\r\n And Much More Coming Soon!\r\n\r\n### Setting Up Environment Variables\r\n\r\nTo use this library, you need to set several API keys in your environment. Start by creating a .env file in the root directory of your project and adding your API keys there.\r\n\r\n\ud83d\udd34 This file should be kept private and not committed to version control to protect your keys.\r\n\r\nHere is an example of what your .env file should look like:\r\n\r\n```\r\nOPENAI_API_KEY=\"your_openai_api_key_here\"\r\nGEMENI_API_KEY=\"your_gemeni_api_key_here\"\r\nCLAUDE_API_KEY=\"your_claude_api_key_here\"\r\nRAPIDAPI_API_KEY=\"your_rapidapi_key_here\" # for accessing APIs on RapidAPI\r\nVALUE_SERP_API_KEY=\"your_value_serp_api_key_here\" #for Google search\r\nSERPER_API_KEY=\"your_serper_api_key_here\" #for Google search\r\nSTABILITY_API_KEY=\"your_stability_api_key_here\" #for image generation\r\n\r\n```\r\n\r\n### Creating an LLM Instance\r\n\r\n```python\r\nfrom SimplerLLM.language.llm import LLM, LLMProvider\r\n\r\n# For OpenAI\r\nllm_instance = LLM.create(provider=LLMProvider.OPENAI, model_name=\"gpt-3.5-turbo\")\r\n\r\n# For Google Gemini\r\n#llm_instance = LLM.create(provider=LLMProvider.GEMINI,model_name=\"gemini-pro\")\r\n\r\n# For Anthropic Claude \r\n#llm_instance = LLM.create(LLMProvider.ANTHROPIC, model_name=\"claude-3-opus-20240229\")\r\n\r\nresponse = llm_instance.generate_response(prompt=\"generate a 5 words sentence\")\r\n\r\n```\r\n\r\n### Using Tools\r\n\r\n#### SERP\r\n\r\n```python\r\nfrom SimplerLLM.tools.serp import search_with_serper_api\r\n\r\nsearch_results = search_with_serper_api(\"your search query\", num_results=3)\r\n\r\n# use the search results the way you want!\r\n\r\n```\r\n\r\n#### Generic Text Loader\r\n\r\n```python\r\nfrom SimplerLLM.tools.generic_loader import load_content\r\n\r\ntext_file = load_content(\"file.txt\")\r\n\r\nprint(text_file.content)\r\n\r\n```\r\n\r\n#### Calling any RapidAPI API\r\n\r\n```python\r\nfrom SimplerLLM.tools.rapid_api import RapidAPIClient\r\n\r\napi_url = \"https://domain-authority1.p.rapidapi.com/seo/get-domain-info\"\r\napi_params = {\r\n 'domain': 'learnwithhasan.com',\r\n}\r\n\r\napi_client = RapidAPIClient() # API key read from environment variable\r\nresponse = api_client.call_api(api_url, method='GET', params=api_params)\r\n\r\n\r\n```\r\n\r\n#### Prompt Template Builder\r\n\r\n```python\r\nfrom SimplerLLM.prompts.prompt_builder import create_multi_value_prompts,create_prompt_template\r\n\r\nbasic_prompt = \"Generate 5 titles for a blog about {topic} and {style}\"\r\n\r\nprompt_template = pr.create_prompt_template(basic_prompt)\r\n\r\nprompt_template.assign_parms(topic = \"marketing\",style = \"catchy\")\r\n\r\nprint(prompt_template.content)\r\n\r\n\r\n## working with multiple value prompts\r\nmulti_value_prompt_template = \"\"\"Hello {name}, your next meeting is on {date}.\r\n and bring a {object} wit you\"\"\"\r\n\r\nparams_list = [\r\n {\"name\": \"Alice\", \"date\": \"January 10th\", \"object\" : \"dog\"},\r\n {\"name\": \"Bob\", \"date\": \"January 12th\", \"object\" : \"bag\"},\r\n {\"name\": \"Charlie\", \"date\": \"January 15th\", \"object\" : \"pen\"}\r\n]\r\n\r\n\r\nmulti_value_prompt = create_multi_value_prompts(multi_value_prompt_template)\r\ngenerated_prompts = multi_value_prompt.generate_prompts(params_list)\r\n\r\nprint(generated_prompts[0])\r\n\r\n```\r\n\r\n## Chunking Functions\r\n\r\nWe have introduced new functions to help you split texts into manageable chunks based on different criteria. These functions are part of the chunker tool.\r\n\r\n### chunk_by_max_chunk_size\r\n\r\nThis function splits text into chunks with a maximum size, optionally preserving sentence structure.\r\n\r\n### chunk_by_sentences\r\n\r\nThis function splits the text into chunks based on sentences.\r\n\r\n### chunk_by_paragraphs\r\n\r\nThis function splits text into chunks based on paragraphs.\r\n\r\n### chunk_by_semantics\r\n\r\nThis functions splits text into chunks based on semantics.\r\n\r\nExample\r\n\r\n```python\r\nfrom SimplerLLM.tools import text_chunker as chunker\r\n\r\nblog_url = \"https://www.semrush.com/blog/digital-marketing/\"\r\nblog_post = loader.load_content(blog_url)\r\n\r\ntext = blog_post.content\r\n\r\nchunks = chunker.chunk_by_max_chunk_size(text, 100, True)\r\n\r\n\r\n\r\n```\r\n\r\n### Next Updates\r\n\r\n- Adding More Tools\r\n- Interacting With Local LLMs\r\n- Prompt Optimization\r\n- Response Evaluation\r\n- GPT Trainer\r\n- Document Chunker\r\n- Advanced Document Loader\r\n- Integration With More Providers\r\n- Simple RAG With SimplerVectors\r\n- Integration with Vector Databases\r\n- Agent Builder\r\n- LLM Server \r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "An easy-to-use Library for interacting with language models.",
"version": "0.3.1.1",
"project_urls": {
"Homepage": "https://github.com/hassancs91/SimplerLLM"
},
"split_keywords": [
"text generation",
" openai",
" llm",
" rag"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "34a66df291bc0b8f3feb3b15a1f936788c3d9c7c37564d0e1c439bd31a7da718",
"md5": "03fef5e8158ae2d68287921601637c86",
"sha256": "6238446bfcb23b22106f18dcbf866b4b5b252de77c8343aa5a94088afeb2d721"
},
"downloads": -1,
"filename": "SimplerLLM-0.3.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "03fef5e8158ae2d68287921601637c86",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 95186,
"upload_time": "2024-09-09T08:23:35",
"upload_time_iso_8601": "2024-09-09T08:23:35.151935Z",
"url": "https://files.pythonhosted.org/packages/34/a6/6df291bc0b8f3feb3b15a1f936788c3d9c7c37564d0e1c439bd31a7da718/SimplerLLM-0.3.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f421b8add966711d72648d74e0c8e0c5e1507d113206037980ea80270528cb63",
"md5": "a6d20c7a59a2f78b640d0db5db62132e",
"sha256": "c9adb788d30199fe31dd08ecf645850e7e502a6d0f310fcfad487598d9d50184"
},
"downloads": -1,
"filename": "simplerllm-0.3.1.1.tar.gz",
"has_sig": false,
"md5_digest": "a6d20c7a59a2f78b640d0db5db62132e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 66369,
"upload_time": "2024-09-09T08:23:39",
"upload_time_iso_8601": "2024-09-09T08:23:39.772105Z",
"url": "https://files.pythonhosted.org/packages/f4/21/b8add966711d72648d74e0c8e0c5e1507d113206037980ea80270528cb63/simplerllm-0.3.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-09 08:23:39",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "hassancs91",
"github_project": "SimplerLLM",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "simplerllm"
}