draive 0.9.1__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.
Files changed (106) hide show
  1. draive-0.9.1/LICENSE +21 -0
  2. draive-0.9.1/PKG-INFO +76 -0
  3. draive-0.9.1/README.md +27 -0
  4. draive-0.9.1/pyproject.toml +70 -0
  5. draive-0.9.1/setup.cfg +4 -0
  6. draive-0.9.1/src/draive/__init__.py +186 -0
  7. draive-0.9.1/src/draive/conversation/__init__.py +18 -0
  8. draive-0.9.1/src/draive/conversation/call.py +87 -0
  9. draive-0.9.1/src/draive/conversation/completion.py +67 -0
  10. draive-0.9.1/src/draive/conversation/lmm.py +159 -0
  11. draive-0.9.1/src/draive/conversation/message.py +16 -0
  12. draive-0.9.1/src/draive/conversation/state.py +17 -0
  13. draive-0.9.1/src/draive/embedding/__init__.py +11 -0
  14. draive-0.9.1/src/draive/embedding/call.py +15 -0
  15. draive-0.9.1/src/draive/embedding/embedded.py +18 -0
  16. draive-0.9.1/src/draive/embedding/embedder.py +23 -0
  17. draive-0.9.1/src/draive/embedding/state.py +10 -0
  18. draive-0.9.1/src/draive/generation/__init__.py +15 -0
  19. draive-0.9.1/src/draive/generation/image/__init__.py +9 -0
  20. draive-0.9.1/src/draive/generation/image/call.py +16 -0
  21. draive-0.9.1/src/draive/generation/image/generator.py +17 -0
  22. draive-0.9.1/src/draive/generation/image/state.py +10 -0
  23. draive-0.9.1/src/draive/generation/model/__init__.py +9 -0
  24. draive-0.9.1/src/draive/generation/model/call.py +34 -0
  25. draive-0.9.1/src/draive/generation/model/generator.py +29 -0
  26. draive-0.9.1/src/draive/generation/model/lmm.py +85 -0
  27. draive-0.9.1/src/draive/generation/model/state.py +13 -0
  28. draive-0.9.1/src/draive/generation/text/__init__.py +9 -0
  29. draive-0.9.1/src/draive/generation/text/call.py +26 -0
  30. draive-0.9.1/src/draive/generation/text/generator.py +22 -0
  31. draive-0.9.1/src/draive/generation/text/lmm.py +63 -0
  32. draive-0.9.1/src/draive/generation/text/state.py +13 -0
  33. draive-0.9.1/src/draive/helpers/__init__.py +13 -0
  34. draive-0.9.1/src/draive/helpers/env.py +139 -0
  35. draive-0.9.1/src/draive/helpers/logs.py +59 -0
  36. draive-0.9.1/src/draive/helpers/split_sequence.py +20 -0
  37. draive-0.9.1/src/draive/lmm/__init__.py +18 -0
  38. draive-0.9.1/src/draive/lmm/call.py +73 -0
  39. draive-0.9.1/src/draive/lmm/completion.py +64 -0
  40. draive-0.9.1/src/draive/lmm/message.py +50 -0
  41. draive-0.9.1/src/draive/lmm/state.py +10 -0
  42. draive-0.9.1/src/draive/mistral/__init__.py +11 -0
  43. draive-0.9.1/src/draive/mistral/chat_response.py +92 -0
  44. draive-0.9.1/src/draive/mistral/chat_stream.py +130 -0
  45. draive-0.9.1/src/draive/mistral/chat_tools.py +111 -0
  46. draive-0.9.1/src/draive/mistral/client.py +112 -0
  47. draive-0.9.1/src/draive/mistral/config.py +56 -0
  48. draive-0.9.1/src/draive/mistral/errors.py +7 -0
  49. draive-0.9.1/src/draive/mistral/lmm.py +213 -0
  50. draive-0.9.1/src/draive/openai/__init__.py +23 -0
  51. draive-0.9.1/src/draive/openai/chat_response.py +97 -0
  52. draive-0.9.1/src/draive/openai/chat_stream.py +120 -0
  53. draive-0.9.1/src/draive/openai/chat_tools.py +139 -0
  54. draive-0.9.1/src/draive/openai/client.py +212 -0
  55. draive-0.9.1/src/draive/openai/config.py +122 -0
  56. draive-0.9.1/src/draive/openai/embedding.py +33 -0
  57. draive-0.9.1/src/draive/openai/errors.py +7 -0
  58. draive-0.9.1/src/draive/openai/images.py +30 -0
  59. draive-0.9.1/src/draive/openai/lmm.py +236 -0
  60. draive-0.9.1/src/draive/openai/tokenization.py +22 -0
  61. draive-0.9.1/src/draive/py.typed +0 -0
  62. draive-0.9.1/src/draive/scope/__init__.py +16 -0
  63. draive-0.9.1/src/draive/scope/access.py +330 -0
  64. draive-0.9.1/src/draive/scope/dependencies.py +63 -0
  65. draive-0.9.1/src/draive/scope/errors.py +17 -0
  66. draive-0.9.1/src/draive/scope/metrics.py +462 -0
  67. draive-0.9.1/src/draive/scope/state.py +60 -0
  68. draive-0.9.1/src/draive/similarity/__init__.py +7 -0
  69. draive-0.9.1/src/draive/similarity/cosine.py +35 -0
  70. draive-0.9.1/src/draive/similarity/mmr.py +67 -0
  71. draive-0.9.1/src/draive/similarity/similarity.py +32 -0
  72. draive-0.9.1/src/draive/splitters/__init__.py +5 -0
  73. draive-0.9.1/src/draive/splitters/basic.py +130 -0
  74. draive-0.9.1/src/draive/tokenization/__init__.py +10 -0
  75. draive-0.9.1/src/draive/tokenization/call.py +18 -0
  76. draive-0.9.1/src/draive/tokenization/state.py +10 -0
  77. draive-0.9.1/src/draive/tokenization/text.py +14 -0
  78. draive-0.9.1/src/draive/tools/__init__.py +19 -0
  79. draive-0.9.1/src/draive/tools/errors.py +7 -0
  80. draive-0.9.1/src/draive/tools/state.py +31 -0
  81. draive-0.9.1/src/draive/tools/tool.py +184 -0
  82. draive-0.9.1/src/draive/tools/toolbox.py +51 -0
  83. draive-0.9.1/src/draive/tools/update.py +18 -0
  84. draive-0.9.1/src/draive/types/__init__.py +45 -0
  85. draive-0.9.1/src/draive/types/images.py +18 -0
  86. draive-0.9.1/src/draive/types/memory.py +55 -0
  87. draive-0.9.1/src/draive/types/missing.py +28 -0
  88. draive-0.9.1/src/draive/types/model.py +50 -0
  89. draive-0.9.1/src/draive/types/multimodal.py +8 -0
  90. draive-0.9.1/src/draive/types/parameters.py +847 -0
  91. draive-0.9.1/src/draive/types/specification.py +394 -0
  92. draive-0.9.1/src/draive/types/state.py +16 -0
  93. draive-0.9.1/src/draive/types/updates.py +22 -0
  94. draive-0.9.1/src/draive/utils/__init__.py +13 -0
  95. draive-0.9.1/src/draive/utils/cache.py +177 -0
  96. draive-0.9.1/src/draive/utils/early_exit.py +125 -0
  97. draive-0.9.1/src/draive/utils/retry.py +167 -0
  98. draive-0.9.1/src/draive/utils/stream.py +105 -0
  99. draive-0.9.1/src/draive.egg-info/PKG-INFO +76 -0
  100. draive-0.9.1/src/draive.egg-info/SOURCES.txt +104 -0
  101. draive-0.9.1/src/draive.egg-info/dependency_links.txt +1 -0
  102. draive-0.9.1/src/draive.egg-info/requires.txt +15 -0
  103. draive-0.9.1/src/draive.egg-info/top_level.txt +1 -0
  104. draive-0.9.1/tests/test_metrics.py +58 -0
  105. draive-0.9.1/tests/test_model.py +47 -0
  106. draive-0.9.1/tests/test_state.py +54 -0
