zrb 1.4.1__py3-none-any.whl → 1.4.2__py3-none-any.whl

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.
@@ -22,7 +22,6 @@ from zrb.config import (
22
22
  LLM_ALLOW_ACCESS_LOCAL_FILE,
23
23
  LLM_ALLOW_ACCESS_SHELL,
24
24
  LLM_HISTORY_DIR,
25
- LLM_SYSTEM_PROMPT,
26
25
  SERP_API_KEY,
27
26
  )
28
27
  from zrb.context.any_shared_context import AnySharedContext
@@ -119,7 +118,7 @@ llm_chat: LLMTask = llm_group.add_task(
119
118
  "system-prompt",
120
119
  description="System prompt",
121
120
  prompt="System prompt",
122
- default=LLM_SYSTEM_PROMPT,
121
+ default="",
123
122
  allow_positional_parsing=False,
124
123
  always_prompt=False,
125
124
  ),
@@ -141,17 +140,19 @@ llm_chat: LLMTask = llm_group.add_task(
141
140
  always_prompt=False,
142
141
  ),
143
142
  ],
144
- model=lambda ctx: None if ctx.input.model == "" else ctx.input.model,
143
+ model=lambda ctx: None if ctx.input.model.strip() == "" else ctx.input.model,
145
144
  model_base_url=lambda ctx: (
146
- None if ctx.input.base_url == "" else ctx.input.base_url
145
+ None if ctx.input.base_url.strip() == "" else ctx.input.base_url
147
146
  ),
148
147
  model_api_key=lambda ctx: (
149
- None if ctx.input.api_key == "" else ctx.input.api_key
148
+ None if ctx.input.api_key.strip() == "" else ctx.input.api_key
150
149
  ),
151
150
  conversation_history_reader=_read_chat_conversation,
152
151
  conversation_history_writer=_write_chat_conversation,
153
152
  description="Chat with LLM",
154
- system_prompt="{ctx.input.system_prompt}",
153
+ system_prompt=lambda ctx: (
154
+ None if ctx.input.system_prompt.strip() == "" else ctx.input.system_prompt
155
+ ),
155
156
  message="{ctx.input.message}",
156
157
  retries=0,
157
158
  ),
@@ -127,12 +127,12 @@ def _should_exclude(full_path: str, excluded_patterns: list[str]) -> bool:
127
127
 
128
128
 
129
129
  def read_text_file(file: str) -> str:
130
- """Read a text file"""
130
+ """Read a text file and return a string containing the file content."""
131
131
  return read_file(os.path.abspath(file))
132
132
 
133
133
 
134
134
  def write_text_file(file: str, content: str):
135
- """Write a text file"""
135
+ """Write content to a text file"""
136
136
  return write_file(os.path.abspath(file), content)
137
137
 
138
138
 
zrb/config.py CHANGED
@@ -76,15 +76,6 @@ WEB_AUTH_REFRESH_TOKEN_EXPIRE_MINUTES = int(
76
76
  os.getenv("ZRB_WEB_REFRESH_TOKEN_EXPIRE_MINUTES", "60")
77
77
  )
78
78
 
79
- _DEFAULT_PROMPT = (
80
- "You are a helpful AI assistant capable of using various tools to answer user queries. When solving a problem:\n"
81
- "1. Carefully analyze the user's request and identify what information is needed to provide a complete answer.\n"
82
- "2. Determine which available tools can help you gather the necessary information.\n"
83
- "3. Call tools strategically and in a logical sequence to collect required data.\n"
84
- "4. If a tool provides incomplete information, intelligently decide which additional tool or approach to use.\n"
85
- "5. Always aim to provide the most accurate and helpful response possible."
86
- )
87
- LLM_SYSTEM_PROMPT = os.getenv("ZRB_LLM_SYSTEM_PROMPT", _DEFAULT_PROMPT)
88
79
  LLM_HISTORY_DIR = os.getenv(
89
80
  "ZRB_LLM_HISTORY_DIR", os.path.expanduser(os.path.join("~", ".zrb-llm-history"))
90
81
  )
zrb/llm_config.py CHANGED
@@ -4,23 +4,49 @@ from pydantic_ai.models import Model
4
4
  from pydantic_ai.models.openai import OpenAIModel
5
5
  from pydantic_ai.providers.openai import OpenAIProvider
6
6
 
