diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a0a7296..a61d104 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,9 +20,9 @@ jobs: run: make install-poetry - name: Install dependencies run: make install-env - - name: Build llm-wrapper package + - name: Build allms package run: make build - - name: Publish llm-wrapper package to PyPI + - name: Publish allms package to PyPI env: TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} run: | diff --git a/Makefile b/Makefile index 319cd8a..68e6b45 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ build:: poetry run python -m build --sdist --wheel . linter:: - poetry run pylint llm_wrapper --reports=no --output-format=colorized --fail-under=8.0 + poetry run pylint allms --reports=no --output-format=colorized --fail-under=8.0 tests:: poetry run python -m pytest -s --verbose diff --git a/README.md b/README.md index 0b73b8a..3fc76d4 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ -# llm-wrapper +# allms ___ ## About -llm-wrapper is a versatile and powerful library designed to streamline the process of querying Large Language Models +allms is a versatile and powerful library designed to streamline the process of querying Large Language Models (LLMs) 🤖💬 -Developed by the Allegro engineers, llm-wrapper is based on popular libraries like transformers, pydantic, and langchain. It takes care +Developed by the Allegro engineers, allms is based on popular libraries like transformers, pydantic, and langchain. It takes care of the boring boiler-plate code you write around your LLM applications, quickly enabling you to prototype ideas, and eventually helping you to scale up for production use-cases! -Among the llm-wrapper most notable features, you will find: +Among the allms most notable features, you will find: * **😊 Simple and User-Friendly Interface**: The module offers an intuitive and easy-to-use interface, making it straightforward to work with the model. @@ -28,7 +28,7 @@ ___ Full documentation available at **[llm-wrapper.allegro.tech](https://llm-wrapper.allegro.tech/)** -Get familiar with llm-wrapper 🚀: [introductory jupyter notebook](https://github.com/allegro/llm-wrapper/blob/main/examples/introduction.ipynb) +Get familiar with allms 🚀: [introductory jupyter notebook](https://github.com/allegro/allms/blob/main/examples/introduction.ipynb) ___ @@ -39,7 +39,7 @@ ___ Install the package via pip: ``` -pip install llm-wrapper +pip install allms ``` ### Basic Usage ⭐ @@ -47,15 +47,15 @@ pip install llm-wrapper Configure endpoint credentials and start querying the model with any prompt: ```python -from llm_wrapper.models import AzureOpenAIModel -from llm_wrapper.domain.configuration import AzureOpenAIConfiguration +from allms.models import AzureOpenAIModel +from allms.domain.configuration import AzureOpenAIConfiguration configuration = AzureOpenAIConfiguration( - api_key="your-secret-api-key", - base_url="https://endpoint.openai.azure.com/", - api_version="2023-03-15-preview", - deployment="gpt-35-turbo", - model_name="gpt-3.5-turbo" + api_key="your-secret-api-key", + base_url="https://endpoint.openai.azure.com/", + api_version="2023-03-15-preview", + deployment="gpt-35-turbo", + model_name="gpt-3.5-turbo" ) gpt_model = AzureOpenAIModel(config=configuration) @@ -102,7 +102,7 @@ responses = model.generate(prompt=prompt, input_data=input_data) ### Forcing Structured Output Format -Through pydantic integration, in llm-wrapper you can pass an output dataclass and force the LLM to provide +Through pydantic integration, in allms you can pass an output dataclass and force the LLM to provide you the response in a structured way. ```python @@ -151,7 +151,7 @@ ___ We assume that you have python `3.10.*` installed on your machine. You can set it up using [pyenv](https://github.com/pyenv/pyenv#installationbrew) -([How to install pyenv on MacOS](https://jordanthomasg.medium.com/python-development-on-macos-with-pyenv-2509c694a808)). To install llm-wrapper env locally: +([How to install pyenv on MacOS](https://jordanthomasg.medium.com/python-development-on-macos-with-pyenv-2509c694a808)). To install allms env locally: * Activate your pyenv; * Install Poetry via: @@ -160,7 +160,7 @@ You can set it up using [pyenv](https://github.com/pyenv/pyenv#installationbrew) make install-poetry ``` -* Install llm-wrapper dependencies with the command: +* Install allms dependencies with the command: ```bash make install-env @@ -189,7 +189,7 @@ via the github action `.github/workflows/docs.yml` ### Make a new release -When a new version of llm-wrapper is ready to be released, do the following operations: +When a new version of allms is ready to be released, do the following operations: 1. **Merge to master** the dev branch in which the new version has been specified: 1. In this branch, `version` under `[tool.poetry]` section in `pyproject.toml` should be updated, e.g `0.1.0`; @@ -207,5 +207,5 @@ When a new version of llm-wrapper is ready to be released, do the following oper 1. Go to _Releases_ → _Draft a new release_; 2. Select the recently created tag in _Choose a tag_ window; 3. Copy/paste all the content present in the CHANGELOG under the version you are about to release; - 4. Upload `llm_wrapper-.whl` and `llm_wrapper-.tar.gz` as assets; + 4. Upload `allms-.whl` and `allms-.tar.gz` as assets; 5. Click `Publish release`. \ No newline at end of file diff --git a/llm_wrapper/__init__.py b/allms/__init__.py similarity index 100% rename from llm_wrapper/__init__.py rename to allms/__init__.py diff --git a/llm_wrapper/chains/__init__.py b/allms/chains/__init__.py similarity index 100% rename from llm_wrapper/chains/__init__.py rename to allms/chains/__init__.py diff --git a/llm_wrapper/chains/long_text_processing_chain.py b/allms/chains/long_text_processing_chain.py similarity index 93% rename from llm_wrapper/chains/long_text_processing_chain.py rename to allms/chains/long_text_processing_chain.py index fb2f1d2..df4eb47 100644 --- a/llm_wrapper/chains/long_text_processing_chain.py +++ b/allms/chains/long_text_processing_chain.py @@ -7,10 +7,10 @@ from langchain.chains.combine_documents.base import BaseCombineDocumentsChain from langchain.schema import Document -from llm_wrapper.domain.enumerables import AggregationLogicForLongInputData, LanguageModelTask -from llm_wrapper.domain.input_data import InputData -from llm_wrapper.domain.prompt_dto import AggregateOutputClass, KeywordsOutputClass, SummaryOutputClass -from llm_wrapper.utils.long_text_processing_utils import split_text_to_max_size +from allms.domain.enumerables import AggregationLogicForLongInputData, LanguageModelTask +from allms.domain.input_data import InputData +from allms.domain.prompt_dto import AggregateOutputClass, KeywordsOutputClass, SummaryOutputClass +from allms.utils.long_text_processing_utils import split_text_to_max_size class LongTextProcessingChain(BaseCombineDocumentsChain): diff --git a/llm_wrapper/constants/__init__.py b/allms/constants/__init__.py similarity index 100% rename from llm_wrapper/constants/__init__.py rename to allms/constants/__init__.py diff --git a/llm_wrapper/constants/azure.py b/allms/constants/azure.py similarity index 100% rename from llm_wrapper/constants/azure.py rename to allms/constants/azure.py diff --git a/llm_wrapper/constants/input_data.py b/allms/constants/input_data.py similarity index 100% rename from llm_wrapper/constants/input_data.py rename to allms/constants/input_data.py diff --git a/llm_wrapper/constants/prompt.py b/allms/constants/prompt.py similarity index 100% rename from llm_wrapper/constants/prompt.py rename to allms/constants/prompt.py diff --git a/llm_wrapper/constants/vertex_ai.py b/allms/constants/vertex_ai.py similarity index 100% rename from llm_wrapper/constants/vertex_ai.py rename to allms/constants/vertex_ai.py diff --git a/llm_wrapper/defaults/__init__.py b/allms/defaults/__init__.py similarity index 100% rename from llm_wrapper/defaults/__init__.py rename to allms/defaults/__init__.py diff --git a/llm_wrapper/defaults/azure_defaults.py b/allms/defaults/azure_defaults.py similarity index 100% rename from llm_wrapper/defaults/azure_defaults.py rename to allms/defaults/azure_defaults.py diff --git a/llm_wrapper/defaults/general_defaults.py b/allms/defaults/general_defaults.py similarity index 100% rename from llm_wrapper/defaults/general_defaults.py rename to allms/defaults/general_defaults.py diff --git a/llm_wrapper/defaults/long_text_chain.py b/allms/defaults/long_text_chain.py similarity index 100% rename from llm_wrapper/defaults/long_text_chain.py rename to allms/defaults/long_text_chain.py diff --git a/llm_wrapper/defaults/vertex_ai.py b/allms/defaults/vertex_ai.py similarity index 100% rename from llm_wrapper/defaults/vertex_ai.py rename to allms/defaults/vertex_ai.py diff --git a/llm_wrapper/domain/__init__.py b/allms/domain/__init__.py similarity index 100% rename from llm_wrapper/domain/__init__.py rename to allms/domain/__init__.py diff --git a/llm_wrapper/domain/configuration.py b/allms/domain/configuration.py similarity index 100% rename from llm_wrapper/domain/configuration.py rename to allms/domain/configuration.py diff --git a/llm_wrapper/domain/enumerables.py b/allms/domain/enumerables.py similarity index 100% rename from llm_wrapper/domain/enumerables.py rename to allms/domain/enumerables.py diff --git a/llm_wrapper/domain/input_data.py b/allms/domain/input_data.py similarity index 100% rename from llm_wrapper/domain/input_data.py rename to allms/domain/input_data.py diff --git a/llm_wrapper/domain/prompt_dto.py b/allms/domain/prompt_dto.py similarity index 100% rename from llm_wrapper/domain/prompt_dto.py rename to allms/domain/prompt_dto.py diff --git a/llm_wrapper/domain/response.py b/allms/domain/response.py similarity index 91% rename from llm_wrapper/domain/response.py rename to allms/domain/response.py index 1745916..0dcf0dc 100644 --- a/llm_wrapper/domain/response.py +++ b/allms/domain/response.py @@ -2,7 +2,7 @@ from pydantic import BaseModel -from llm_wrapper.domain.input_data import InputData +from allms.domain.input_data import InputData class ResponseData(BaseModel): diff --git a/llm_wrapper/exceptions/__init__.py b/allms/exceptions/__init__.py similarity index 100% rename from llm_wrapper/exceptions/__init__.py rename to allms/exceptions/__init__.py diff --git a/llm_wrapper/exceptions/validation_input_data_exceptions.py b/allms/exceptions/validation_input_data_exceptions.py similarity index 100% rename from llm_wrapper/exceptions/validation_input_data_exceptions.py rename to allms/exceptions/validation_input_data_exceptions.py diff --git a/allms/models/__init__.py b/allms/models/__init__.py new file mode 100644 index 0000000..52c2da0 --- /dev/null +++ b/allms/models/__init__.py @@ -0,0 +1,7 @@ +from allms.models.azure_llama2 import AzureLlama2Model +from allms.models.azure_mistral import AzureMistralModel +from allms.models.azure_openai import AzureOpenAIModel +from allms.models.vertexai_gemini import VertexAIGeminiModel +from allms.models.vertexai_palm import VertexAIPalmModel + +__all__ = ["AzureOpenAIModel", "AzureLlama2Model", "AzureMistralModel", "VertexAIPalmModel", "VertexAIGeminiModel"] diff --git a/llm_wrapper/models/abstract.py b/allms/models/abstract.py similarity index 95% rename from llm_wrapper/models/abstract.py rename to allms/models/abstract.py index 6cf6fa6..18545f8 100644 --- a/llm_wrapper/models/abstract.py +++ b/allms/models/abstract.py @@ -17,21 +17,21 @@ from langchain.schema import OutputParserException from pydantic import BaseModel -from llm_wrapper.chains.long_text_processing_chain import ( +from allms.chains.long_text_processing_chain import ( LongTextProcessingChain, load_long_text_processing_chain ) -from llm_wrapper.constants.input_data import IODataConstants -from llm_wrapper.constants.prompt import PromptConstants -from llm_wrapper.defaults.general_defaults import GeneralDefaults -from llm_wrapper.domain.enumerables import AggregationLogicForLongInputData, LanguageModelTask - -from llm_wrapper.defaults.long_text_chain import LongTextChainDefaults -from llm_wrapper.domain.input_data import InputData -from llm_wrapper.domain.prompt_dto import SummaryOutputClass, KeywordsOutputClass -from llm_wrapper.domain.response import ResponseData -import llm_wrapper.exceptions.validation_input_data_exceptions as input_exception_message -from llm_wrapper.utils.long_text_processing_utils import get_max_allowed_number_of_tokens +from allms.constants.input_data import IODataConstants +from allms.constants.prompt import PromptConstants +from allms.defaults.general_defaults import GeneralDefaults +from allms.domain.enumerables import AggregationLogicForLongInputData, LanguageModelTask + +from allms.defaults.long_text_chain import LongTextChainDefaults +from allms.domain.input_data import InputData +from allms.domain.prompt_dto import SummaryOutputClass, KeywordsOutputClass +from allms.domain.response import ResponseData +import allms.exceptions.validation_input_data_exceptions as input_exception_message +from allms.utils.long_text_processing_utils import get_max_allowed_number_of_tokens logger = logging.getLogger(__name__) diff --git a/llm_wrapper/models/azure_base.py b/allms/models/azure_base.py similarity index 100% rename from llm_wrapper/models/azure_base.py rename to allms/models/azure_base.py diff --git a/llm_wrapper/models/azure_llama2.py b/allms/models/azure_llama2.py similarity index 82% rename from llm_wrapper/models/azure_llama2.py rename to allms/models/azure_llama2.py index 23bb9f6..05555dc 100644 --- a/llm_wrapper/models/azure_llama2.py +++ b/allms/models/azure_llama2.py @@ -1,11 +1,11 @@ import typing from asyncio import AbstractEventLoop -from llm_wrapper.defaults.azure_defaults import AzureLlama2Defaults -from llm_wrapper.defaults.general_defaults import GeneralDefaults -from llm_wrapper.domain.configuration import AzureSelfDeployedConfiguration -from llm_wrapper.models.abstract import AbstractModel -from llm_wrapper.models.azure_base import AzureMLOnlineEndpointAsync, ChatModelContentFormatter +from allms.defaults.azure_defaults import AzureLlama2Defaults +from allms.defaults.general_defaults import GeneralDefaults +from allms.domain.configuration import AzureSelfDeployedConfiguration +from allms.models.abstract import AbstractModel +from allms.models.azure_base import AzureMLOnlineEndpointAsync, ChatModelContentFormatter class AzureLlama2Model(AbstractModel): diff --git a/llm_wrapper/models/azure_mistral.py b/allms/models/azure_mistral.py similarity index 82% rename from llm_wrapper/models/azure_mistral.py rename to allms/models/azure_mistral.py index 43e473c..1af75cf 100644 --- a/llm_wrapper/models/azure_mistral.py +++ b/allms/models/azure_mistral.py @@ -1,11 +1,11 @@ import typing from asyncio import AbstractEventLoop -from llm_wrapper.defaults.azure_defaults import AzureMistralAIDefaults -from llm_wrapper.defaults.general_defaults import GeneralDefaults -from llm_wrapper.domain.configuration import AzureSelfDeployedConfiguration -from llm_wrapper.models.abstract import AbstractModel -from llm_wrapper.models.azure_base import AzureMLOnlineEndpointAsync, ChatModelContentFormatter +from allms.defaults.azure_defaults import AzureMistralAIDefaults +from allms.defaults.general_defaults import GeneralDefaults +from allms.domain.configuration import AzureSelfDeployedConfiguration +from allms.models.abstract import AbstractModel +from allms.models.azure_base import AzureMLOnlineEndpointAsync, ChatModelContentFormatter class AzureMistralModel(AbstractModel): diff --git a/llm_wrapper/models/azure_openai.py b/allms/models/azure_openai.py similarity index 86% rename from llm_wrapper/models/azure_openai.py rename to allms/models/azure_openai.py index f796253..2007b02 100644 --- a/llm_wrapper/models/azure_openai.py +++ b/allms/models/azure_openai.py @@ -3,10 +3,10 @@ from langchain.chat_models import AzureChatOpenAI -from llm_wrapper.defaults.azure_defaults import AzureGptTurboDefaults -from llm_wrapper.defaults.general_defaults import GeneralDefaults -from llm_wrapper.domain.configuration import AzureOpenAIConfiguration -from llm_wrapper.models.abstract import AbstractModel +from allms.defaults.azure_defaults import AzureGptTurboDefaults +from allms.defaults.general_defaults import GeneralDefaults +from allms.domain.configuration import AzureOpenAIConfiguration +from allms.models.abstract import AbstractModel class AzureOpenAIModel(AbstractModel): diff --git a/llm_wrapper/models/vertexai_base.py b/allms/models/vertexai_base.py similarity index 96% rename from llm_wrapper/models/vertexai_base.py rename to allms/models/vertexai_base.py index b5803b1..e4b51f5 100644 --- a/llm_wrapper/models/vertexai_base.py +++ b/allms/models/vertexai_base.py @@ -5,7 +5,7 @@ from langchain_core.outputs import LLMResult, Generation from pydash import chain -from llm_wrapper.constants.vertex_ai import VertexModelConstants +from allms.constants.vertex_ai import VertexModelConstants class CustomVertexAI(VertexAI): async def _agenerate( diff --git a/llm_wrapper/models/vertexai_gemini.py b/allms/models/vertexai_gemini.py similarity index 84% rename from llm_wrapper/models/vertexai_gemini.py rename to allms/models/vertexai_gemini.py index 47e16aa..4dac9f3 100644 --- a/llm_wrapper/models/vertexai_gemini.py +++ b/allms/models/vertexai_gemini.py @@ -2,11 +2,11 @@ from langchain_community.llms.vertexai import VertexAI from typing import Optional -from llm_wrapper.defaults.general_defaults import GeneralDefaults -from llm_wrapper.defaults.vertex_ai import GeminiModelDefaults -from llm_wrapper.domain.configuration import VertexAIConfiguration -from llm_wrapper.models.vertexai_base import CustomVertexAI -from llm_wrapper.models.abstract import AbstractModel +from allms.defaults.general_defaults import GeneralDefaults +from allms.defaults.vertex_ai import GeminiModelDefaults +from allms.domain.configuration import VertexAIConfiguration +from allms.models.vertexai_base import CustomVertexAI +from allms.models.abstract import AbstractModel class VertexAIGeminiModel(AbstractModel): diff --git a/llm_wrapper/models/vertexai_palm.py b/allms/models/vertexai_palm.py similarity index 84% rename from llm_wrapper/models/vertexai_palm.py rename to allms/models/vertexai_palm.py index dee4853..860fe50 100644 --- a/llm_wrapper/models/vertexai_palm.py +++ b/allms/models/vertexai_palm.py @@ -2,11 +2,11 @@ from langchain_community.llms.vertexai import VertexAI from typing import Optional -from llm_wrapper.defaults.general_defaults import GeneralDefaults -from llm_wrapper.defaults.vertex_ai import PalmModelDefaults -from llm_wrapper.domain.configuration import VertexAIConfiguration -from llm_wrapper.models.vertexai_base import CustomVertexAI -from llm_wrapper.models.abstract import AbstractModel +from allms.defaults.general_defaults import GeneralDefaults +from allms.defaults.vertex_ai import PalmModelDefaults +from allms.domain.configuration import VertexAIConfiguration +from allms.models.vertexai_base import CustomVertexAI +from allms.models.abstract import AbstractModel class VertexAIPalmModel(AbstractModel): diff --git a/llm_wrapper/utils/__init__.py b/allms/utils/__init__.py similarity index 100% rename from llm_wrapper/utils/__init__.py rename to allms/utils/__init__.py diff --git a/llm_wrapper/utils/io_utils.py b/allms/utils/io_utils.py similarity index 88% rename from llm_wrapper/utils/io_utils.py rename to allms/utils/io_utils.py index 6a2e04d..bc36edf 100644 --- a/llm_wrapper/utils/io_utils.py +++ b/allms/utils/io_utils.py @@ -5,8 +5,8 @@ import fsspec import pandas as pd -from llm_wrapper.constants.input_data import IODataConstants -from llm_wrapper.domain.input_data import InputData +from allms.constants.input_data import IODataConstants +from allms.domain.input_data import InputData logger = logging.getLogger(__name__) diff --git a/llm_wrapper/utils/logger_utils.py b/allms/utils/logger_utils.py similarity index 100% rename from llm_wrapper/utils/logger_utils.py rename to allms/utils/logger_utils.py diff --git a/llm_wrapper/utils/long_text_processing_utils.py b/allms/utils/long_text_processing_utils.py similarity index 98% rename from llm_wrapper/utils/long_text_processing_utils.py rename to allms/utils/long_text_processing_utils.py index 14dc18e..ba72078 100644 --- a/llm_wrapper/utils/long_text_processing_utils.py +++ b/allms/utils/long_text_processing_utils.py @@ -4,7 +4,7 @@ from langchain.base_language import BaseLanguageModel from langchain.schema import Document -from llm_wrapper.defaults.long_text_chain import LongTextChainDefaults +from allms.defaults.long_text_chain import LongTextChainDefaults def truncate_text_to_max_size( diff --git a/docs/api/input_output_dataclasses.md b/docs/api/input_output_dataclasses.md index 777bea7..9aac10c 100644 --- a/docs/api/input_output_dataclasses.md +++ b/docs/api/input_output_dataclasses.md @@ -1,4 +1,4 @@ -## `class llm_wrapper.domain.input_data.InputData` dataclass +## `class allms.domain.input_data.InputData` dataclass ```python @dataclass class InputData: @@ -12,7 +12,7 @@ class InputData: - `id` (`str`): Unique identifier. Requests are done in an async mode, so the order of the responses is not the same as the order of the input data, so this field can be used to identify them. -## `class llm_wrapper.domain.response.ResponseData` dataclass +## `class allms.domain.response.ResponseData` dataclass ```python @dataclass class ResponseData: diff --git a/docs/api/models/azure_llama2_model.md b/docs/api/models/azure_llama2_model.md index 613efcb..469c248 100644 --- a/docs/api/models/azure_llama2_model.md +++ b/docs/api/models/azure_llama2_model.md @@ -1,4 +1,4 @@ -## `class llm_wrapper.models.AzureLlama2Model` API +## `class allms.models.AzureLlama2Model` API ### Methods ```python __init__( @@ -48,6 +48,7 @@ is not provided, the length of this list is equal 1, and the first element is th --- +## `class allms.domain.configuration.AzureSelfDeployedConfiguration` API ```python AzureSelfDeployedConfiguration( api_key: str, @@ -63,9 +64,10 @@ AzureSelfDeployedConfiguration( --- ### Example usage + ```python -from llm_wrapper.models import AzureLlama2Model -from llm_wrapper.domain.configuration import AzureSelfDeployedConfiguration +from allms.models import AzureLlama2Model +from allms.domain.configuration import AzureSelfDeployedConfiguration configuration = AzureSelfDeployedConfiguration( api_key="", diff --git a/docs/api/models/azure_mistral_model.md b/docs/api/models/azure_mistral_model.md index af459b7..19d90f1 100644 --- a/docs/api/models/azure_mistral_model.md +++ b/docs/api/models/azure_mistral_model.md @@ -1,4 +1,4 @@ -## `class llm_wrapper.models.AzureMistralModel` API +## `class allms.models.AzureMistralModel` API ### Methods ```python __init__( @@ -48,6 +48,7 @@ is not provided, the length of this list is equal 1, and the first element is th --- +## `class allms.domain.configuration.AzureSelfDeployedConfiguration` API ```python AzureSelfDeployedConfiguration( api_key: str, @@ -63,9 +64,10 @@ AzureSelfDeployedConfiguration( --- ### Example usage + ```python -from llm_wrapper.models import AzureMistralModel -from llm_wrapper.domain.configuration import AzureSelfDeployedConfiguration +from allms.models import AzureMistralModel +from allms.domain.configuration import AzureSelfDeployedConfiguration configuration = AzureSelfDeployedConfiguration( api_key="", diff --git a/docs/api/models/azure_openai_model.md b/docs/api/models/azure_openai_model.md index ed812e8..cc73255 100644 --- a/docs/api/models/azure_openai_model.md +++ b/docs/api/models/azure_openai_model.md @@ -1,4 +1,4 @@ -## `class llm_wrapper.models.AzureOpenAIModel` API +## `class allms.models.AzureOpenAIModel` API ### Methods ```python __init__( @@ -48,6 +48,7 @@ is not provided, the length of this list is equal 1, and the first element is th --- +## `class allms.domain.configuration.AzureOpenAIConfiguration` API ```python AzureOpenAIConfiguration( api_key: str, @@ -70,9 +71,10 @@ Sets up the environment for the `AzureOpenAIModel` model. --- ### Example usage + ```python -from llm_wrapper.models import AzureOpenAIModel -from llm_wrapper.domain.configuration import AzureOpenAIConfiguration +from allms.models import AzureOpenAIModel +from allms.domain.configuration import AzureOpenAIConfiguration configuration = AzureOpenAIConfiguration( api_key="", diff --git a/docs/api/models/vertexai_gemini_model.md b/docs/api/models/vertexai_gemini_model.md index db6ba9b..02bb4ed 100644 --- a/docs/api/models/vertexai_gemini_model.md +++ b/docs/api/models/vertexai_gemini_model.md @@ -1,4 +1,4 @@ -## `class llm_wrapper.models.VertexAIGeminiModel` API +## `class allms.models.VertexAIGeminiModel` API ### Methods ```python __init__( @@ -53,6 +53,7 @@ is not provided, the length of this list is equal 1, and the first element is th --- +## `class allms.domain.configuration.VertexAIConfiguration` API ```python VertexAIConfiguration( cloud_project: str, @@ -66,9 +67,10 @@ VertexAIConfiguration( --- ### Example usage + ```python -from llm_wrapper.models import VertexAIGeminiModel -from llm_wrapper.domain.configuration import VertexAIConfiguration +from allms.models import VertexAIGeminiModel +from allms.domain.configuration import VertexAIConfiguration configuration = VertexAIConfiguration( cloud_project="", diff --git a/docs/api/models/vertexai_palm_model.md b/docs/api/models/vertexai_palm_model.md index acfd91b..7729387 100644 --- a/docs/api/models/vertexai_palm_model.md +++ b/docs/api/models/vertexai_palm_model.md @@ -1,4 +1,4 @@ -## `class llm_wrapper.models.VertexAIPalmModel` API +## `class allms.models.VertexAIPalmModel` API ### Methods ```python __init__( @@ -53,6 +53,7 @@ is not provided, the length of this list is equal 1, and the first element is th --- +## `class allms.domain.configuration.VertexAIConfiguration` API ```python VertexAIConfiguration( cloud_project: str, @@ -66,9 +67,10 @@ VertexAIConfiguration( --- ### Example usage + ```python -from llm_wrapper.models import VertexAIPalmModel -from llm_wrapper.domain.configuration import VertexAIConfiguration +from allms.models import VertexAIPalmModel +from allms.domain.configuration import VertexAIConfiguration configuration = VertexAIConfiguration( cloud_project="", diff --git a/docs/faq.md b/docs/faq.md index b2b3d20..1448e7a 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -1,8 +1,8 @@ # Frequently Asked Questions -### 1. How to use the llm-wrapper in a python notebook? -When using the `llm-wrapper` library, which utilizes asynchronous programming under the hood, you must install the `nest-asyncio` library to use it in a Jupyter notebook environment. +### 1. How to use the allms in a python notebook? +When using the `allms` library, which utilizes asynchronous programming under the hood, you must install the `nest-asyncio` library to use it in a Jupyter notebook environment. To ensure proper functionality, execute the following code at the beginning of your notebook: ```jupyterpython diff --git a/docs/index.md b/docs/index.md index 1c5b0e8..aee5de9 100644 --- a/docs/index.md +++ b/docs/index.md @@ -4,7 +4,7 @@ # Introduction -`llm-wrapper` is a versatile and powerful library designed to streamline the process of querying large language models, offering a user-friendly experience. The `llm-wrapper` module is designed to simplify interactions with the underlying model by providing the following features: +`allms` is a versatile and powerful library designed to streamline the process of querying large language models, offering a user-friendly experience. The `allms` module is designed to simplify interactions with the underlying model by providing the following features: - **Simple and User-Friendly Interface**: The module offers an intuitive and easy-to-use interface, making it straightforward to work with the model. diff --git a/docs/installation_and_quick_start.md b/docs/installation_and_quick_start.md index 85fb4a1..a23c8d6 100644 --- a/docs/installation_and_quick_start.md +++ b/docs/installation_and_quick_start.md @@ -2,7 +2,7 @@ Install the package via pip: ```bash -pip install llm-wrapper +pip install allms ``` # Quick Start @@ -16,8 +16,8 @@ that must be passed in the corresponding configuration object. Below is a brief ### Azure GPT ```python -from llm_wrapper.models import AzureOpenAIModel -from llm_wrapper.domain.configuration import AzureOpenAIConfiguration +from allms.models import AzureOpenAIModel +from allms.domain.configuration import AzureOpenAIConfiguration configuration = AzureOpenAIConfiguration( api_key="", @@ -42,8 +42,8 @@ gpt_response = gpt_model.generate("2+2 is?") ### Google PaLM ```python -from llm_wrapper.models import VertexAIPalmModel -from llm_wrapper.domain.configuration import VertexAIConfiguration +from allms.models import VertexAIPalmModel +from allms.domain.configuration import VertexAIConfiguration configuration = VertexAIConfiguration( cloud_project="", @@ -60,8 +60,8 @@ palm_response = palm_model.generate("2+2 is?") ### Google Gemini ```python -from llm_wrapper.models import VertexAIGeminiModel -from llm_wrapper.domain.configuration import VertexAIConfiguration +from allms.models import VertexAIGeminiModel +from allms.domain.configuration import VertexAIConfiguration configuration = VertexAIConfiguration( cloud_project="", @@ -78,8 +78,8 @@ gemini_response = gemini_model.generate("2+2 is?") ### Azure LLaMA 2 ```python -from llm_wrapper.models import AzureLlama2Model -from llm_wrapper.domain.configuration import AzureSelfDeployedConfiguration +from allms.models import AzureLlama2Model +from allms.domain.configuration import AzureSelfDeployedConfiguration configuration = AzureSelfDeployedConfiguration( api_key="", @@ -98,8 +98,8 @@ llama_response = llama_model.generate("2+2 is?") ### Azure Mistral ```python -from llm_wrapper.models.azure_mistral import AzureMistralModel -from llm_wrapper.domain.configuration import AzureSelfDeployedConfiguration +from allms.models.azure_mistral import AzureMistralModel +from allms.domain.configuration import AzureSelfDeployedConfiguration configuration = AzureSelfDeployedConfiguration( api_key="", diff --git a/docs/usage/advanced.md b/docs/usage/advanced.md index 9516d83..29cff44 100644 --- a/docs/usage/advanced.md +++ b/docs/usage/advanced.md @@ -3,14 +3,15 @@ ## Symbolic Variables and Batch Mode If you want to generate responses for a batch of examples, you can achieve this by preparing a prompt with symbolic -variables and providing input data that will be injected into this prompt. `llm-wrapper` will automatically make these +variables and providing input data that will be injected into this prompt. `allms` will automatically make these requests in an async mode and retry them in case of any API error. Let's say we want to classify reviews of coffee as positive or negative. Here's how to do it: + ```python -from llm_wrapper.models import AzureOpenAIModel -from llm_wrapper.domain.configuration import AzureOpenAIConfiguration -from llm_wrapper.domain.input_data import InputData +from allms.models import AzureOpenAIModel +from allms.domain.configuration import AzureOpenAIConfiguration +from allms.domain.input_data import InputData configuration = AzureOpenAIConfiguration( api_key="", @@ -80,7 +81,7 @@ And the results: ``` ## Controlling the Number of Concurrent Requests -As it's written above, `llm-wrapper` automatically makes requests in an async mode. By default, the maximum number of +As it's written above, `allms` automatically makes requests in an async mode. By default, the maximum number of concurrent requests is set to 1000. You can control this value by setting the `max_concurrency` parameter when initializing the model. Set it to a value that is appropriate for your model endpoint. @@ -91,9 +92,8 @@ a common loop for multiple models or to have a custom loop, it's possible to spe ```python import asyncio -from llm_wrapper.models import AzureOpenAIModel -from llm_wrapper.domain.configuration import AzureOpenAIConfiguration - +from allms.models import AzureOpenAIModel +from allms.domain.configuration import AzureOpenAIConfiguration custom_event_loop = asyncio.new_event_loop() diff --git a/docs/usage/basic.md b/docs/usage/basic.md index b4224b0..dae4af2 100644 --- a/docs/usage/basic.md +++ b/docs/usage/basic.md @@ -2,12 +2,12 @@ ## Single Query -In the simplest approach you just need to pass a prompt and the model will provide a response for it. +In the simplest approach you just need to pass a prompt and the model will provide a response for it. ```python -from llm_wrapper.models import AzureOpenAIModel -from llm_wrapper.domain.configuration import AzureOpenAIConfiguration -from llm_wrapper.domain.response import ResponseData +from allms.models import AzureOpenAIModel +from allms.domain.configuration import AzureOpenAIConfiguration +from allms.domain.response import ResponseData configuration = AzureOpenAIConfiguration( api_key="", @@ -22,7 +22,7 @@ model = AzureOpenAIModel(config=configuration) response = model.generate("What is the capital of Poland?") print(response) -#[ResponseData(response='The capital of Poland is Warsaw.', input_data=None, number_of_prompt_tokens=7, number_of_generated_tokens=7, error=None)] +# [ResponseData(response='The capital of Poland is Warsaw.', input_data=None, number_of_prompt_tokens=7, number_of_generated_tokens=7, error=None)] ``` As a response you'll get `List[ResponseData]`, where the first element will contain response from the model in the diff --git a/docs/usage/deploy_open_source_models.md b/docs/usage/deploy_open_source_models.md index 9cf2daa..08294b7 100644 --- a/docs/usage/deploy_open_source_models.md +++ b/docs/usage/deploy_open_source_models.md @@ -1,7 +1,7 @@ # How to Deploy Azure Open-source LLMs? -To use Open-source models like Llama or Mistral with llm-wrapper, first you have to deploy it on your own on Azure as a ML Online Endpoint. +To use Open-source models like Llama or Mistral with allms, first you have to deploy it on your own on Azure as a ML Online Endpoint. Here's how to do it: 1. Go to [ml.azure.com](https://ml.azure.com/) and use a subscription with a workspace that has access to the @@ -14,8 +14,22 @@ Here's how to do it: 7. In the menu on the left, click `Endpoints` and select the endpoint you've just created. 8. After the deployment is complete, you'll see `Consume` tab where the endpoint URL and authentication key will be provided. -9. Now you can start using the model by providing the API key, endpoint URL and deployment name to - `llm_wrapper.models.AzureLlama2Model` +9. Now you can start using the model by configuring it as in the example below: + +```python +from allms.models import AzureLlama2Model +from allms.domain.configuration import AzureSelfDeployedConfiguration + +configuration = AzureSelfDeployedConfiguration( + api_key="", + endpoint_url="", + deployment="" +) + +llama_model = AzureLlama2Model(config=configuration) +llama_response = llama_model.generate("2+2 is?") +``` + In case of any problems with deployment, you can review this guide on the Azure blog: [Introducing Llama 2 on Azure](https://techcommunity.microsoft.com/t5/ai-machine-learning-blog/introducing-llama-2-on-azure/ba-p/3881233) diff --git a/docs/usage/error_handling.md b/docs/usage/error_handling.md index b1a0056..21aec4c 100644 --- a/docs/usage/error_handling.md +++ b/docs/usage/error_handling.md @@ -2,7 +2,7 @@ ## Too long prompt Each LLM has its own context size defined. This is the maximum number of input plus output tokens that the model is able -to consume. `llm-wrapper` before sending the request to the model automatically checks if your input data will fit into +to consume. `allms` before sending the request to the model automatically checks if your input data will fit into the model's context size and if not it'll either: - raise `ValueError` saying that your prompt is too long if the prompt alone has already more tokens than the allowed maximum context size of the model @@ -24,14 +24,14 @@ split the whole input into shorter chunks, process them separately and combine t ## Output parsing errors If you use the [Forcing model response format](forcing_response_format.md) functionality, sometimes the model can -generate a response that actually doesn't comform to the provided output data schema. In this case, `llm-wrapper` won't +generate a response that actually doesn't comform to the provided output data schema. In this case, `allms` won't be able to parse the output to the provided output data model class. So as a response you'll get a `ResponseData` where `ResponseData.response` will be a raw, unparsed response from the model, and the `ResponseData.error` will be `OutputParserException`. ## API errors -`llm-wrapper` automatically retries failed requests. But even with this feature, the model can fail to return a response +`allms` automatically retries failed requests. But even with this feature, the model can fail to return a response more times than the maximum number of retries (which is currently set to 8) or some other unexpected errors may occur. In all of these cases, `ResponseData.error` will contain the exception that occurred. So a good rule of thumb is to first check the `ResponseData.error` and only if it's empty move to processing the response of the model. \ No newline at end of file diff --git a/docs/usage/forcing_response_format.md b/docs/usage/forcing_response_format.md index d9bfbdf..b348c05 100644 --- a/docs/usage/forcing_response_format.md +++ b/docs/usage/forcing_response_format.md @@ -2,7 +2,7 @@ ## Pydantic BaseModels Integration -If you want to force the model to output the response in a given JSON schema, `llm-wrapper` provides an easy way to do +If you want to force the model to output the response in a given JSON schema, `allms` provides an easy way to do it. You just need to provide a data model that describes the desired output format and the package does all the rest. As an output you get string already parsed to a provided data model class. @@ -25,7 +25,7 @@ class ReviewOutputDataModel(BaseModel): cons: typing.List[str] = Field(description="List of cons of the coffee") ``` -2. Provide the data model class together with prompt and input data to the `.generate()` method. `llm-wrapper` will +2. Provide the data model class together with prompt and input data to the `.generate()` method. `allms` will automatically force the model to output the data in the provided format and will parse the string returned from the model to the provided data model class. @@ -75,7 +75,7 @@ few-shot learning techniques is also advisable. In the case of JSON-like output, to use them in the JSON example. ## How forcing response format works under the hood? -To force the model to provide output in a desired format, under the hood `llm-wrapper` automatically adds a description +To force the model to provide output in a desired format, under the hood `allms` automatically adds a description of the desired output format. For example, for the `ReviewOutputDataModel` the description looks like this: ````text diff --git a/examples/introduction.ipynb b/examples/introduction.ipynb index e7ac9ee..6ea261d 100644 --- a/examples/introduction.ipynb +++ b/examples/introduction.ipynb @@ -5,7 +5,7 @@ "source": [ "# Introduction\n", "\n", - "Follow this tutorial to get to know the most important features of llm-wrapper!\n", + "Follow this tutorial to get to know the most important features of allms!\n", "\n" ], "metadata": { @@ -46,7 +46,7 @@ "source": [ "## Setting up your LLM\n", "\n", - "To start working with `llm-wrapper` you need to import one of the supported models and configure it. Make sure to have access to an Azure OpenAI endpoint and dispose of the needed information. In this tutorial we are going to use a GPT model." + "To start working with `allms` you need to import one of the supported models and configure it. Make sure to have access to an Azure OpenAI endpoint and dispose of the needed information. In this tutorial we are going to use a GPT model." ] }, { @@ -67,8 +67,8 @@ }, "outputs": [], "source": [ - "from llm_wrapper.models import AzureOpenAIModel\n", - "from llm_wrapper.domain.configuration import AzureOpenAIConfiguration\n", + "from allms.models import AzureOpenAIModel\n", + "from allms.domain.configuration import AzureOpenAIConfiguration\n", "\n", "configuration = AzureOpenAIConfiguration(\n", " api_key=\"your-secret-api-key\",\n", @@ -173,7 +173,7 @@ } ], "source": [ - "from llm_wrapper.domain.input_data import InputData\n", + "from allms.domain.input_data import InputData\n", "\n", "\n", "positive_review_0 = \"Very good coffee, lightly roasted, with good aroma and taste. The taste of sourness is barely noticeable (which is good because I don't like sour coffees). After grinding, the aroma spreads throughout the room. I recommend it to all those who do not like strongly roasted and pitch-black coffees. A very good solution is to close the package with string, which allows you to preserve the aroma and freshness.\"\n", diff --git a/llm_wrapper/models/__init__.py b/llm_wrapper/models/__init__.py deleted file mode 100644 index 196cb79..0000000 --- a/llm_wrapper/models/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -from llm_wrapper.models.azure_llama2 import AzureLlama2Model -from llm_wrapper.models.azure_mistral import AzureMistralModel -from llm_wrapper.models.azure_openai import AzureOpenAIModel -from llm_wrapper.models.vertexai_gemini import VertexAIGeminiModel -from llm_wrapper.models.vertexai_palm import VertexAIPalmModel - -__all__ = ["AzureOpenAIModel", "AzureLlama2Model", "AzureMistralModel", "VertexAIPalmModel", "VertexAIGeminiModel"] diff --git a/mkdocs.yml b/mkdocs.yml index 184c972..e492835 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,4 +1,4 @@ -site_name: llm-wrapper +site_name: allms theme: readthedocs nav: - Introduction: index.md diff --git a/pyproject.toml b/pyproject.toml index 5e05ff0..1684f2c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,10 @@ [tool.poetry] -name = "llm-wrapper" -version = "0.0.1.1" +name = "allms" +version = "0.0.1.1" # TODO: change it to 1.0.0 for the first release description = "" authors = ["Allegro Opensource "] readme = "README.md" -packages = [{include = "llm_wrapper"}] +packages = [{include = "allms"}] [tool.poetry.dependencies] python = "^3.10" diff --git a/tests/conftest.py b/tests/conftest.py index 5e1e542..256b13d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,10 +5,10 @@ import pytest from aioresponses import aioresponses -from llm_wrapper.domain.configuration import AzureOpenAIConfiguration, AzureSelfDeployedConfiguration, VertexAIConfiguration -from llm_wrapper.models import AzureOpenAIModel, VertexAIPalmModel, AzureLlama2Model -from llm_wrapper.models.azure_mistral import AzureMistralModel -from llm_wrapper.models.vertexai_gemini import VertexAIGeminiModel +from allms.domain.configuration import AzureOpenAIConfiguration, AzureSelfDeployedConfiguration, VertexAIConfiguration +from allms.models import AzureOpenAIModel, VertexAIPalmModel, AzureLlama2Model +from allms.models.azure_mistral import AzureMistralModel +from allms.models.vertexai_gemini import VertexAIGeminiModel class AzureOpenAIEnv: diff --git a/tests/test_end_to_end.py b/tests/test_end_to_end.py index 2963a86..531bba7 100644 --- a/tests/test_end_to_end.py +++ b/tests/test_end_to_end.py @@ -2,8 +2,8 @@ import pandas as pd -from llm_wrapper.domain.prompt_dto import KeywordsOutputClass -from llm_wrapper.utils import io_utils +from allms.domain.prompt_dto import KeywordsOutputClass +from allms.utils import io_utils from tests.conftest import AzureOpenAIEnv diff --git a/tests/test_model_behavior_for_different_input_data.py b/tests/test_model_behavior_for_different_input_data.py index 0d4c19a..77d628c 100644 --- a/tests/test_model_behavior_for_different_input_data.py +++ b/tests/test_model_behavior_for_different_input_data.py @@ -1,12 +1,12 @@ import logging -import llm_wrapper.exceptions.validation_input_data_exceptions as input_validation_messages +import allms.exceptions.validation_input_data_exceptions as input_validation_messages from unittest.mock import patch import pytest -from llm_wrapper.domain.input_data import InputData -from llm_wrapper.domain.response import ResponseData +from allms.domain.input_data import InputData +from allms.domain.response import ResponseData class TestModelBehaviorForDifferentInput: diff --git a/tests/test_output_parser.py b/tests/test_output_parser.py index cc17f86..5e02556 100644 --- a/tests/test_output_parser.py +++ b/tests/test_output_parser.py @@ -3,8 +3,8 @@ from langchain.schema import OutputParserException -from llm_wrapper.domain.input_data import InputData -from llm_wrapper.domain.prompt_dto import SummaryOutputClass, KeywordsOutputClass +from allms.domain.input_data import InputData +from allms.domain.prompt_dto import SummaryOutputClass, KeywordsOutputClass class TestOutputModelParserForDifferentModelOutputs: