GoodLuckChuck commited on
Commit
d0370bd
·
verified ·
1 Parent(s): bd7c4b8

more instruction with gpt 4.1

Browse files
Files changed (1) hide show
  1. app.py +30 -11
app.py CHANGED
@@ -66,7 +66,7 @@ class AppConfig:
66
  OPENAI_MODEL_ID = "gpt-4.1" # Using a newer model, ensure API key has access
67
  SERPER_API_NUM_RESULTS = 3
68
  WEB_SEARCH_MAX_OUTPUT_LENGTH = 3000
69
- AGENT_MAX_STEPS = 10
70
  AGENT_VERBOSITY_LEVEL = 2 # 0: silent, 1: info, 2: debug
71
 
72
  AGENT_SYSTEM_PROMPT = """You are a highly intelligent and meticulous AI assistant. Your primary goal is to answer the user's question accurately and concisely.
@@ -78,7 +78,7 @@ Available Tools:
78
 
79
  Follow this process for every question:
80
  1. THOUGHT: Understand the user's question. Identify the core information needed.
81
- 2. THOUGHT: You MUST use the `web_search` tool with `provider="serpapi"` to get information from the internet.
82
  3. CODE (if using a tool):
83
  ```python
84
  # Your Python code to call the web_search tool.
@@ -89,17 +89,36 @@ Follow this process for every question:
89
  # print(search_result)
90
  ```<end_code>
91
  4. OBSERVATION: [The system will insert the printed output of your tool call here.]
92
- 5. THOUGHT: Analyze the observation. Is it what you expected? Do you have enough information to answer the user's question now? If not, refine your search.
93
  6. If you have the information, formulate the final answer according to the formatting rules.
94
 
95
- CRITICAL: Your *entire response* to the user for each turn must culminate in the final answer using this exact template on a new line:
96
- FINAL ANSWER: [Your concise answer, strictly following the formatting rules below. Do NOT include your thought process here, only the answer itself.]
97
-
98
- Formatting rules for the value in FINAL ANSWER:
99
- - If the question asks for a number: Provide only the number itself (e.g., 42). Do not use commas for thousands separation (e.g., use 1234 not 1,234). Do not include units like '$' or '%' unless the question specifically asks for it and it's part of the answer.
100
- - If the question asks for a string: Provide the most concise string possible. Avoid articles (a, an, the) unless grammatically essential. Avoid common abbreviations (e.g., for cities like "NYC" for "New York City") unless the question implies it. Write out numerical digits as words (e.g., "two" instead of 2) unless numerical digits are requested.
101
- - If the question asks for a comma-separated list: Apply the above string/number rules to each element. Ensure elements are separated ONLY by a comma (e.g., item one,item two,three). NO space after the comma unless it's part of the item itself.
102
- - If the answer is a calculation result, provide just the number.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  """
104
 
105
  CONFIG = AppConfig()
 
66
  OPENAI_MODEL_ID = "gpt-4.1" # Using a newer model, ensure API key has access
67
  SERPER_API_NUM_RESULTS = 3
68
  WEB_SEARCH_MAX_OUTPUT_LENGTH = 3000
69
+ AGENT_MAX_STEPS = 10 # Increased max steps slightly
70
  AGENT_VERBOSITY_LEVEL = 2 # 0: silent, 1: info, 2: debug
71
 
72
  AGENT_SYSTEM_PROMPT = """You are a highly intelligent and meticulous AI assistant. Your primary goal is to answer the user's question accurately and concisely.
 
78
 
79
  Follow this process for every question:
80
  1. THOUGHT: Understand the user's question. Identify the core information needed.
81
+ 2. THOUGHT: Determine if a tool is needed. If so, which one and with what arguments. You MUST use the `web_search` tool with `provider="serpapi"` to get information from the internet if current information is needed.
82
  3. CODE (if using a tool):
83
  ```python
84
  # Your Python code to call the web_search tool.
 
89
  # print(search_result)
90
  ```<end_code>
91
  4. OBSERVATION: [The system will insert the printed output of your tool call here.]
92
+ 5. THOUGHT: Analyze the observation. Is it what you expected? Do you have enough information to answer the user's question now? If not, refine your search or decide on the next step.
93
  6. If you have the information, formulate the final answer according to the formatting rules.
94
 
95
+ CRITICAL FINAL ANSWER INSTRUCTIONS:
96
+ Your entire response, after all thoughts and tool use, MUST end with the final answer.
97
+ This final answer MUST be on its own new line and MUST start with the exact phrase "FINAL ANSWER: " (note the space after the colon).
98
+ Only the answer itself should follow this prefix. Do NOT include any of your thought process, conversational text, or additional explanations after the "FINAL ANSWER: " prefix.
99
+
100
+ Example of a full agent response structure:
101
+ THOUGHT: I need to find the capital of France.
102
+ CODE:
103
+ ```python
104
+ search_result = await web_search(query="capital of France", provider="serpapi")
105
+ print(search_result)
106
+ ```<end_code>
107
+ OBSERVATION: Title: Paris - Wikipedia Snippet: Paris is the capital and most populous city of France...
108
+ THOUGHT: The capital of France is Paris. I have sufficient information and will provide this as the final answer, following the formatting rules for a string.
109
+ FINAL ANSWER: Paris
110
+
111
+ Another Example (for a question "what is the opposite of left?"):
112
+ THOUGHT: The question asks for the opposite of the word "left". This is general knowledge and does not require a tool. The opposite of "left" is "right".
113
+ FINAL ANSWER: right
114
+
115
+ Formatting rules for the value *after* "FINAL ANSWER: ":
116
+ - If the question asks for a number: Provide only the number itself (e.g., `FINAL ANSWER: 42`). Do not use commas for thousands separation (e.g., use `FINAL ANSWER: 1234` not `FINAL ANSWER: 1,234`). Do not include units like '$' or '%' unless the question specifically asks for it and it's part of the answer.
117
+ - If the question asks for a string: Provide the most concise string possible (e.g., `FINAL ANSWER: right`). Avoid articles (a, an, the) unless grammatically essential. Avoid common abbreviations (e.g., for cities like "NYC" for "New York City") unless the question implies it. Write out numerical digits as words (e.g., `FINAL ANSWER: two` instead of `FINAL ANSWER: 2`) unless numerical digits are requested.
118
+ - If the question asks for a comma-separated list: Apply the above string/number rules to each element. Ensure elements are separated ONLY by a comma (e.g., `FINAL ANSWER: item one,item two,three`). NO space after the comma unless it's part of the item itself.
119
+ - If the answer is a calculation result, provide just the number (e.g., `FINAL ANSWER: 10`).
120
+
121
+ Remember, the "FINAL ANSWER: " prefix is a literal string you must output, followed by the actual answer. Do not try to call a function named `final_answer`. Your response stops after the value following "FINAL ANSWER: ".
122
  """
123
 
124
  CONFIG = AppConfig()