7
+ DEFAULT_SYSTEM_PROMPT = """
8
+ You have access to tools.
9
+ Your goal to to answer user queries accurately.
10
+ Follow these instructions precisely:
11
+ 1. ALWAYS use available tools to gather information BEFORE asking the user questions
12
+ 2. For tools that require arguments: provide arguments in valid JSON format
13
+ 3. For tools that require NO arguments: call with empty JSON object ({}) NOT empty string ('')
14
+ 4. NEVER pass arguments to tools that don't accept parameters
15
+ 5. NEVER ask users for information obtainable through tools
16
+ 6. Use tools in logical sequence until you have sufficient information
17
+ 7. If a tool call fails, check if you're passing arguments in the correct format
18
+ 8. Only after exhausting relevant tools should you request clarification
19
+ """.strip()
20
+
7
21
 
8
22
  class LLMConfig:
9
23
 
10
24
  def __init__(
11
25
  self,
12
- model_name: str | None = None,
13
- base_url: str | None = None,
14
- api_key: str | None = None,
26
+ default_model_name: str | None = None,
27
+ default_base_url: str | None = None,
28
+ default_api_key: str | None = None,
29
+ default_system_prompt: str | None = None,
15
30
  ):
16
31
  self._model_name = (
17
- model_name if model_name is not None else os.getenv("ZRB_LLM_MODEL", None)
32
+ default_model_name
33
+ if default_model_name is not None
34
+ else os.getenv("ZRB_LLM_MODEL", None)
35
+ )
36
+ self._model_base_url = (
37
+ default_base_url
38
+ if default_base_url is not None
39
+ else os.getenv("ZRB_LLM_BASE_URL", None)
18
40
  )
19
- self._base_url = (
20
- base_url if base_url is not None else os.getenv("ZRB_LLM_BASE_URL", None)
41
+ self._model_api_key = (
42
+ default_api_key
43
+ if default_api_key is not None
44
+ else os.getenv("ZRB_LLM_API_KEY", None)
21
45
  )
22
- self._api_key = (
23
- api_key if api_key is not None else os.getenv("ZRB_LLM_API_KEY", None)
46
+ self._system_prompt = (
47
+ default_system_prompt
48
+ if default_system_prompt is not None
49
+ else os.getenv("ZRB_LLM_SYSTEM_PROMPT", None)
24
50
  )
25
51
  self._default_model = None
26
52
 
@@ -28,9 +54,16 @@ class LLMConfig:
28
54
  return self._model_name if self._model_name is not None else None
29
55
 
30
56
  def _get_model_provider(self) -> OpenAIProvider:
31
- if self._base_url is None and self._api_key is None:
57
+ if self._model_base_url is None and self._model_api_key is None:
32
58
  return "openai"
33
- return OpenAIProvider(base_url=self._base_url, api_key=self._api_key)
59
+ return OpenAIProvider(
60
+ base_url=self._model_base_url, api_key=self._model_api_key
61
+ )
62
+
63
+ def get_default_system_prompt(self) -> str:
64
+ if self._system_prompt is not None:
65
+ return self._system_prompt
66
+ return DEFAULT_SYSTEM_PROMPT
34
67
 
35
68
  def get_default_model(self) -> Model | str | None:
36
69
  if self._default_model is not None:
@@ -43,6 +76,18 @@ class LLMConfig:
43
76
  provider=self._get_model_provider(),
44
77
  )
45
78
 
79
+ def set_default_system_prompt(self, system_prompt: str):
80
+ self._system_prompt = system_prompt
81
+
82
+ def set_default_model_name(self, model_name: str):
83
+ self._model_name = model_name
84
+
85
+ def set_default_model_api_key(self, model_api_key: str):
86
+ self._model_api_key = model_api_key
87
+
88
+ def set_default_model_base_url(self, model_base_url: str):
89
+ self._model_base_url = model_base_url
90
+
46
91
  def set_default_model(self, model: Model | str | None):
47
92
  self._default_model = model
48
93
 
zrb/task/llm_task.py CHANGED
@@ -18,7 +18,6 @@ from pydantic_ai.models import Model
18
18
  from pydantic_ai.settings import ModelSettings
19
19
 
20
20
  from zrb.attr.type import StrAttr, fstring
21
- from zrb.config import LLM_SYSTEM_PROMPT
22
21
  from zrb.context.any_context import AnyContext
23
22
  from zrb.context.any_shared_context import AnySharedContext
24
23
  from zrb.env.any_env import AnyEnv
@@ -58,7 +57,7 @@ class LLMTask(BaseTask):
58
57
  ModelSettings | Callable[[AnySharedContext], ModelSettings] | None
59
58
  ) = None,
