sinapsis 0.1.0__tar.gz → 0.2.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.
Files changed (29) hide show
  1. {sinapsis-0.1.0 → sinapsis-0.2.0}/PKG-INFO +9 -4
  2. {sinapsis-0.1.0 → sinapsis-0.2.0}/README.md +3 -2
  3. {sinapsis-0.1.0 → sinapsis-0.2.0}/pyproject.toml +13 -2
  4. {sinapsis-0.1.0 → sinapsis-0.2.0}/src/sinapsis/templates/hello_world.py +0 -2
  5. sinapsis-0.2.0/src/sinapsis/webapp/chatbot_base.py +271 -0
  6. {sinapsis-0.1.0 → sinapsis-0.2.0}/src/sinapsis.egg-info/PKG-INFO +9 -4
  7. {sinapsis-0.1.0 → sinapsis-0.2.0}/src/sinapsis.egg-info/SOURCES.txt +2 -10
  8. sinapsis-0.1.0/.dockerignore +0 -1
  9. sinapsis-0.1.0/.gitignore +0 -49
  10. sinapsis-0.1.0/.pre-commit-config.yaml +0 -46
  11. sinapsis-0.1.0/.python-version +0 -1
  12. sinapsis-0.1.0/README-internal.md +0 -272
  13. sinapsis-0.1.0/docker/Dockerfile +0 -44
  14. sinapsis-0.1.0/docker/compose.yaml +0 -18
  15. sinapsis-0.1.0/src/sinapsis/configs/hello_world_agent.yml +0 -22
  16. sinapsis-0.1.0/uv.lock +0 -342
  17. {sinapsis-0.1.0 → sinapsis-0.2.0}/LICENSE +0 -0
  18. {sinapsis-0.1.0 → sinapsis-0.2.0}/setup.cfg +0 -0
  19. {sinapsis-0.1.0 → sinapsis-0.2.0}/src/sinapsis/__init__.py +0 -0
  20. {sinapsis-0.1.0 → sinapsis-0.2.0}/src/sinapsis/bin/sinapsis_cli.py +0 -0
  21. {sinapsis-0.1.0 → sinapsis-0.2.0}/src/sinapsis/templates/__init__.py +0 -0
  22. {sinapsis-0.1.0 → sinapsis-0.2.0}/src/sinapsis/templates/display_hello_world.py +0 -0
  23. {sinapsis-0.1.0 → sinapsis-0.2.0}/src/sinapsis/webapp/__init__.py +0 -0
  24. {sinapsis-0.1.0 → sinapsis-0.2.0}/src/sinapsis/webapp/agent_gradio_helper.py +0 -0
  25. {sinapsis-0.1.0 → sinapsis-0.2.0}/src/sinapsis/webapp/agent_webapp_utils.py +0 -0
  26. {sinapsis-0.1.0 → sinapsis-0.2.0}/src/sinapsis.egg-info/dependency_links.txt +0 -0
  27. {sinapsis-0.1.0 → sinapsis-0.2.0}/src/sinapsis.egg-info/entry_points.txt +0 -0
  28. {sinapsis-0.1.0 → sinapsis-0.2.0}/src/sinapsis.egg-info/requires.txt +0 -0
  29. {sinapsis-0.1.0 → sinapsis-0.2.0}/src/sinapsis.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: sinapsis
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Modular and Universal AI platform
5
5
  Author-email: SinapsisAI <dev@sinapsis.tech>
6
6
  License: GNU AFFERO GENERAL PUBLIC LICENSE
@@ -665,6 +665,10 @@ License: GNU AFFERO GENERAL PUBLIC LICENSE
665
665
  For more information on this, and how to apply and follow the GNU AGPL, see
666
666
  <https://www.gnu.org/licenses/>.
667
667
 
668
+ Project-URL: Homepage, https://sinapsis.tech
669
+ Project-URL: Documentation, https://docs.sinapsis.tech/docs
670
+ Project-URL: Tutorials, https://docs.sinapsis.tech/tutorials
671
+ Project-URL: Repository, https://github.com/Sinapsis-AI/sinapsis.git
668
672
  Requires-Python: >=3.10
