mojentic 0.5.3__tar.gz → 0.5.4__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 (104) hide show
  1. {mojentic-0.5.3/src/mojentic.egg-info → mojentic-0.5.4}/PKG-INFO +2 -1
  2. {mojentic-0.5.3 → mojentic-0.5.4}/pyproject.toml +2 -1
  3. mojentic-0.5.4/src/_examples/oversized_embeddings.py +9 -0
  4. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/agents/iterative_problem_solver.py +5 -2
  5. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/agents/simple_recursive_agent.py +2 -2
  6. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/gateways/openai.py +29 -6
  7. {mojentic-0.5.3 → mojentic-0.5.4/src/mojentic.egg-info}/PKG-INFO +2 -1
  8. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic.egg-info/SOURCES.txt +1 -0
  9. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic.egg-info/requires.txt +1 -0
  10. {mojentic-0.5.3 → mojentic-0.5.4}/LICENSE.md +0 -0
  11. {mojentic-0.5.3 → mojentic-0.5.4}/README.md +0 -0
  12. {mojentic-0.5.3 → mojentic-0.5.4}/setup.cfg +0 -0
  13. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/__init__.py +0 -0
  14. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/broker_as_tool.py +0 -0
  15. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/broker_examples.py +0 -0
  16. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/characterize_ollama.py +0 -0
  17. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/characterize_openai.py +0 -0
  18. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/chat_session.py +0 -0
  19. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/chat_session_with_tool.py +0 -0
  20. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/coding_file_tool.py +0 -0
  21. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/current_datetime_tool_example.py +0 -0
  22. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/design_analysis.py +0 -0
  23. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/embeddings.py +0 -0
  24. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/ensures_files_exist.py +0 -0
  25. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/file_deduplication.py +0 -0
  26. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/file_tool.py +0 -0
  27. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/image_analysis.py +0 -0
  28. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/image_broker.py +0 -0
  29. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/image_broker_splat.py +0 -0
  30. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/iterative_solver.py +0 -0
  31. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/list_models.py +0 -0
  32. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/raw.py +0 -0
  33. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/react/__init__.py +0 -0
  34. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/react/agents/__init__.py +0 -0
  35. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/react/agents/decisioning_agent.py +0 -0
  36. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/react/agents/thinking_agent.py +0 -0
  37. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/react/formatters.py +0 -0
  38. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/react/models/__init__.py +0 -0
  39. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/react/models/base.py +0 -0
  40. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/react/models/events.py +0 -0
  41. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/react.py +0 -0
  42. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/recursive_agent.py +0 -0
  43. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/routed_send_response.py +0 -0
  44. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/simple_llm.py +0 -0
  45. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/simple_llm_repl.py +0 -0
  46. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/simple_structured.py +0 -0
  47. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/simple_tool.py +0 -0
  48. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/solver_chat_session.py +0 -0
  49. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/streaming.py +0 -0
  50. {mojentic-0.5.3 → mojentic-0.5.4}/src/_examples/working_memory.py +0 -0
  51. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/__init__.py +0 -0
  52. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/agents/__init__.py +0 -0
  53. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/agents/agent_broker.py +0 -0
  54. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/agents/base_agent.py +0 -0
  55. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/agents/base_llm_agent.py +0 -0
  56. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/agents/base_llm_agent_spec.py +0 -0
  57. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/agents/correlation_aggregator_agent.py +0 -0
  58. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/agents/output_agent.py +0 -0
  59. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/audit/event_store.py +0 -0
  60. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/audit/event_store_spec.py +0 -0
  61. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/context/__init__.py +0 -0
  62. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/context/shared_working_memory.py +0 -0
  63. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/dispatcher.py +0 -0
  64. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/event.py +0 -0
  65. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/__init__.py +0 -0
  66. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/chat_session.py +0 -0
  67. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/chat_session_spec.py +0 -0
  68. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/gateways/__init__.py +0 -0
  69. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/gateways/anthropic.py +0 -0
  70. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/gateways/anthropic_messages_adapter.py +0 -0
  71. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/gateways/embeddings_gateway.py +0 -0
  72. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/gateways/file_gateway.py +0 -0
  73. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/gateways/llm_gateway.py +0 -0
  74. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/gateways/models.py +0 -0
  75. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/gateways/ollama.py +0 -0
  76. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/gateways/ollama_messages_adapter.py +0 -0
  77. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/gateways/ollama_messages_adapter_spec.py +0 -0
  78. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/gateways/openai_message_adapter_spec.py +0 -0
  79. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/gateways/openai_messages_adapter.py +0 -0
  80. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/gateways/tokenizer_gateway.py +0 -0
  81. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/llm_broker.py +0 -0
  82. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/llm_broker_spec.py +0 -0
  83. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/message_composers.py +0 -0
  84. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/message_composers_spec.py +0 -0
  85. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/registry/__init__.py +0 -0
  86. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/registry/llm_registry.py +0 -0
  87. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/registry/models.py +0 -0
  88. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/registry/populate_registry_from_ollama.py +0 -0
  89. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/tools/__init__.py +0 -0
  90. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/tools/ask_user_tool.py +0 -0
  91. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/tools/current_datetime.py +0 -0
  92. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/tools/date_resolver.py +0 -0
  93. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/tools/date_resolver_spec.py +0 -0
  94. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/tools/file_manager.py +0 -0
  95. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/tools/llm_tool.py +0 -0
  96. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/tools/tool_wrapper.py +0 -0
  97. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/tools/tool_wrapper_spec.py +0 -0
  98. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/llm/tools/web_search.py +0 -0
  99. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/router.py +0 -0
  100. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/router_spec.py +0 -0
  101. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/utils/__init__.py +0 -0
  102. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic/utils/formatting.py +0 -0
  103. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic.egg-info/dependency_links.txt +0 -0
  104. {mojentic-0.5.3 → mojentic-0.5.4}/src/mojentic.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mojentic
3
- Version: 0.5.3
3
+ Version: 0.5.4
4
4
  Summary: Mojentic is an agentic framework that aims to provide a simple and flexible way to assemble teams of agents to solve complex problems.
5
5
  Author-email: Stacey Vetzal <stacey@vetzal.com>
6
6
  Project-URL: Homepage, https://github.com/mojility/mojentic
@@ -13,6 +13,7 @@ Description-Content-Type: text/markdown
13
13
  License-File: LICENSE.md
14
14
  Requires-Dist: pydantic
15
15
  Requires-Dist: structlog
16
+ Requires-Dist: numpy
16
17
  Requires-Dist: ollama
17
18
  Requires-Dist: openai
18
19
  Requires-Dist: anthropic
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mojentic"
3
- version = "0.5.3"
3
+ version = "0.5.4"
4
4
  authors = [
5
5
  { name = "Stacey Vetzal", email = "stacey@vetzal.com" },
6
6
  ]
@@ -16,6 +16,7 @@ classifiers = [
16
16
  dependencies = [
17
17
  "pydantic",
18
18
  "structlog",
19
+ "numpy",
19
20
  "ollama",
20
21
  "openai",
21
22
  "anthropic",
@@ -0,0 +1,9 @@
1
+ import os
2
+
3
+ from mojentic.llm.gateways import OllamaGateway, OpenAIGateway
4
+
5
+ ollama = OllamaGateway()
6
+ print(len(ollama.calculate_embeddings("Hello, world! " * 5000)))
7
+
8
+ openai = OpenAIGateway(os.environ["OPENAI_API_KEY"])
9
+ print(len(openai.calculate_embeddings("Hello, world! " * 5000)))
@@ -26,7 +26,8 @@ class IterativeProblemSolver:
26
26
  max_iterations: int
27
27
  chat: ChatSession
28
28
 
29
- def __init__(self, llm: LLMBroker, available_tools: Optional[List[LLMTool]] = None, max_iterations: int = 3):
29
+ def __init__(self, llm: LLMBroker, available_tools: Optional[List[LLMTool]] = None, max_iterations: int = 3,
30
+ system_prompt: Optional[str] = None):
30
31
  """Initialize the IterativeProblemSolver.
31
32
 
32
33
  Parameters
@@ -42,7 +43,9 @@ class IterativeProblemSolver:
42
43
  self.available_tools = available_tools or []
43
44
  self.chat = ChatSession(
44
45
  llm=llm,
45
- system_prompt="You are a helpful assistant, working on behalf of the user on a specific user request.",
46
+ system_prompt=system_prompt or "You are a problem-solving assistant that can solve complex problems step by step. "
47
+ "You analyze problems, break them down into smaller parts, and solve them systematically. "
48
+ "If you cannot solve a problem completely in one step, you make progress and identify what to do next.",
46
49
  tools=self.available_tools,
47
50
  )
48
51
 
@@ -140,7 +140,7 @@ class SimpleRecursiveAgent:
140
140
  emitter: EventEmitter
141
141
  chat: ChatSession
142
142
 
143
- def __init__(self, llm: LLMBroker, available_tools: Optional[List[LLMTool]] = None, max_iterations: int = 5):
143
+ def __init__(self, llm: LLMBroker, available_tools: Optional[List[LLMTool]] = None, max_iterations: int = 5, system_prompt: Optional[str] = None):
144
144
  """
145
145
  Initialize the SimpleRecursiveAgent.
146
146
 
@@ -161,7 +161,7 @@ class SimpleRecursiveAgent:
161
161
  # Initialize the chat session
162
162
  self.chat = ChatSession(
163
163
  llm=llm,
164
- system_prompt="You are a problem-solving assistant that can solve complex problems step by step. "
164
+ system_prompt=system_prompt or "You are a problem-solving assistant that can solve complex problems step by step. "
165
165
  "You analyze problems, break them down into smaller parts, and solve them systematically. "
166
166
  "If you cannot solve a problem completely in one step, you make progress and identify what to do next.",
167
167
  tools=self.available_tools
@@ -1,12 +1,15 @@
1
1
  import json
2
- from typing import Type, List
2
+ from itertools import islice
3
+ from typing import Type, List, Iterable
3
4
 
5
+ import numpy as np
4
6
  import structlog
5
7
  from openai import OpenAI
6
8
 
7
9
  from mojentic.llm.gateways.llm_gateway import LLMGateway
8
10
  from mojentic.llm.gateways.models import LLMToolCall, LLMGatewayResponse
9
11
  from mojentic.llm.gateways.openai_messages_adapter import adapt_messages_to_openai
12
+ from mojentic.llm.gateways.tokenizer_gateway import TokenizerGateway
10
13
 
11
14
  logger = structlog.get_logger()
12
15
 
@@ -121,8 +124,28 @@ class OpenAIGateway(LLMGateway):
121
124
  The embeddings for the text.
122
125
  """
123
126
  logger.debug("calculate_embeddings", text=text, model=model)
124
- response = self.client.embeddings.create(
125
- model=model,
126
- input=text
127
- )
128
- return response.data[0].embedding
127
+
128
+ embeddings = [self.client.embeddings.create(model=model, input=chunk).data[0].embedding
129
+ for chunk in self._chunked_tokens(text, 8191)]
130
+ lengths = [len(embedding) for embedding in embeddings]
131
+
132
+ average = np.average(embeddings, axis=0, weights=lengths)
133
+ average = average / np.linalg.norm(average)
134
+ average = average.tolist()
135
+
136
+ return average
137
+
138
+ def _batched(self, iterable: Iterable, n: int):
139
+ """Batch data into tuples of length n. The last batch may be shorter."""
140
+ # batched('ABCDEFG', 3) --> ABC DEF G
141
+ if n < 1:
142
+ raise ValueError('n must be at least one')
143
+ it = iter(iterable)
144
+ while batch := tuple(islice(it, n)):
145
+ yield batch
146
+
147
+ def _chunked_tokens(self, text, chunk_length):
148
+ tokenizer = TokenizerGateway()
149
+ tokens = tokenizer.encode(text)
150
+ chunks_iterator = self._batched(tokens, chunk_length)
151
+ yield from chunks_iterator
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mojentic
3
- Version: 0.5.3
3
+ Version: 0.5.4
4
4
  Summary: Mojentic is an agentic framework that aims to provide a simple and flexible way to assemble teams of agents to solve complex problems.
5
5
  Author-email: Stacey Vetzal <stacey@vetzal.com>
6
6
  Project-URL: Homepage, https://github.com/mojility/mojentic
@@ -13,6 +13,7 @@ Description-Content-Type: text/markdown
13
13
  License-File: LICENSE.md
14
14
  Requires-Dist: pydantic
15
15
  Requires-Dist: structlog
16
+ Requires-Dist: numpy
16
17
  Requires-Dist: ollama
17
18
  Requires-Dist: openai
18
19
  Requires-Dist: anthropic
@@ -21,6 +21,7 @@ src/_examples/image_broker.py
21
21
  src/_examples/image_broker_splat.py
22
22
  src/_examples/iterative_solver.py
23
23
  src/_examples/list_models.py
24
+ src/_examples/oversized_embeddings.py
24
25
  src/_examples/raw.py
25
26
  src/_examples/react.py
26
27
  src/_examples/recursive_agent.py
@@ -1,5 +1,6 @@
1
1
  pydantic
2
2
  structlog
3
+ numpy
3
4
  ollama
4
5
  openai
5
6
  anthropic
File without changes
File without changes
File without changes
File without changes
File without changes