60
59
  agent: Agent | Callable[[AnySharedContext], Agent] | None = None,
61
- system_prompt: StrAttr | None = LLM_SYSTEM_PROMPT,
60
+ system_prompt: StrAttr | None = None,
62
61
  render_system_prompt: bool = True,
63
62
  message: StrAttr | None = None,
64
63
  tools: (
@@ -258,14 +257,14 @@ class LLMTask(BaseTask):
258
257
  return default_llm_config.get_default_model()
259
258
  if isinstance(model, str):
260
259
  llm_config = LLMConfig(
261
- model_name=model,
262
- base_url=get_attr(
260
+ default_model_name=model,
261
+ default_base_url=get_attr(
263
262
  ctx,
264
263
  self._get_model_base_url(ctx),
265
264
  None,
266
265
  auto_render=self._render_model_base_url,
267
266
  ),
268
- api_key=get_attr(
267
+ default_api_key=get_attr(
269
268
  ctx,
270
269
  self._get_model_api_key(ctx),
271
270
  None,
@@ -292,12 +291,15 @@ class LLMTask(BaseTask):
292
291
  raise ValueError(f"Invalid model base URL: {api_key}")
293
292
 
294
293
  def _get_system_prompt(self, ctx: AnyContext) -> str:
295
- return get_str_attr(
294
+ system_prompt = get_attr(
296
295
  ctx,
297
296
  self._system_prompt,
298
- "You are a helpful assistant",
297
+ None,
299
298
  auto_render=self._render_system_prompt,
300
299
  )
300
+ if system_prompt is not None:
301
+ return system_prompt
302
+ return default_llm_config.get_default_system_prompt()
301
303
 
302
304
  def _get_message(self, ctx: AnyContext) -> str:
303
305
  return get_str_attr(ctx, self._message, "How are you?", auto_render=True)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: zrb
3
- Version: 1.4.1
3
+ Version: 1.4.2
4
4
  Summary: Your Automation Powerhouse
5
5
  Home-page: https://github.com/state-alchemists/zrb
6
6
  License: AGPL-3.0-or-later
@@ -44,7 +44,6 @@ Description-Content-Type: text/markdown
44
44
 
45
45
  Zrb streamlines repetitive tasks, integrates with powerful LLMs, and lets you create custom automation workflows effortlessly. Whether you’re building CI/CD pipelines, code generators, or unique automation scripts, Zrb is designed to simplify and supercharge your workflow.
46
46
 
47
- ---
48
47
 
49
48
  ## 🚀 Why Zrb?
50
49
 
@@ -54,7 +53,6 @@ Zrb streamlines repetitive tasks, integrates with powerful LLMs, and lets you cr
54
53
  - **Developer-Friendly:** Quick to install and get started, with clear documentation and examples.
55
54
  - **Web Interface:** Run Zrb as a server to make tasks accessible even to non-technical team members.
56
55
 
57
- ---
58
56
 
59
57
  ## 🔥 Key Features
60
58
 
@@ -64,11 +62,8 @@ Zrb streamlines repetitive tasks, integrates with powerful LLMs, and lets you cr
64
62
  - **Flexible Input Handling:** Defaults, prompts, and command-line parameters to suit any workflow.
65
63
  - **Extensible & Open Source:** Contribute, customize, or extend Zrb to fit your unique needs.
66
64
 
67
- ---
68
65
 
69
- ## 🛠️ Getting Started
70
-
71
- ### Quick Installation
66
+ # 🛠️ Installation
72
67
 
73
68
  Install Zrb via pip:
74
69
 
@@ -84,7 +79,7 @@ bash -c "$(curl -fsSL https://raw.githubusercontent.com/state-alchemists/zrb/mai
84
79
 
85
80
  ```
86
81
 
87
- ### Your First Task
82
+ # 🍲 Quick Start
88
83
 
89
84
  Create a file at `/home/<your-user-name>/zrb_init.py` with the following content:
90
85
 
@@ -183,7 +178,8 @@ Now, let's see how things work in detail. First, Zrb generates a `state diagram.
183
178
 
184
179
  - **Step by step guide:** [Getting started with Zrb](https://github.com/state-alchemists/zrb/blob/main/docs/recipes/getting-started/README.md).
185
180
  - **Full documentation:** [Zrb Documentation](https://github.com/state-alchemists/zrb/blob/main/docs/README.md)
186
- - **Video demo:** [![Video Title](https://img.youtube.com/vi/W7dgk96l__o/0.jpg)](https://www.youtube.com/watch?v=W7dgk96l__o)
181
+ - **Video demo:**
182
+ [![Video Title](https://img.youtube.com/vi/W7dgk96l__o/0.jpg)](https://www.youtube.com/watch?v=W7dgk96l__o)
187
183
 
188
184
 
189
185
  # 🤝 Join the Community
@@ -7,11 +7,11 @@ zrb/builtin/base64.py,sha256=1YnSwASp7OEAvQcsnHZGpJEvYoI1Z2zTIJ1bCDHfcPQ,921
7
7
  zrb/builtin/git.py,sha256=8_qVE_2lVQEVXQ9vhiw8Tn4Prj1VZB78ZjEJJS5Ab3M,5461
8
8
  zrb/builtin/git_subtree.py,sha256=7BKwOkVTWDrR0DXXQ4iJyHqeR6sV5VYRt8y_rEB0EHg,3505
9
9
  zrb/builtin/group.py,sha256=-phJfVpTX3_gUwS1u8-RbZUHe-X41kxDBSmrVh4rq8E,1682
10
- zrb/builtin/llm/llm_chat.py,sha256=QCfxocM7UQPtpIWLMzr9wKbl9DCPcDZszAnPxszaww0,6071
10
+ zrb/builtin/llm/llm_chat.py,sha256=OwbeXNaskyufYIhbhLmj9JRYB9bw5D8JfntAzOhmrP8,6140
11
11
  zrb/builtin/llm/previous-session.js,sha256=xMKZvJoAbrwiyHS0OoPrWuaKxWYLoyR5sguePIoCjTY,816
12
12
  zrb/builtin/llm/tool/api.py,sha256=bXFE7jihdhUscxJH8lu5imwlYH735AalbCyUTl28BaQ,826
13
13
  zrb/builtin/llm/tool/cli.py,sha256=to_IjkfrMGs6eLfG0cpVN9oyADWYsJQCtyluUhUdBww,253
14
- zrb/builtin/llm/tool/file.py,sha256=8H_qXt4imsy28DD21wBIo4ud5zfnkFjLLm8Simo84Q8,4732
14
+ zrb/builtin/llm/tool/file.py,sha256=YkJ5RGwsqlv3ZxAcQDKqjlcOdmHYRJlZ6M9P49uMJEY,4792
15
15
  zrb/builtin/llm/tool/rag.py,sha256=vEIThEy0JGwXEiNRLOEJAHAE0l1Qie2qvU3ryioeYMk,6066
16
16
  zrb/builtin/llm/tool/web.py,sha256=SDnCtYHZ0Q4DtLbIhc11a0UyyKbTTeW60UfeIKzK35k,3204
17
17
  zrb/builtin/md5.py,sha256=0pNlrfZA0wlZlHvFHLgyqN0JZJWGKQIF5oXxO44_OJk,949
@@ -208,7 +208,7 @@ zrb/callback/callback.py,sha256=hKefB_Jd1XGjPSLQdMKDsGLHPzEGO2dqrIArLl_EmD0,848
208
208
  zrb/cmd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
209
209
  zrb/cmd/cmd_result.py,sha256=L8bQJzWCpcYexIxHBNsXj2pT3BtLmWex0iJSMkvimOA,597
210
210
  zrb/cmd/cmd_val.py,sha256=7Doowyg6BK3ISSGBLt-PmlhzaEkBjWWm51cED6fAUOQ,1014
211
- zrb/config.py,sha256=X0mlhmpUrYp_l4qI3CnsqOAfvxfLkteCOV9ABGF--Qc,4690
211
+ zrb/config.py,sha256=YBbpjH4Wnb8yQz0-982RCnbrdefdQy8SNZnJZJsfDvk,3985
212
212
  zrb/content_transformer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
213
213
  zrb/content_transformer/any_content_transformer.py,sha256=v8ZUbcix1GGeDQwB6OKX_1TjpY__ksxWVeqibwa_iZA,850
214
214
  zrb/content_transformer/content_transformer.py,sha256=STl77wW-I69QaGzCXjvkppngYFLufow8ybPLSyAvlHs,2404
@@ -237,7 +237,7 @@ zrb/input/option_input.py,sha256=TQB82ko5odgzkULEizBZi0e9TIHEbIgvdP0AR3RhA74,213
237
237
  zrb/input/password_input.py,sha256=szBojWxSP9QJecgsgA87OIYwQrY2AQ3USIKdDZY6snU,1465
238
238
  zrb/input/str_input.py,sha256=NevZHX9rf1g8eMatPyy-kUX3DglrVAQpzvVpKAzf7bA,81
239
239
  zrb/input/text_input.py,sha256=shvVbc2U8Is36h23M5lcW8IEwKc9FR-4uEPZZroj3rU,3377
240
- zrb/llm_config.py,sha256=SXSkDpmXxGLJaoUrT09oNdOGwHXc82TwIGssVeo6S7U,1553
240
+ zrb/llm_config.py,sha256=zNr46IOm8lGQKSp9yzWLfa4KOx5Yn_7xFoReyk2Cp9Y,3328
241
241
  zrb/runner/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
242
242
  zrb/runner/cli.py,sha256=0mT0oO_yEhc8N4nYCJNujhgLjVykZ0B-kAOFXyAvAqM,6672
243
243
  zrb/runner/common_util.py,sha256=0zhZn1Jdmr194_nsL5_L-Kn9-_NDpMTI2z6_LXUQJ-U,1369
@@ -300,7 +300,7 @@ zrb/task/base_task.py,sha256=SQRf37bylS586KwyW0eYDe9JZ5Hl18FP8kScHae6y3A,21251
300
300
  zrb/task/base_trigger.py,sha256=jC722rDvodaBLeNaFghkTyv1u0QXrK6BLZUUqcmBJ7Q,4581
301
301
  zrb/task/cmd_task.py,sha256=pUKRSR4DZKjbmluB6vi7cxqyhxOLfJ2czSpYeQbiDvo,10705
302
302
  zrb/task/http_check.py,sha256=Gf5rOB2Se2EdizuN9rp65HpGmfZkGc-clIAlHmPVehs,2565
303
- zrb/task/llm_task.py,sha256=Gf_Y8e3-U46wjnH5K36I1XJnFwwU-eTQlG5JL87UobM,13495
303
+ zrb/task/llm_task.py,sha256=m8B0dXsRZOo5h0FPEm3KJTEj378iAVpwxMMUfbZwTW0,13578
304
304
  zrb/task/make_task.py,sha256=PD3b_aYazthS8LHeJsLAhwKDEgdurQZpymJDKeN60u0,2265
305
305
  zrb/task/rsync_task.py,sha256=GSL9144bmp6F0EckT6m-2a1xG25AzrrWYzH4k3SVUKM,6370
306
306
  zrb/task/scaffolder.py,sha256=rME18w1HJUHXgi9eTYXx_T2G4JdqDYzBoNOkdOOo5-o,6806
@@ -341,7 +341,7 @@ zrb/util/string/name.py,sha256=8picJfUBXNpdh64GNaHv3om23QHhUZux7DguFLrXHp8,1163
341
341
  zrb/util/todo.py,sha256=1nDdwPc22oFoK_1ZTXyf3638Bg6sqE2yp_U4_-frHoc,16015
342
342
  zrb/xcom/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
343
343
  zrb/xcom/xcom.py,sha256=o79rxR9wphnShrcIushA0Qt71d_p3ZTxjNf7x9hJB78,1571
344
- zrb-1.4.1.dist-info/METADATA,sha256=qKftyv7rxRUk1eiIo5hUOZJY80melIT4RpgAPXVa1Ew,8135
345
- zrb-1.4.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
346
- zrb-1.4.1.dist-info/entry_points.txt,sha256=-Pg3ElWPfnaSM-XvXqCxEAa-wfVI6BEgcs386s8C8v8,46
347
- zrb-1.4.1.dist-info/RECORD,,
344
+ zrb-1.4.2.dist-info/METADATA,sha256=P5W8EKRiKGR4QNCpW0dtC-NJEXxoMfuTz9uHCwgY2WU,8096
345
+ zrb-1.4.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
346
+ zrb-1.4.2.dist-info/entry_points.txt,sha256=-Pg3ElWPfnaSM-XvXqCxEAa-wfVI6BEgcs386s8C8v8,46
347
+ zrb-1.4.2.dist-info/RECORD,,
File without changes