prompt-caller 0.1.0__py3-none-any.whl → 0.1.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.
@@ -19,6 +19,9 @@ load_dotenv()
19
19
 
20
20
  class PromptCaller:
21
21
 
22
+ def __init__(self, promptPath="prompts"):
23
+ self.promptPath = promptPath
24
+
22
25
  def _loadPrompt(self, file_path):
23
26
  with open(file_path, "r", encoding="utf-8") as file:
24
27
  content = file.read()
@@ -62,7 +65,7 @@ class PromptCaller:
62
65
  context = {}
63
66
 
64
67
  configuration, template = self._loadPrompt(
65
- os.path.join("prompts", f"{promptName}.prompt")
68
+ os.path.join(self.promptPath, f"{promptName}.prompt")
66
69
  )
67
70
 
68
71
  template = self._renderTemplate(template, context)
@@ -126,14 +129,16 @@ class PromptCaller:
126
129
 
127
130
  return response
128
131
 
129
- def agent(self, promptName, context=None, tools=None, allowed_steps=3):
132
+ def agent(
133
+ self, promptName, context=None, tools=None, output=None, allowed_steps=10
134
+ ):
130
135
 
131
136
  configuration, messages = self.loadPrompt(promptName, context)
132
137
 
133
- output = None
138
+ dynamicOutput = None
134
139
 
135
- if "output" in configuration:
136
- output = configuration.get("output")
140
+ if output is None and "output" in configuration:
141
+ dynamicOutput = configuration.get("output")
137
142
  configuration.pop("output")
138
143
 
139
144
  for message in messages:
@@ -153,10 +158,13 @@ class PromptCaller:
153
158
  tools_dict = {t.name.lower(): t for t in tools}
154
159
 
155
160
  if output:
161
+ tools.extend([output])
162
+ tools_dict[output.__name__.lower()] = output
163
+ elif dynamicOutput:
156
164
  dynamicModel = self.createPydanticModel(output)
157
165
 
158
- tools.extend([dynamicModel])
159
- tools_dict["dynamicmodel"] = dynamicModel
166
+ tools.extend([dynamicModel])
167
+ tools_dict["dynamicmodel"] = dynamicModel
160
168
 
161
169
  chat = chat.bind_tools(tools)
162
170
 
@@ -171,9 +179,12 @@ class PromptCaller:
171
179
  tool_name = tool_call["name"].lower()
172
180
 
173
181
  # If it's the final formatting tool, validate and return
174
- if tool_name == "dynamicmodel":
182
+ if dynamicOutput and tool_name == "dynamicmodel":
175
183
  return dynamicModel.model_validate(tool_call["args"])
176
184
 
185
+ if output and tool_name == output.__name__.lower():
186
+ return output.model_validate(tool_call["args"])
187
+
177
188
  selected_tool = tools_dict.get(tool_name)
178
189
  if not selected_tool:
179
190
  raise ValueError(f"Unknown tool: {tool_name}")
@@ -199,5 +210,6 @@ class PromptCaller:
199
210
  return response
200
211
 
201
212
  except Exception as e:
213
+ print(e)
202
214
  # Replace with appropriate logging in production
203
215
  raise RuntimeError("Error during agent process") from e
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prompt_caller
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: This package is responsible for calling prompts in a specific format. It uses LangChain and OpenAI API
5
5
  Home-page: https://github.com/ThiNepo/prompt-caller
6
6
  Author: Thiago Nepomuceno
@@ -89,33 +89,33 @@ In this example:
89
89
 
90
90
  3. **Using the agent feature:**
91
91
 
92
- The `agent` method allows you to enhance the prompt's functionality by integrating external tools. Here’s an example where we evaluate a mathematical expression using Python’s `eval` in a safe execution environment:
92
+ The `agent` method allows you to enhance the prompt's functionality by integrating external tools. Here’s an example where we evaluate a mathematical expression using Python’s `eval` in a safe execution environment:
93
93
 
94
- ```python
95
- from prompt_caller import PromptCaller
94
+ ```python
95
+ from prompt_caller import PromptCaller
96
96
 
97
- ai = PromptCaller()
97
+ ai = PromptCaller()
98
98
 
99
- def evaluate_expression(expression: str):
100
- """
101
- Evaluate a math expression using eval.
102
- """
103
- safe_globals = {"__builtins__": None}
104
- return eval(expression, safe_globals, {})
99
+ def evaluate_expression(expression: str):
100
+ """
101
+ Evaluate a math expression using eval.
102
+ """
103
+ safe_globals = {"__builtins__": None}
104
+ return eval(expression, safe_globals, {})
105
105
 
106
- response = ai.agent(
107
- "sample-agent", {"expression": "3+8/9"}, tools=[evaluate_expression]
108
- )
106
+ response = ai.agent(
107
+ "sample-agent", {"expression": "3+8/9"}, tools=[evaluate_expression]
108
+ )
109
109
 
110
- print(response)
111
- ```
110
+ print(response)
111
+ ```
112
+
113
+ In this example:
112
114
 
113
- In this example:
115
+ - The `agent` method is used to process the prompt while integrating external tools.
116
+ - The `evaluate_expression` function evaluates the mathematical expression securely.
117
+ - The response includes the processed result based on the prompt and tool execution.
114
118
 
115
- - The `agent` method is used to process the prompt while integrating external tools.
116
- - The `evaluate_expression` function evaluates the mathematical expression securely.
117
- - The response includes the processed result based on the prompt and tool execution.
118
-
119
119
 
120
120
  ## How It Works
121
121
 
@@ -0,0 +1,8 @@
1
+ prompt_caller/__init__.py,sha256=4EGdeAJ_Ig7A-b-e17-nYbiXjckT7uL3to5lchMsoW4,41
2
+ prompt_caller/__main__.py,sha256=dJ0dYtVmnhZuoV79R6YiAIta1ZkUKb-TEX4VEuYbgk0,139
3
+ prompt_caller/prompt_caller.py,sha256=zAJq_5v-ku_O9ACAw7C7JU1RmVwlIvunbd-31B0XX6E,7119
4
+ prompt_caller-0.1.2.dist-info/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
5
+ prompt_caller-0.1.2.dist-info/METADATA,sha256=IjSAGTvmJbi7X6_5f3OxvH6QA7l9H6Opx4d9wtGGRak,4909
6
+ prompt_caller-0.1.2.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
7
+ prompt_caller-0.1.2.dist-info/top_level.txt,sha256=iihiDRq-0VrKB8IKjxf7Lrtv-fLMq4tvgM4fH3x0I94,14
8
+ prompt_caller-0.1.2.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- prompt_caller/__init__.py,sha256=4EGdeAJ_Ig7A-b-e17-nYbiXjckT7uL3to5lchMsoW4,41
2
- prompt_caller/__main__.py,sha256=dJ0dYtVmnhZuoV79R6YiAIta1ZkUKb-TEX4VEuYbgk0,139
3
- prompt_caller/prompt_caller.py,sha256=FlQEmNJWrxrdLMaoTxsCfPPcbr3DXWN5Oq1pp45yVQM,6644
4
- prompt_caller-0.1.0.dist-info/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
5
- prompt_caller-0.1.0.dist-info/METADATA,sha256=0ciKS5ENrpqRA6EjrulhMu_R-7iwWwmMEbiYpjJbymk,4957
6
- prompt_caller-0.1.0.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
7
- prompt_caller-0.1.0.dist-info/top_level.txt,sha256=iihiDRq-0VrKB8IKjxf7Lrtv-fLMq4tvgM4fH3x0I94,14
8
- prompt_caller-0.1.0.dist-info/RECORD,,