Spaces:
Runtime error
Runtime error
Scott Cogan commited on
Commit ·
746446f
1
Parent(s): 9253c9f
feat: Add detailed logging for template processing
Browse files
app.py
CHANGED
|
@@ -89,11 +89,11 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 89 |
if isinstance(value, str):
|
| 90 |
logger.debug(f"Processing template string: {value[:100]}...")
|
| 91 |
try:
|
| 92 |
-
#
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
# Process existing template syntax
|
| 98 |
value = value.replace('{{', '{{ ').replace('}}', ' }}')
|
| 99 |
value = value.replace('{%', '{% ').replace('%}', ' %}')
|
|
@@ -104,8 +104,15 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 104 |
|
| 105 |
# Handle newlines
|
| 106 |
value = value.replace('\n', '\\n')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
-
|
|
|
|
| 109 |
except Exception as e:
|
| 110 |
logger.error(f"Error processing template string: {str(e)}")
|
| 111 |
raise
|
|
@@ -121,6 +128,16 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 121 |
|
| 122 |
logger.debug("Starting template processing...")
|
| 123 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
prompt_templates = process_template(prompt_templates)
|
| 125 |
logger.debug("Template processing completed")
|
| 126 |
|
|
@@ -129,8 +146,10 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 129 |
for key, value in prompt_templates.items():
|
| 130 |
if isinstance(value, dict):
|
| 131 |
logger.debug(f"{key}: {list(value.keys())}")
|
|
|
|
|
|
|
| 132 |
else:
|
| 133 |
-
logger.debug(f"{key}: {str(value)[:
|
| 134 |
except Exception as e:
|
| 135 |
logger.error(f"Error during template processing: {str(e)}")
|
| 136 |
raise
|
|
@@ -150,6 +169,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 150 |
try:
|
| 151 |
rendered = template.render(tools=[], task="test", name="test", final_answer="test", remaining_steps=1, answer_facts="test")
|
| 152 |
logger.debug(f"Template render test successful for {key}.{subkey}")
|
|
|
|
| 153 |
except Exception as e:
|
| 154 |
logger.error(f"Template render test failed for {key}.{subkey}: {str(e)}")
|
| 155 |
raise
|
|
@@ -160,6 +180,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 160 |
try:
|
| 161 |
rendered = template.render(tools=[], task="test", name="test", final_answer="test", remaining_steps=1, answer_facts="test")
|
| 162 |
logger.debug(f"Template render test successful for {key}")
|
|
|
|
| 163 |
except Exception as e:
|
| 164 |
logger.error(f"Template render test failed for {key}: {str(e)}")
|
| 165 |
raise
|
|
@@ -171,14 +192,12 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 171 |
# Pre-process the system prompt template
|
| 172 |
if 'system_prompt' in prompt_templates and 'text' in prompt_templates['system_prompt']:
|
| 173 |
system_prompt = prompt_templates['system_prompt']['text']
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
system_prompt = re.sub(r'{{([^{}]+)}}', lambda m: '{{ ' + m.group(1).strip() + ' }}', system_prompt)
|
| 179 |
-
system_prompt = re.sub(r'{%([^{}]+)%}', lambda m: '{% ' + m.group(1).strip() + ' %}', system_prompt)
|
| 180 |
prompt_templates['system_prompt']['text'] = system_prompt
|
| 181 |
-
logger.debug("Pre-processed system prompt
|
| 182 |
|
| 183 |
agent = CodeAgent(
|
| 184 |
model=model,
|
|
|
|
| 89 |
if isinstance(value, str):
|
| 90 |
logger.debug(f"Processing template string: {value[:100]}...")
|
| 91 |
try:
|
| 92 |
+
# Log the exact content before processing
|
| 93 |
+
logger.debug(f"Raw template content: {value}")
|
| 94 |
+
|
| 95 |
+
# Only process if template syntax is present
|
| 96 |
+
if '{{' in value or '{%' in value:
|
| 97 |
# Process existing template syntax
|
| 98 |
value = value.replace('{{', '{{ ').replace('}}', ' }}')
|
| 99 |
value = value.replace('{%', '{% ').replace('%}', ' %}')
|
|
|
|
| 104 |
|
| 105 |
# Handle newlines
|
| 106 |
value = value.replace('\n', '\\n')
|
| 107 |
+
|
| 108 |
+
logger.debug(f"Processed template with syntax: {value}")
|
| 109 |
+
else:
|
| 110 |
+
# For non-template content, just handle newlines
|
| 111 |
+
value = value.replace('\n', '\\n')
|
| 112 |
+
logger.debug(f"Processed non-template content: {value}")
|
| 113 |
|
| 114 |
+
# Log the final processed content
|
| 115 |
+
logger.debug(f"Final processed content: {value}")
|
| 116 |
except Exception as e:
|
| 117 |
logger.error(f"Error processing template string: {str(e)}")
|
| 118 |
raise
|
|
|
|
| 128 |
|
| 129 |
logger.debug("Starting template processing...")
|
| 130 |
try:
|
| 131 |
+
# Log the original templates
|
| 132 |
+
logger.debug("Original templates:")
|
| 133 |
+
for key, value in prompt_templates.items():
|
| 134 |
+
if isinstance(value, dict):
|
| 135 |
+
logger.debug(f"{key}: {list(value.keys())}")
|
| 136 |
+
for subkey, subvalue in value.items():
|
| 137 |
+
logger.debug(f"{key}.{subkey}: {str(subvalue)[:200]}...")
|
| 138 |
+
else:
|
| 139 |
+
logger.debug(f"{key}: {str(value)[:200]}...")
|
| 140 |
+
|
| 141 |
prompt_templates = process_template(prompt_templates)
|
| 142 |
logger.debug("Template processing completed")
|
| 143 |
|
|
|
|
| 146 |
for key, value in prompt_templates.items():
|
| 147 |
if isinstance(value, dict):
|
| 148 |
logger.debug(f"{key}: {list(value.keys())}")
|
| 149 |
+
for subkey, subvalue in value.items():
|
| 150 |
+
logger.debug(f"{key}.{subkey}: {str(subvalue)[:200]}...")
|
| 151 |
else:
|
| 152 |
+
logger.debug(f"{key}: {str(value)[:200]}...")
|
| 153 |
except Exception as e:
|
| 154 |
logger.error(f"Error during template processing: {str(e)}")
|
| 155 |
raise
|
|
|
|
| 169 |
try:
|
| 170 |
rendered = template.render(tools=[], task="test", name="test", final_answer="test", remaining_steps=1, answer_facts="test")
|
| 171 |
logger.debug(f"Template render test successful for {key}.{subkey}")
|
| 172 |
+
logger.debug(f"Rendered content: {rendered[:200]}...")
|
| 173 |
except Exception as e:
|
| 174 |
logger.error(f"Template render test failed for {key}.{subkey}: {str(e)}")
|
| 175 |
raise
|
|
|
|
| 180 |
try:
|
| 181 |
rendered = template.render(tools=[], task="test", name="test", final_answer="test", remaining_steps=1, answer_facts="test")
|
| 182 |
logger.debug(f"Template render test successful for {key}")
|
| 183 |
+
logger.debug(f"Rendered content: {rendered[:200]}...")
|
| 184 |
except Exception as e:
|
| 185 |
logger.error(f"Template render test failed for {key}: {str(e)}")
|
| 186 |
raise
|
|
|
|
| 192 |
# Pre-process the system prompt template
|
| 193 |
if 'system_prompt' in prompt_templates and 'text' in prompt_templates['system_prompt']:
|
| 194 |
system_prompt = prompt_templates['system_prompt']['text']
|
| 195 |
+
logger.debug(f"Original system prompt: {system_prompt[:200]}...")
|
| 196 |
+
# Only process template variables, leave other text unchanged
|
| 197 |
+
system_prompt = re.sub(r'{{([^{}]+)}}', lambda m: '{{ ' + m.group(1).strip() + ' }}', system_prompt)
|
| 198 |
+
system_prompt = re.sub(r'{%([^{}]+)%}', lambda m: '{% ' + m.group(1).strip() + ' %}', system_prompt)
|
|
|
|
|
|
|
| 199 |
prompt_templates['system_prompt']['text'] = system_prompt
|
| 200 |
+
logger.debug(f"Pre-processed system prompt: {system_prompt[:200]}...")
|
| 201 |
|
| 202 |
agent = CodeAgent(
|
| 203 |
model=model,
|