You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/openagi/prompts/worker_task_execution.py
+5-10Lines changed: 5 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,7 @@
1
-
fromtextwrapimportdedent
2
-
3
1
fromopenagi.prompts.baseimportBasePrompt
4
2
5
-
WORKER_TASK_EXECUTION=dedent(
6
-
"""
7
-
You: {worker_description}
3
+
WORKER_TASK_EXECUTION="""
4
+
You are expert in: {worker_description}
8
5
9
6
# Instructions
10
7
- You run in a loop of Thought, Action, Observation. Follow the instructions below to understand the workflow and follow them in each iteration of the loop.
@@ -13,9 +10,9 @@
13
10
- Observation will be the result of running those actions. Make sure to thoroughly analyze the observation to see if it aligns with your expectations.
14
11
- On each observation, try to understand the drawbacks and mistakes and learn from them to improve further and get back on track.
15
12
- Take the context into account when you are answering the question. It will be the results or data from the past executions. If no context is provided, then you can assume that the context is empty and you can start from scratch. Use context to ensure consistency and accuracy in your responses.
16
-
- Output the answer when you feel the observations are correct and aligned with the goal. They do not have to be very accurate, but ensure they are reasonably reliable.
17
-
- The output should always be in the following format in all the iterations. Ensure the JSON format is suitable for utilization with json.loads(), enclosed in triple backticks:
13
+
- Output the answer when you feel the observations are reasonably good and aligned with the goal. They do not have to be very accurate, but ensure they are reasonably reliable.
18
14
- No Action/Output should be without json. Trying not include your thoughts as part of the action. You can skip the action if not required.
Copy file name to clipboardExpand all lines: src/openagi/utils/extraction.py
+34-62Lines changed: 34 additions & 62 deletions
Original file line number
Diff line number
Diff line change
@@ -2,47 +2,27 @@
2
2
importjson
3
3
importlogging
4
4
importre
5
-
fromtextwrapimportdedent
6
5
fromtypingimportDict, List, Optional, Tuple
7
6
8
7
fromopenagi.exceptionimportOpenAGIException
9
8
fromopenagi.llms.baseimportLLMBaseModel
10
9
11
10
12
-
defforce_json_output(resp_txt: str, llm):
11
+
defforce_json_output(resp_txt: str, llm)->str:
13
12
"""
14
-
Forces the output once the max iterations are reached.
13
+
Forces proper JSON output format in first attempt.
15
14
"""
16
-
#prompt = dedent(
17
-
# """
18
-
# Below is a JSON block. Please try to provide the output in the format shown below only
19
-
# ```json
20
-
# {"key": "value"}
21
-
# ```
22
-
# the contents between ```json and ``` will be extracted and passed to json.loads() in python to convert it to a dictionary. Make sure that it works when passed else you will be fined. If its already in the correct format, then you can return the same output in the expected output format.
23
-
# Input:
24
-
# {resp_txt}
25
-
# Output:
26
-
# """
27
-
#).strip()
28
-
29
-
prompt=dedent(
30
-
"""
31
-
Your task is to process the input JSON and provide a valid JSON output. Follow these instructions carefully:
32
-
1. The output must be enclosed in a code block using triple backticks and the 'json' language identifier, like this:
33
-
```json
34
-
{"key": "value"}
35
-
```
36
-
2. The JSON inside the code block must be valid and parseable by Python's json.loads() function.
37
-
3. Ensure there are no extra spaces, newlines, or characters outside the JSON object within the code block.
38
-
4. If the input is already in the correct format, reproduce it exactly in the output format specified above.
39
-
5. Do not include any explanations, comments, or additional text in your response. The output needs be in JSON only.
40
-
6. Verify your output carefully before submitting. Incorrect responses will result in penalties.
15
+
prompt="""
16
+
You are a JSON formatting expert. Your task is to process the input and provide a valid JSON output.
41
17
42
-
Input: {resp_txt}
43
-
Output:
44
-
"""
45
-
).strip()
18
+
FOLLOW THESE INSTRUCTIONS to convert:
19
+
- Output must be ONLY a JSON object wrapped in ```json code block
20
+
- Do not include any explanations, comments, or additional text in your response. The output needs be in JSON only.
0 commit comments