draive-0.9.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Miquido
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
draive-0.9.1/PKG-INFO ADDED
@@ -0,0 +1,76 @@
1
+ Metadata-Version: 2.1
2
+ Name: draive
3
+ Version: 0.9.1
4
+ Maintainer-email: Kacper Kaliński <kacper.kalinski@miquido.com>
5
+ License: MIT License
6
+
7
+ Copyright (c) 2024 Miquido
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+ Project-URL: Homepage, https://miquido.com
27
+ Classifier: Intended Audience :: Developers
28
+ Classifier: Programming Language :: Python
29
+ Classifier: License :: OSI Approved :: MIT License
30
+ Classifier: Topic :: Software Development
31
+ Classifier: Typing :: Typed
32
+ Requires-Python: >=3.11
33
+ Description-Content-Type: text/markdown
34
+ License-File: LICENSE
35
+ Requires-Dist: openai~=1.14
36
+ Requires-Dist: mistralai~=0.1.3
37
+ Requires-Dist: numpy~=1.26
38
+ Requires-Dist: tiktoken~=0.6.0
39
+ Requires-Dist: pydantic~=2.6
40
+ Requires-Dist: httpx~=0.25.0
41
+ Provides-Extra: dev
42
+ Requires-Dist: ruff~=0.2.0; extra == "dev"
43
+ Requires-Dist: pyright~=1.1.0; extra == "dev"
44
+ Requires-Dist: bandit~=1.7.0; extra == "dev"
45
+ Requires-Dist: pytest~=7.4.0; extra == "dev"
46
+ Requires-Dist: pytest-cov~=4.1.0; extra == "dev"
47
+ Requires-Dist: pytest-asyncio~=0.23.0; extra == "dev"
48
+ Requires-Dist: python-dotenv~=1.0.0; extra == "dev"
49
+
50
+ # draive
51
+
52
+ Framework for building AI oriented applications.
53
+
54
+ ## License
55
+
56
+ MIT License
57
+
58
+ Copyright (c) 2024 Miquido
59
+
60
+ Permission is hereby granted, free of charge, to any person obtaining a copy
61
+ of this software and associated documentation files (the "Software"), to deal
62
+ in the Software without restriction, including without limitation the rights
63
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
64
+ copies of the Software, and to permit persons to whom the Software is
65
+ furnished to do so, subject to the following conditions:
66
+
67
+ The above copyright notice and this permission notice shall be included in all
68
+ copies or substantial portions of the Software.
69
+
70
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
71
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
72
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
73
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
74
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
75
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
76
+ SOFTWARE.
draive-0.9.1/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # draive
2
+
3
+ Framework for building AI oriented applications.
4
+
5
+ ## License
6
+
7
+ MIT License
8
+
9
+ Copyright (c) 2024 Miquido
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
@@ -0,0 +1,70 @@
1
+ [build-system]
2
+ requires = ["setuptools"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "draive"
7
+ version = "0.9.1"
8
+ readme = "README.md"
9
+ maintainers = [
10
+ {name = "Kacper Kaliński", email = "kacper.kalinski@miquido.com"}
11
+ ]
12
+ requires-python = ">=3.11"
13
+ classifiers = [
14
+ "Intended Audience :: Developers",
15
+ "Programming Language :: Python",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Topic :: Software Development",
18
+ "Typing :: Typed",
19
+ ]
20
+ license = {file = "LICENSE"}
21
+ dependencies = [
22
+ "openai~=1.14",
23
+ "mistralai~=0.1.3",
24
+ "numpy~=1.26",
25
+ "tiktoken~=0.6.0",
26
+ "pydantic~=2.6",
27
+ "httpx~=0.25.0",
28
+ ]
29
+
30
+ [project.urls]
31
+ Homepage = "https://miquido.com"
32
+
33
+ [project.optional-dependencies]
34
+ dev = [
35
+ "ruff~=0.2.0",
36
+ "pyright~=1.1.0",
37
+ "bandit~=1.7.0",
38
+ "pytest~=7.4.0",
39
+ "pytest-cov~=4.1.0",
40
+ "pytest-asyncio~=0.23.0",
41
+ "python-dotenv~=1.0.0",
42
+ ]
43
+
44
+ [tool.ruff]
45
+ target-version = "py311"
46
+ line-length = 100
47
+ extend-exclude = [".venv", ".git", ".cache"]
48
+ lint.select = ["E", "F", "A", "I", "B", "PL", "W", "C", "RUF", "UP"]
49
+ lint.ignore = []
50
+
51
+ [tool.ruff.lint.per-file-ignores]
52
+ "__init__.py" = ["F401", "E402"]
53
+ "./tests/*.py" = ["PLR2004"]
54
+
55
+ [tool.ruff.lint.flake8-bugbear]
56
+ extend-immutable-calls = ["Argument", "draive.Argument"]
57
+
58
+ [tool.pyright]
59
+ pythonVersion = "3.11"
60
+ venvPath = "./.venv"
61
+ include = [
62
+ "./src",
63
+ ]
64
+ exclude = [
65
+ "**/__pycache__",
66
+ ]
67
+ ignore = []
68
+ reportMissingImports = true
69
+ reportMissingTypeStubs = true
70
+ typeCheckingMode = "strict"
draive-0.9.1/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,186 @@
1
+ from draive.conversation import (
2
+ Conversation,
3
+ ConversationCompletion,
4
+ ConversationCompletionStream,
5
+ ConversationMessage,
6
+ ConversationMessageContent,
7
+ conversation_completion,
8
+ lmm_conversation_completion,
9
+ )
10
+ from draive.embedding import Embedded, Embedder, Embedding, embed_text
11
+ from draive.generation import (
12
+ ImageGeneration,
13
+ ImageGenerator,
14
+ ModelGeneration,
15
+ ModelGenerator,
16
+ TextGeneration,
17
+ TextGenerator,
18
+ generate_image,
19
+ generate_model,
20
+ generate_text,
21
+ )
22
+ from draive.helpers import (
23
+ getenv_bool,
24
+ getenv_float,
25
+ getenv_int,
26
+ getenv_str,
27
+ load_env,
28
+ setup_logging,
29
+ split_sequence,
30
+ )
31
+ from draive.lmm import (
32
+ LMM,
33
+ LMMCompletion,
34
+ LMMCompletionContent,
35
+ LMMCompletionMessage,
36
+ LMMCompletionStream,
37
+ LMMCompletionStreamingUpdate,
38
+ lmm_completion,
39
+ )
40
+ from draive.mistral import (
41
+ MistralChatConfig,
42
+ MistralClient,
43
+ MistralException,
44
+ mistral_lmm_completion,
45
+ )
46
+ from draive.openai import (
47
+ OpenAIChatConfig,
48
+ OpenAIClient,
49
+ OpenAIEmbeddingConfig,
50
+ OpenAIException,
51
+ OpenAIImageGenerationConfig,
52
+ openai_embed_text,
53
+ openai_generate_image,
54
+ openai_lmm_completion,
55
+ openai_tokenize_text,
56
+ )
57
+ from draive.scope import (
58
+ DependenciesScope,
59
+ MetricsScope,
60
+ ScopeDependency,
61
+ ScopeMetric,
62
+ StateScope,
63
+ TokenUsage,
64
+ ctx,
65
+ )
66
+ from draive.similarity import mmr_similarity, similarity
67
+ from draive.splitters import split_text
68
+ from draive.tokenization import TextTokenizer, Tokenization, count_text_tokens, tokenize_text
69
+ from draive.tools import (
70
+ Tool,
71
+ Toolbox,
72
+ ToolCallContext,
73
+ ToolCallStatus,
74
+ ToolCallUpdate,
75
+ ToolException,
76
+ ToolsUpdatesContext,
77
+ tool,
78
+ )
79
+ from draive.types import (
80
+ MISSING,
81
+ Argument,
82
+ Field,
83
+ ImageBase64Content,
84
+ ImageContent,
85
+ ImageURLContent,
86
+ Memory,
87
+ MissingValue,
88
+ Model,
89
+ MultimodalContent,
90
+ ReadOnlyMemory,
91
+ State,
92
+ UpdateSend,
93
+ )
94
+ from draive.utils import allowing_early_exit, auto_retry, cache, with_early_exit
95
+
96
+ __all__ = [
97
+ "Conversation",
98
+ "ImageContent",
99
+ "ImageBase64Content",
100
+ "ImageURLContent",
101
+ "UpdateSend",
102
+ "Embedded",
103
+ "Embedder",
104
+ "Embedding",
105
+ "Model",
106
+ "Memory",
107
+ "ModelGeneration",
108
+ "ModelGenerator",
109
+ "ReadOnlyMemory",
110
+ "DependenciesScope",
111
+ "ScopeDependency",
112
+ "ScopeMetric",
113
+ "MetricsScope",
114
+ "StateScope",
115
+ "State",
116
+ "Field",
117
+ "TextGeneration",
118
+ "TextGenerator",
119
+ "ImageGeneration",
120
+ "ImageGenerator",
121
+ "generate_image",
122
+ "TextTokenizer",
123
+ "Tokenization",
124
+ "TokenUsage",
125
+ "auto_retry",
126
+ "cache",
127
+ "conversation_completion",
128
+ "tokenize_text",
129
+ "count_text_tokens",
130
+ "ctx",
131
+ "embed_text",
132
+ "generate_model",
133
+ "generate_text",
134
+ "load_env",
135
+ "getenv_bool",
136
+ "getenv_float",
137
+ "getenv_int",
138
+ "getenv_str",
139
+ "mmr_similarity",
140
+ "similarity",
141
+ "split_sequence",
142
+ "split_text",
143
+ "tool",
144
+ "Argument",
145
+ "allowing_early_exit",
146
+ "with_early_exit",
147
+ "setup_logging",
148
+ "MissingValue",
149
+ "MISSING",
150
+ "MultimodalContent",
151
+ "Tool",
152
+ "ToolException",
153
+ "Toolbox",
154
+ "ToolCallContext",
155
+ "ToolCallStatus",
156
+ "ToolCallUpdate",
157
+ "ToolException",
158
+ "ToolsUpdatesContext",
159
+ "LMM",
160
+ "LMMCompletion",
161
+ "LMMCompletionContent",
162
+ "LMMCompletionMessage",
163
+ "LMMCompletionStreamingUpdate",
164
+ "LMMCompletionStream",
165
+ "lmm_completion",
166
+ "ConversationMessage",
167
+ "ConversationMessageContent",
168
+ "Conversation",
169
+ "ConversationCompletionStream",
170
+ "ConversationCompletion",
171
+ "conversation_completion",
172
+ "lmm_conversation_completion",
173
+ "OpenAIException",
174
+ "OpenAIChatConfig",
175
+ "OpenAIClient",
176
+ "OpenAIEmbeddingConfig",
177
+ "OpenAIImageGenerationConfig",
178
+ "openai_tokenize_text",
179
+ "openai_embed_text",
180
+ "openai_lmm_completion",
181
+ "openai_generate_image",
182
+ "MistralException",
183
+ "MistralClient",
184
+ "MistralChatConfig",
185
+ "mistral_lmm_completion",
186
+ ]
@@ -0,0 +1,18 @@
1
+ from draive.conversation.call import conversation_completion
2
+ from draive.conversation.completion import ConversationCompletion, ConversationCompletionStream
3
+ from draive.conversation.lmm import lmm_conversation_completion
4
+ from draive.conversation.message import (
5
+ ConversationMessage,
6
+ ConversationMessageContent,
7
+ )
8
+ from draive.conversation.state import Conversation
9
+
10
+ __all__ = [
11
+ "ConversationMessage",
12
+ "ConversationMessageContent",
13
+ "Conversation",
14
+ "ConversationCompletionStream",
15
+ "ConversationCompletion",
16
+ "conversation_completion",
17
+ "lmm_conversation_completion",
18
+ ]
@@ -0,0 +1,87 @@
1
+ from typing import Literal, overload
2
+
3
+ from draive.conversation.completion import ConversationCompletionStream
4
+ from draive.conversation.message import (
5
+ ConversationMessage,
6
+ ConversationMessageContent,
7
+ ConversationStreamingUpdate,
8
+ )
9
+ from draive.conversation.state import Conversation
10
+ from draive.scope import ctx
11
+ from draive.tools import Toolbox
12
+ from draive.types import Memory, UpdateSend
13
+
14
+ __all__ = [
15
+ "conversation_completion",
16
+ ]
17
+
18
+
19
+ @overload
20
+ async def conversation_completion(
21
+ *,
22
+ instruction: str,
23
+ input: ConversationMessage | ConversationMessageContent, # noqa: A002
24
+ memory: Memory[ConversationMessage] | None = None,
25
+ tools: Toolbox | None = None,
26
+ stream: Literal[True],
27
+ ) -> ConversationCompletionStream:
28
+ ...
29
+
30
+
31
+ @overload
32
+ async def conversation_completion(
33
+ *,
34
+ instruction: str,
35
+ input: ConversationMessage | ConversationMessageContent, # noqa: A002
36
+ memory: Memory[ConversationMessage] | None = None,
37
+ tools: Toolbox | None = None,
38
+ stream: UpdateSend[ConversationStreamingUpdate],
39
+ ) -> ConversationMessage:
40
+ ...
41
+
42
+
43
+ @overload
44
+ async def conversation_completion(
45
+ *,
46
+ instruction: str,
47
+ input: ConversationMessage | ConversationMessageContent, # noqa: A002
48
+ memory: Memory[ConversationMessage] | None = None,
49
+ tools: Toolbox | None = None,
50
+ ) -> ConversationMessage:
51
+ ...
52
+
53
+
54
+ async def conversation_completion(
55
+ *,
56
+ instruction: str,
57
+ input: ConversationMessage | ConversationMessageContent, # noqa: A002
58
+ memory: Memory[ConversationMessage] | None = None,
59
+ tools: Toolbox | None = None,
60
+ stream: UpdateSend[ConversationStreamingUpdate] | bool = False,
61
+ ) -> ConversationCompletionStream | ConversationMessage:
62
+ conversation: Conversation = ctx.state(Conversation)
63
+
64
+ match stream:
65
+ case False:
66
+ return await conversation.completion(
67
+ instruction=instruction,
68
+ input=input,
69
+ memory=memory or conversation.memory,
70
+ tools=tools or conversation.tools,
71
+ )
72
+ case True:
73
+ return await conversation.completion(
74
+ instruction=instruction,
75
+ input=input,
76
+ memory=memory or conversation.memory,
77
+ tools=tools or conversation.tools,
78
+ stream=True,
79
+ )
80
+ case progress:
81
+ return await conversation.completion(
82
+ instruction=instruction,
83
+ input=input,
84
+ memory=memory or conversation.memory,
85
+ tools=tools or conversation.tools,
86
+ stream=progress,
87
+ )
@@ -0,0 +1,67 @@
1
+ from typing import Literal, Protocol, overload, runtime_checkable
2
+
3
+ from draive.conversation.message import (
4
+ ConversationMessage,
5
+ ConversationMessageContent,
6
+ ConversationStreamingUpdate,
7
+ )
8
+ from draive.lmm import LMMCompletionStream
9
+ from draive.tools import Toolbox
10
+ from draive.types import Memory, UpdateSend
11
+
12
+ __all__ = [
13
+ "ConversationCompletionStream",
14
+ "ConversationCompletion",
15
+ ]
16
+
17
+
18
+ ConversationCompletionStream = LMMCompletionStream
19
+
20
+
21
+ @runtime_checkable
22
+ class ConversationCompletion(Protocol):
23
+ @overload
24
+ async def __call__(
25
+ self,
26
+ *,
27
+ instruction: str,
28
+ input: ConversationMessage | ConversationMessageContent, # noqa: A002
29
+ memory: Memory[ConversationMessage] | None = None,
30
+ tools: Toolbox | None = None,
31
+ stream: Literal[True],
32
+ ) -> ConversationCompletionStream:
33
+ ...
34
+
35
+ @overload
36
+ async def __call__(
37
+ self,
38
+ *,
39
+ instruction: str,
40
+ input: ConversationMessage | ConversationMessageContent, # noqa: A002
41
+ memory: Memory[ConversationMessage] | None = None,
42
+ tools: Toolbox | None = None,
43
+ stream: UpdateSend[ConversationStreamingUpdate],
44
+ ) -> ConversationMessage:
45
+ ...
46
+
47
+ @overload
48
+ async def __call__(
49
+ self,
50
+ *,
51
+ instruction: str,
52
+ input: ConversationMessage | ConversationMessageContent, # noqa: A002
53
+ memory: Memory[ConversationMessage] | None = None,
54
+ tools: Toolbox | None = None,
55
+ ) -> ConversationMessage:
56
+ ...
57
+
58
+ async def __call__( # noqa: PLR0913
59
+ self,
60
+ *,
61
+ instruction: str,
62
+ input: ConversationMessage | ConversationMessageContent, # noqa: A002
63
+ memory: Memory[ConversationMessage] | None = None,
64
+ tools: Toolbox | None = None,
65
+ stream: UpdateSend[ConversationStreamingUpdate] | bool = False,
66
+ ) -> ConversationCompletionStream | ConversationMessage:
67
+ ...