SimplerLLM


NameSimplerLLM JSON
Version 0.2.5 PyPI version JSON
download
home_pagehttps://github.com/hassancs91/SimplerLLM
SummaryAn easy-to-use Library for interacting with language models.
upload_time2024-05-14 10:47:42
maintainerNone
docs_urlNone
authorHasan Aboul Hasan
requires_python>=3.6
licenseMIT
keywords text generation openai llm rag
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ⚪ 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/d1/59/efdf984d9016b94c051852ce68a048ad8943dbc3cf545979de1b6ec15c21/simplerllm-0.2.5.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.2.5",
    "project_urls": {
        "Homepage": "https://github.com/hassancs91/SimplerLLM"
    },
    "split_keywords": [
        "text generation",
        " openai",
        " llm",
        " rag"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "782411cb491d386334ed51c2e32f1afa8e17eb20309e724d14edbb76b4edb002",
                "md5": "139d98dc6611daa7256006ae233fbe9d",
                "sha256": "a8ae636a51cfc16db8fcffd4e301be92f5d41ec9c9e551d38450488e43d89d53"
            },
            "downloads": -1,
            "filename": "SimplerLLM-0.2.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "139d98dc6611daa7256006ae233fbe9d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 28943,
            "upload_time": "2024-05-14T10:47:40",
            "upload_time_iso_8601": "2024-05-14T10:47:40.131780Z",
            "url": "https://files.pythonhosted.org/packages/78/24/11cb491d386334ed51c2e32f1afa8e17eb20309e724d14edbb76b4edb002/SimplerLLM-0.2.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d159efdf984d9016b94c051852ce68a048ad8943dbc3cf545979de1b6ec15c21",
                "md5": "c409e0b0e06ce76f4481445a4e86e05c",
                "sha256": "6314e4134fe02e3e50c6ba430fd37c04549ada2fe948568d67cbb79751fc240f"
            },
            "downloads": -1,
            "filename": "simplerllm-0.2.5.tar.gz",
            "has_sig": false,
            "md5_digest": "c409e0b0e06ce76f4481445a4e86e05c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 23881,
            "upload_time": "2024-05-14T10:47:42",
            "upload_time_iso_8601": "2024-05-14T10:47:42.136569Z",
            "url": "https://files.pythonhosted.org/packages/d1/59/efdf984d9016b94c051852ce68a048ad8943dbc3cf545979de1b6ec15c21/simplerllm-0.2.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-14 10:47:42",
    "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"
}
        
Elapsed time: 0.25590s