Skip to content

Commit 3a46d9d

Browse files
committed
Improve program webpage prompt visualizer
1 parent ab7ef24 commit 3a46d9d

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

openevolve/llm/ensemble.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ async def generate_with_context(
5757

5858
def _sample_model(self) -> LLMInterface:
5959
"""Sample a model from the ensemble based on weights"""
60-
logger.info(f"Sampled model: {vars(self.models[index])['model']}")
6160
index = self.random_state.choices(range(len(self.models)), weights=self.weights, k=1)[0]
62-
return self.models[index]
61+
sampled_model = self.models[index]
62+
logger.info(f"Sampled model: {vars(sampled_model)['model']}")
63+
return sampled_model
6364

6465
async def generate_multiple(self, prompt: str, n: int, **kwargs) -> List[str]:
6566
"""Generate multiple texts in parallel"""

scripts/templates/program_page.html

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,36 @@ <h2>Code:</h2>
2727
<pre>{{ program_data.code }}</pre>
2828
<h2>Prompts:</h2>
2929
<ul>
30+
{#-- recursive “display” macro --#}
31+
{% macro display(val) %}
32+
{% if val is mapping %}
33+
<ul>
34+
{% for k, v in val.items() %}
35+
<li>
36+
<strong>{{ k|e }}:</strong>
37+
{{ display(v) }}
38+
</li>
39+
{% endfor %}
40+
</ul>
41+
{% elif val is sequence and not val is string %}
42+
<ul>
43+
{% for item in val %}
44+
<li>{{ display(item) }}</li>
45+
{% endfor %}
46+
</ul>
47+
{% else %}
48+
<pre>{{ val|e }}</pre>
49+
{% endif %}
50+
{% endmacro %}
51+
{#-- loop over every prompts --#}
52+
<div class="prompts">
3053
{% for key, value in program_data.prompts.items() %}
31-
<li><strong>{{ key }}:</strong> <pre style="white-space: pre-wrap; word-break: break-word;">{{ value }}</pre></li>
54+
<section>
55+
<h3>{{ key|title }}</h3>
56+
{{ display(value) }}
57+
</section>
3258
{% endfor %}
59+
</div>
3360
</ul>
3461
{% if artifacts_json %}
3562
<h2>Artifacts:</h2>

0 commit comments

Comments
 (0)