669
673
  Description-Content-Type: text/markdown
670
674
  Requires-Dist: sinapsis-core>=0.1.0
@@ -718,11 +722,11 @@ If you need to install <code>uv</code> please see the [official documentation](h
718
722
 
719
723
  Example with <code>uv</code>:
720
724
  ```bash
721
- uv pip install sinapsis
725
+ uv pip install sinapsis --extra-index-url https://pypi.sinapsis.tech
722
726
  ```
723
727
  or with raw <code>pip</code>:
724
728
  ```bash
725
- pip install sinapsis
729
+ pip install sinapsis --extra-index-url https://pypi.sinapsis.tech
726
730
  ```
727
731
 
728
732
 
@@ -845,6 +849,7 @@ sinapsis run my_test_agent.yml
845
849
 
846
850
  - Data Validation and Type Safety through Pydantic
847
851
  - YAML-based configuration files
852
+ - Command Line Interface
848
853
  </details>
849
854
 
850
855
  <h2 id="examples">👀 Examples</h2>
@@ -45,11 +45,11 @@ If you need to install <code>uv</code> please see the [official documentation](h
45
45
 
46
46
  Example with <code>uv</code>:
47
47
  ```bash
48
- uv pip install sinapsis
48
+ uv pip install sinapsis --extra-index-url https://pypi.sinapsis.tech
49
49
  ```
50
50
  or with raw <code>pip</code>:
51
51
  ```bash
52
- pip install sinapsis
52
+ pip install sinapsis --extra-index-url https://pypi.sinapsis.tech
53
53
  ```
54
54
 
55
55
 
@@ -172,6 +172,7 @@ sinapsis run my_test_agent.yml
172
172
 
173
173
  - Data Validation and Type Safety through Pydantic
174
174
  - YAML-based configuration files
175
+ - Command Line Interface
175
176
  </details>
176
177
 
177
178
  <h2 id="examples">👀 Examples</h2>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sinapsis"
3
- version = "0.1.0"
3
+ version = "0.2.0"
4
4
  description = "Modular and Universal AI platform"
5
5
  authors = [
6
6
  {name = "SinapsisAI", email = "dev@sinapsis.tech"},
@@ -59,5 +59,16 @@ sinapsis-core = { index = "sinapsis-core" }
59
59
  name = "sinapsis-core"
60
60
  url = "https://pypi.sinapsis.tech/"
61
61
 
62
+
62
63
  [tool.setuptools]
63
- license-files = []
64
+ license-files = []
65
+
66
+ [build-system]
67
+ requires = ["setuptools"]
68
+ build-backend = "setuptools.build_meta"
69
+
70
+ [project.urls]
71
+ Homepage = "https://sinapsis.tech"
72
+ Documentation = "https://docs.sinapsis.tech/docs"
73
+ Tutorials = "https://docs.sinapsis.tech/tutorials"
74
+ Repository = "https://github.com/Sinapsis-AI/sinapsis.git"
@@ -46,10 +46,8 @@ class HelloWorld(Template):
46
46
  container (DataContainer): The modified data container. A text packet is appended to the 'texts' field.
47
47
  """
48
48
  text_packet = TextPacket(content=self.attributes.display_text)
49
- # optionally add additional metadata that may be useful in downstream tasks
50
49
  text_packet.source = self.instance_name
51
50
 
52
- # finally append it to the data container
53
51
  container.texts.append(text_packet)
54
52
 
55
53
  return container
@@ -0,0 +1,271 @@
1
+ # -*- coding: utf-8 -*-
2
+ import json
3
+ import os.path
4
+ import uuid
5
+
6
+ import gradio as gr
7
+ from pydantic.dataclasses import dataclass
8
+ from sinapsis_core.cli.run_agent_from_config import generic_agent_builder
9
+ from sinapsis_core.data_containers.data_packet import DataContainer, TextPacket
10
+ from sinapsis_core.utils.env_var_keys import SINAPSIS_CACHE_DIR
11
+
12
+ from sinapsis.webapp.agent_gradio_helper import add_logo_and_title, css_header
13
+
14
+ SINAPSIS_AVATAR = "https://github.com/Sinapsis-AI/brand-resources/blob/main/sinapsis_logo/4x/fav_icon.png?raw=true"
15
+
16
+
17
+ @dataclass
18
+ class ChatKeys:
19
+ """
20
+ Defines key names used for referencing various chat-related data types.
21
+
22
+ This class serves as a centralized place to manage key names for different types of data
23
+ that may be used in chat interactions. These keys are typically used to map data in structured formats.
24
+ """
25
+
26
+ text: str = "text"
27
+ files: str = "files"
28
+ file_path: str = "path"
29
+ audio_path: str = "audio_path"
30
+ role: str = "role"
31
+ content: str = "content"
32
+ user: str = "user"
33
+ assistant: str = "assistant"
34
+
35
+
36
+ class BaseChatbot:
37
+ """
38
+ A base chatbot class designed to work with various LLM frameworks, such as LLaMA.
39
+ This class provides the functionality to interact with users through text, audio,
40
+ and file inputs, maintain chat history, and integrate with Gradio for a web
41
+ interface. The class is intended to serve as a foundation
42
+ that can be adapted to different LLM frameworks by modifying the agent
43
+ initialization and response handling methods.
44
+ """
45
+
46
+ def __init__(self, config_file: str, app_title: str = "Sinapsis LLaMA Chatbot") -> None:
47
+ """
48
+ Initialize the chatbot with given configuration, framework, and task.
49
+
50
+ Args:
51
+ config_file (str): Path to the configuration file.
52
+ app_title (str): Title of the app
53
+ """
54
+ self.config_file = config_file
55
+ self.file_name = f"{SINAPSIS_CACHE_DIR}/chatbot/chat.txt"
56
+ os.makedirs(os.path.dirname(self.file_name), exist_ok=True)
57
+ self.app_title = app_title
58
+ self.chat_history: list = self.load_chat()
59
+ self.agent = generic_agent_builder(self.config_file)
60
+
61
+ def load_chat(self) -> list:
62
+ """If the file self.file_name exists, it loads
63
+ previous chat history. Otherwise, it creates a new file and
64
+ sets the chat history as an empty list
65
+
66
+ Returns:
67
+ the list of messages or empty list for messages
68
+ """
69
+ if os.path.exists(self.file_name):
70
+ with open(self.file_name, "r", encoding="utf-8") as chat:
71
+ try:
72
+ history = json.load(chat)
73
+ except json.JSONDecodeError:
74
+ history = []
75
+ else:
76
+ history = []
77
+ with open(self.file_name, "w") as file:
78
+ json.dump(history, file)
79
+ return history
80
+
81
+ @staticmethod
82
+ def generate_packet(message, conv_id: str) -> DataContainer:
83
+ """
84
+ Args:
85
+ message (str): The user's input message, either as a audio file or text
86
+ conv_id (str): The conversation ID to associate with the message.
87
+ """
88
+ container = DataContainer()
89
+ if not message.endswith("wav"):
90
+ text_msg = TextPacket(content=message, id=conv_id)
91
+ container.texts.append(text_msg)
92
+ else:
93
+ container.generic_data[ChatKeys.audio_path] = message
94
+ return container
95
+
96
+ def agent_execution(self, container: DataContainer) -> dict:
97
+ """
98
+ Makes a call to the agent to retrieve a response from the templates in the agent.
99
+
100
+ Args:
101
+ container (DataContainer): container with the packets to be processed by the
102
+ templates in the agent.
103
+
104
+ Returns:
105
+ dict : The response to be added to the chatbot window
106
+
107
+ """
108
+ response = self.agent(container)
109
+ response_dict = {
110
+ ChatKeys.text: "Could not process request, please try again",
111
+ ChatKeys.files: [],
112
+ }
113
+
114
+ if response.texts:
115
+ response_dict = {
116
+ ChatKeys.text: response.texts[-1].content,
117
+ ChatKeys.files: [],
118
+ }
119
+ if container.generic_data.get(ChatKeys.audio_path):
120
+ container.generic_data[ChatKeys.audio_path] = False
121
+ return response_dict
122
+
123
+ @staticmethod
124
+ def _set_conversation_id(conv_id: str) -> str:
125
+ """
126
+ Ensure a valid conversation ID is set. If no ID is provided, a new one is
127
+ generated.
128
+ Args:
129
+ conv_id (str): The provided conversation ID.
130
+ Returns:
131
+ str: The valid conversation ID (either provided or generated).
132
+ """
133
+ if not conv_id:
134
+ conv_id = str(uuid.uuid4())
135
+ return conv_id
136
+
137
+ def add_message(self, message: dict | str, role: str) -> tuple[gr.components.Textbox, gr.components.Audio]:
138
+ """
139
+ The method adds a user or assistant message to the chat history.
140
+
141
+ Args:
142
+ message (dict | str): The input message, either as text or a dictionary.
143
+ role (str): The role of the message sender, e.g., "user" or "assistant".
144
+
145
+ Returns:
146
+ tuple: A tuple with updated chat history, a Textbox, and an Audio component.
147
+ """
148
+
149
+ if isinstance(message, dict):
150
+ for x in message[ChatKeys.files]:
151
+ self.chat_history.append({ChatKeys.role: role, ChatKeys.content: {ChatKeys.file_path: x}})
152
+ if message[ChatKeys.text]:
153
+ self.chat_history.append({ChatKeys.role: role, ChatKeys.content: message[ChatKeys.text]})
154
+ elif isinstance(message, str) and not message.endswith("wav"):
155
+ self.chat_history.append({ChatKeys.role: role, ChatKeys.content: message})
156
+ else:
157
+ self.chat_history.append({ChatKeys.role: role, ChatKeys.content: {ChatKeys.file_path: message}})
158
+ return (
159
+ gr.Textbox(value=None),
160
+ gr.Audio(value=None),
161
+ )
162
+
163
+ def stop_agent(self) -> tuple[dict, dict]:
164
+ """
165
+ Stop the chatbot's agent and save the chat history to a file.
166
+
167
+
168
+ Returns:
169
+ tuple: A tuple with None and Gradio updates for interactivity.
170
+ """
171
+ self._clear_history()
172
+ self.agent = None
173
+ return gr.update(interactive=False), gr.update(interactive=False)
174
+
175
+ def _clear_history(self) -> None:
176
+ """
177
+ Clears the chat history and saves it to a file named "chat.txt".
178
+
179
+ This method writes the current chat history to a file in JSON format,
180
+ then clears the history.
181
+ """
182
+ with open(self.file_name, "w+", encoding="utf-8") as chat:
183
+ json.dump(self.chat_history, chat, indent=4)
184
+ chat.close()
185
+ self.chat_history = []
186
+
187
+ def process_msg(self, message: str, conv_id: str) -> tuple[list, gr.Textbox, gr.Audio, str] | list:
188
+ """
189
+ Process a user message and generate a chatbot response.
190
+
191
+ Args:
192
+ message (str): The user's input message.
193
+ conv_id (str): The conversation ID for the current session.
194
+
195
+ Returns:
196
+ tuple: The updated chat history and UI components for the chatbot interface.
197
+ """
198
+
199
+ conv_id = self._set_conversation_id(conv_id)
200
+ _ = self.add_message(message, ChatKeys.user)
201
+ container = self.generate_packet(message, conv_id)
202
+ response = self.agent_execution(container)
203
+
204
+ retrieved_chat = self.add_message(response, ChatKeys.assistant)
205
+ return self.chat_history, retrieved_chat[0], retrieved_chat[1], conv_id
206
+
207
+ def add_app_components(self) -> tuple[gr.Chatbot, gr.Textbox, gr.Audio]:
208
+ """
209
+ Add interactive components (buttons, inputs, and chatbot UI) to the interface.
210
+
211
+ Returns:
212
+ tuple: A tuple containing the components for the chatbot interface.
213
+ """
214
+ chatbot = gr.Chatbot(
215
+ self.chat_history, type="messages", height=600, show_label=False, avatar_images=(None, SINAPSIS_AVATAR)
216
+ )
217
+ chat_input = gr.Textbox(
218
+ interactive=True,
219
+ placeholder="Enter a message",
220
+ show_label=False,
221
+ )
222
+
223
+ audio_input = gr.Audio(
224
+ sources=["microphone"],
225
+ type="filepath",
226
+ label="Record Audio",
227
+ interactive=True,
228
+ )
229
+
230
+ return chatbot, chat_input, audio_input
231
+
232
+ def app_interface(self) -> None:
233
+ """
234
+ Define the core functionality of the chatbot, including initialization,
235
+ message handling, and user interaction.
236
+ """
237
+
238
+ conversation_id = gr.State()
239
+
240
+ (
241
+ chatbot,
242
+ chat_input,
243
+ audio_input,
244
+ ) = self.add_app_components()
245
+
246
+ clear_btn = gr.ClearButton([audio_input, chat_input, chatbot, conversation_id])
247
+ clear_btn.click(self._clear_history, inputs=[], outputs=[])
248
+
249
+ audio_input.stop_recording(
250
+ self.process_msg,
251
+ inputs=[audio_input, conversation_id],
252
+ outputs=[chatbot, chat_input, audio_input, conversation_id],
253
+ )
254
+ chat_input.submit(
255
+ self.process_msg,
256
+ inputs=[chat_input, conversation_id],
257
+ outputs=[chatbot, chat_input, audio_input, conversation_id],
258
+ )
259
+
260
+ finish_chatbot = gr.Button(value="Finish chatbot", elem_id="finish-button", variant="primary")
261
+ finish_chatbot.click(
262
+ self.stop_agent,
263
+ inputs=[],
264
+ outputs=[chat_input, audio_input],
265
+ )
266
+
267
+ def __call__(self) -> gr.Blocks:
268
+ with gr.Blocks(css=css_header()) as chatbot_interface:
269
+ add_logo_and_title(self.app_title)
270
+ self.app_interface()
271
+ return chatbot_interface
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: sinapsis
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Modular and Universal AI platform
5
5
  Author-email: SinapsisAI <dev@sinapsis.tech>
6
6
  License: GNU AFFERO GENERAL PUBLIC LICENSE
@@ -665,6 +665,10 @@ License: GNU AFFERO GENERAL PUBLIC LICENSE
665
665
  For more information on this, and how to apply and follow the GNU AGPL, see
666
666
  <https://www.gnu.org/licenses/>.
667
667
 
668
+ Project-URL: Homepage, https://sinapsis.tech
669
+ Project-URL: Documentation, https://docs.sinapsis.tech/docs
670
+ Project-URL: Tutorials, https://docs.sinapsis.tech/tutorials
671
+ Project-URL: Repository, https://github.com/Sinapsis-AI/sinapsis.git
668
672
  Requires-Python: >=3.10
669
673
  Description-Content-Type: text/markdown
670
674
  Requires-Dist: sinapsis-core>=0.1.0
@@ -718,11 +722,11 @@ If you need to install <code>uv</code> please see the [official documentation](h
718
722
 
719
723
  Example with <code>uv</code>:
720
724
  ```bash
721
- uv pip install sinapsis
725
+ uv pip install sinapsis --extra-index-url https://pypi.sinapsis.tech
722
726
  ```
723
727
  or with raw <code>pip</code>:
724
728
  ```bash
725
- pip install sinapsis
729
+ pip install sinapsis --extra-index-url https://pypi.sinapsis.tech
726
730
  ```
727
731
 
728
732
 
@@ -845,6 +849,7 @@ sinapsis run my_test_agent.yml
845
849
 
846
850
  - Data Validation and Type Safety through Pydantic
847
851
  - YAML-based configuration files
852
+ - Command Line Interface
848
853
  </details>
849
854
 
850
855
  <h2 id="examples">👀 Examples</h2>
@@ -1,14 +1,6 @@
1
- .dockerignore
2
- .gitignore
3
- .pre-commit-config.yaml
4
- .python-version
5
1
  LICENSE
6
- README-internal.md
7
2
  README.md
8
3
  pyproject.toml
9
- uv.lock
10
- docker/Dockerfile
11
- docker/compose.yaml
12
4
  src/sinapsis/__init__.py
13
5
  src/sinapsis.egg-info/PKG-INFO
14
6
  src/sinapsis.egg-info/SOURCES.txt
@@ -17,10 +9,10 @@ src/sinapsis.egg-info/entry_points.txt
17
9
  src/sinapsis.egg-info/requires.txt
18
10
  src/sinapsis.egg-info/top_level.txt
19
11
  src/sinapsis/bin/sinapsis_cli.py
20
- src/sinapsis/configs/hello_world_agent.yml
21
12
  src/sinapsis/templates/__init__.py
22
13
  src/sinapsis/templates/display_hello_world.py
23
14
  src/sinapsis/templates/hello_world.py
24
15
  src/sinapsis/webapp/__init__.py
25
16
  src/sinapsis/webapp/agent_gradio_helper.py
26
- src/sinapsis/webapp/agent_webapp_utils.py
17
+ src/sinapsis/webapp/agent_webapp_utils.py
18
+ src/sinapsis/webapp/chatbot_base.py
@@ -1 +0,0 @@
1
- .venv
sinapsis-0.1.0/.gitignore DELETED
@@ -1,49 +0,0 @@
1
- # Byte-compiled / optimized / DLL files
2
- __pycache__/
3
- *.py[cod]
4
- *$py.class
5
-
6
- # Distribution / packaging
7
- .Python
8
- build/
9
- develop-eggs/
10
- dist/
11
- downloads/
12
- eggs/
13
- .eggs/
14
- lib/
15
- lib64/
16
- parts/
17
- sdist/
18
- var/
19
- wheels/
20
- share/python-wheels/
21
- *.egg-info/
22
- .installed.cfg
23
- *.egg
24
- MANIFEST
25
-
26
-
27
- .pdm.toml
28
- .pdm-python
29
- .pdm-build/
30
-
31
- # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
32
- __pypackages__/
33
-
34
- # Environments
35
- .env
36
- .venv
37
- env/
38
- venv/
39
- ENV/
40
- env.bak/
41
- venv.bak/
42
-
43
- # mypy
44
- .mypy_cache/
45
- .dmypy.json
46
- dmypy.json
47
-
48
- artifacts/*
49
- .vscode/*
@@ -1,46 +0,0 @@
1
- fail_fast: True
2
-
3
- repos:
4
- - repo: https://github.com/pre-commit/pre-commit-hooks
5
- rev: v5.0.0
6
- hooks:
7
- - id: fix-encoding-pragma
8
- exclude: 'docs/.*'
9
- - id: check-yaml
10
- exclude: 'docs/.*'
11
- - id: trailing-whitespace
12
- exclude: 'docs/.*'
13
- - id: name-tests-test
14
- args: ["--pytest-test-first"]
15
- exclude: 'docs/.*'
16
- - id: check-added-large-files
17
- args: ["--maxkb=10"]
18
- - id: check-docstring-first
19
- exclude: 'docs/.*'
20
- - id: check-case-conflict
21
- exclude: 'docs/.*'
22
- - id: check-shebang-scripts-are-executable
23
- exclude: 'docs/.*'
24
-
25
- - repo: https://github.com/gitleaks/gitleaks
26
- rev: v8.16.1
27
- hooks:
28
- - id: gitleaks
29
- exclude: '.*/tests/.*'
30
-
31
- - repo: https://github.com/astral-sh/ruff-pre-commit
32
- rev: v0.9.3
33
- hooks:
34
- - id: ruff
35
- - id: ruff-format
36
-
37
- - repo: https://github.com/pre-commit/mirrors-mypy
38
- rev: v1.14.1
39
- hooks:
40
- - id: mypy
41
- name: mypy
42
- entry: mypy
43
- language: python
44
- types: [python]
45
- additional_dependencies:
46
- - "pydantic>=2.8.2"
@@ -1 +0,0 @@
1
- 3.10.12