donkey-llms-litellm 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,85 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ #IDE
10
+ .DS_Store
11
+ .idea
12
+ .vscode
13
+
14
+ # Distribution / packaging
15
+ .Python
16
+ build/
17
+ develop-eggs/
18
+ dist/
19
+ downloads/
20
+ eggs/
21
+ .eggs/
22
+ lib/
23
+ lib64/
24
+ parts/
25
+ sdist/
26
+ var/
27
+ wheels/
28
+ share/python-wheels/
29
+ *.egg-info/
30
+ .installed.cfg
31
+ *.egg
32
+ MANIFEST
33
+
34
+ # PyInstaller
35
+ # Usually these files are written by a python script from a template
36
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
37
+ *.manifest
38
+ *.spec
39
+
40
+ # Installer logs
41
+ pip-log.txt
42
+ pip-delete-this-directory.txt
43
+
44
+ # Unit test / coverage reports
45
+ htmlcov/
46
+ .tox/
47
+ .nox/
48
+ .coverage
49
+ .coverage.*
50
+ .cache
51
+ nosetests.xml
52
+ coverage.xml
53
+ *.cover
54
+ *.py,cover
55
+ .hypothesis/
56
+ .pytest_cache/
57
+ cover/
58
+
59
+ # Mkdocs documentation
60
+ docs/_build/
61
+ docs/api_reference/site/
62
+
63
+ # Ruff
64
+ .ruff_cache/
65
+
66
+ # PyBuilder
67
+ .pybuilder/
68
+ target/
69
+
70
+ # Jupyter Notebook
71
+ .ipynb_checkpoints
72
+
73
+ # pyenv
74
+ # For a library or package, you might want to ignore these files since the code is
75
+ # intended to run in multiple environments; otherwise, check them in:
76
+ .python-version
77
+
78
+ # Environments
79
+ .env
80
+ .venv
81
+ env/
82
+ venv/
83
+ ENV/
84
+ env.bak/
85
+ venv.bak/
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.4
2
+ Name: donkey-llms-litellm
3
+ Version: 0.1.0
4
+ Summary: donkey llms LiteLLM integration
5
+ Author-email: Leonardo Furnielis <leonardofurnielis@outlook.com>
6
+ License: Apache-2.0
7
+ Requires-Python: <3.14,>=3.11
8
+ Requires-Dist: donkey-core<0.2.0,>=0.1.0
9
+ Requires-Dist: litellm<1.85.0,>=1.84.0
10
+ Provides-Extra: dev
11
+ Requires-Dist: pytest-asyncio<2.0.0,>=1.4.0; extra == 'dev'
12
+ Requires-Dist: pytest<10.0.0,>=9.1.1; extra == 'dev'
13
+ Requires-Dist: ruff<0.16.0,>=0.15.20; extra == 'dev'
14
+ Description-Content-Type: text/markdown
15
+
16
+ # Donkey llms integration - LiteLLM
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ pip install donkey-llms-litellm
22
+ ```
@@ -0,0 +1,7 @@
1
+ # Donkey llms integration - LiteLLM
2
+
3
+ ## Installation
4
+
5
+ ```bash
6
+ pip install donkey-llms-litellm
7
+ ```
@@ -0,0 +1,3 @@
1
+ from donkey.llms.litellm.base import LiteLLM
2
+
3
+ __all__ = ["LiteLLM"]
@@ -0,0 +1,90 @@
1
+ from typing import Any
2
+
3
+ from donkey.core.bridge.pydantic import Field, SecretStr
4
+ from donkey.core.llms import BaseLLM, ChatMessage, ChatResponse, CompletionResponse
5
+
6
+ import litellm
7
+
8
+
9
+ class LiteLLM(BaseLLM):
10
+ """
11
+ A wrapper class for interacting with a LiteLLM-compatible large language model (LLM).
12
+ For more information, see: [https://docs.litellm.ai/](https://docs.litellm.ai/).
13
+
14
+ Attributes:
15
+ model (str): The identifier of the LLM model to use (e.g., "gpt-4", "llama-3").
16
+ temperature (float, optional): Sampling temperature to use. Must be between 0.0 and 1.0.
17
+ Higher values result in more random outputs, while lower values make the
18
+ output more deterministic. Default is 1.0.
19
+ max_tokens (int, optional): The maximum number of tokens to generate in the completion.
20
+ api_key (str): API key used for authenticating with the LLM provider.
21
+ additional_kwargs (dict[str, Any], optional): A dictionary of additional parameters passed
22
+ to the LLM during completion. This allows customization of the request beyond
23
+ the standard parameters.
24
+ callback_manager: (BaseObservability, optional): The callback manager is used for observability.
25
+
26
+ Example:
27
+ ```python
28
+ from donkey.llms.litellm import LiteLLM
29
+
30
+ llm = LiteLLM(model="gpt-4", api_key="your_api_key_here")
31
+ ```
32
+ """
33
+
34
+ model: str
35
+ temperature: float = Field(
36
+ default=1.0,
37
+ ge=0.0,
38
+ le=1.0,
39
+ description="The temperature to use. Higher values make the output more random, "
40
+ "while lower values make it more focused and deterministic.",
41
+ )
42
+ max_tokens: int = Field(ge=0)
43
+ api_key: SecretStr
44
+ additional_kwargs: dict[str, Any] = Field(default_factory=dict)
45
+
46
+ def _get_all_kwargs(self, **kwargs: Any) -> dict[str, Any]:
47
+ return {
48
+ "temperature": self.temperature,
49
+ "max_tokens": self.max_tokens,
50
+ **self.additional_kwargs,
51
+ **kwargs, # Method-provided kwargs override class-level kwargs
52
+ "model": self.model, # Always enforced from class
53
+ "api_key": self.api_key.get_secret_value(), # Always enforced from class
54
+ }
55
+
56
+ def _completion(self, prompt: str, **kwargs: Any) -> CompletionResponse:
57
+ """Creates a completion for the provided prompt and parameters. Using OpenAI's standard endpoint (/completions)."""
58
+ all_kwargs = self._get_all_kwargs(**kwargs)
59
+
60
+ response = litellm.text_completion(prompt=prompt, **all_kwargs).model_dump(
61
+ exclude_none=True
62
+ )
63
+
64
+ return CompletionResponse(
65
+ text=response["choices"][0]["text"],
66
+ input_token_count=response.get("usage", {}).get("prompt_tokens"),
67
+ generated_token_count=response.get("usage", {}).get("completion_tokens"),
68
+ raw=response,
69
+ )
70
+
71
+ def _chat_completion(
72
+ self, messages: list[ChatMessage | dict], **kwargs: Any
73
+ ) -> ChatResponse:
74
+ """Creates a chat completion for LLM. Using OpenAI's standard endpoint (/chat/completions)."""
75
+ all_kwargs = self._get_all_kwargs(**kwargs)
76
+ input_messages_dict = [
77
+ ChatMessage.model_validate(message).to_dict() for message in messages
78
+ ]
79
+
80
+ response = litellm.completion(
81
+ messages=input_messages_dict, **all_kwargs
82
+ ).model_dump(exclude_none=True)
83
+ message_dict = response["choices"][0]["message"]
84
+
85
+ return ChatResponse(
86
+ message=ChatMessage(
87
+ role=message_dict.get("role"), content=message_dict.get("content", None)
88
+ ),
89
+ raw=response,
90
+ )
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "donkey-llms-litellm"
7
+ version = "0.1.0"
8
+ description = "donkey llms LiteLLM integration"
9
+ authors = [{ name = "Leonardo Furnielis", email = "leonardofurnielis@outlook.com" }]
10
+ license = { text = "Apache-2.0" }
11
+ readme = "README.md"
12
+ requires-python = ">=3.11,<3.14"
13
+ dependencies = [
14
+ "litellm>=1.84.0 ,<1.85.0",
15
+ "donkey-core>=0.1.0,<0.2.0",
16
+ ]
17
+
18
+ [tool.hatch.build.targets.sdist]
19
+ include = ["donkey/"]
20
+
21
+ [tool.hatch.build.targets.wheel]
22
+ include = ["donkey/"]
23
+
24
+ [project.optional-dependencies]
25
+ dev = [
26
+ "pytest>=9.1.1,<10.0.0",
27
+ "pytest-asyncio>=1.4.0,<2.0.0",
28
+ "ruff>=0.15.20,<0.16.0",
29
+ ]