-
Notifications
You must be signed in to change notification settings - Fork 13
feat: add mako template rendering #1082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
dfe4658
fa9e32c
9144f07
9719f91
7ae1c36
cae121f
8f95694
f9bd01b
5c4f648
d597c43
0e5cd9f
9926715
64d06db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,3 +32,4 @@ basilisk_config.yml | |
| *.mo | ||
| user_data/ | ||
| coverage.xml | ||
| .worktrees/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ | |
|
|
||
| import logging | ||
|
|
||
| from pydantic import ValidationError | ||
|
|
||
| import basilisk.config as config | ||
| from basilisk.config import ( | ||
| AutomaticUpdateModeEnum, | ||
|
|
@@ -117,8 +119,23 @@ def on_ok(self) -> None: | |
| ) | ||
| conf.server.enable = self.view.server_enable.GetValue() | ||
| conf.server.port = int(self.view.server_port.GetValue()) | ||
| conf.templates.html_message_template_path = ( | ||
| self.view.html_message_template_path.get_path() | ||
| ) | ||
| conf.templates.html_export_template_path = ( | ||
| self.view.html_export_template_path.get_path() | ||
| ) | ||
|
|
||
| conf.save() | ||
| try: | ||
| conf.save() | ||
| except (OSError, ValidationError) as exc: | ||
| self.view.show_error( | ||
| # Translators: Error shown when saving preferences fails | ||
| _("Failed to save preferences: {error}").format(error=exc), | ||
| # Translators: Title for the preferences save error dialog | ||
| _("Save error"), | ||
| ) | ||
| return | ||
|
Comment on lines
+122
to
+138
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Roll back staged config changes when saving fails. These assignments mutate the live 🤖 Prompt for AI Agents |
||
| set_log_level(conf.general.log_level.name) | ||
|
|
||
| self.view.EndModal(wx.ID_OK) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>${conversation.title or _("Conversation") | h}</title> | ||
| <style> | ||
| body { font-family: system-ui, sans-serif; max-width: 860px; margin: 2rem auto; padding: 0 1rem; color: #1a1a1a; background: #fff; } | ||
| article { margin-bottom: 2rem; border-radius: 6px; padding: 1rem 1.25rem; } | ||
| article.user { background: #f0f4ff; } | ||
| article.assistant { background: #f6faf3; } | ||
| .meta { font-size: 0.8rem; color: #666; margin-top: 0.5rem; } | ||
| pre { background: #f4f4f4; padding: 0.75rem; border-radius: 4px; overflow-x: auto; } | ||
| code { font-family: monospace; } | ||
| @media (prefers-color-scheme: dark) { | ||
| body { background: #1a1a1a; color: #e8e8e8; } | ||
| article.user { background: #1e2a40; } | ||
| article.assistant { background: #1a2d1a; } | ||
| .meta { color: #aaa; } | ||
| pre { background: #2a2a2a; } | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <header> | ||
| <h1>${conversation.title or _("Conversation") | h}</h1> | ||
| % if profile: | ||
| <p class="meta">${_("Profile")}: ${profile.name | h}</p> | ||
| % endif | ||
| </header> | ||
| <main role="log" aria-label="${_('Conversation history')}"> | ||
| % for block in conversation.messages: | ||
| <article class="user" aria-label="${_('User message')}"> | ||
| <div>${block.request.content | h}</div> | ||
| % if block.request.attachments: | ||
| % for att in block.request.attachments: | ||
| <% | ||
| mime = att.mime_type or "application/octet-stream" | ||
| is_image = mime.startswith("image/") | ||
| b64 = att.encoded_data if hasattr(att, "encoded_data") else "" | ||
| %> | ||
| % if is_image: | ||
| <img src="data:${mime};base64,${b64}" alt="${att.name | h}" style="max-width:100%"> | ||
| % else: | ||
| <a href="#" onclick="downloadAttachment('${b64}','${att.name | h}','${mime}');return false">${_("Download")} ${att.name | h}</a> | ||
| % endif | ||
| % endfor | ||
| % endif | ||
| </article> | ||
| % if block.response: | ||
| <article class="assistant" aria-label="${_('Assistant message')}"> | ||
| <div>${block.response.content | h}</div> | ||
| <p class="meta"> | ||
| ${block.model.name | h} — | ||
| <time datetime="${block.created_at.isoformat()}">${block.created_at.strftime('%Y-%m-%d %H:%M')}</time> | ||
| </p> | ||
| </article> | ||
| % endif | ||
| % endfor | ||
| </main> | ||
| <script> | ||
| function downloadAttachment(b64, filename, mime) { | ||
| const bytes = atob(b64); | ||
| const arr = new Uint8Array(bytes.length); | ||
| for (let i = 0; i < bytes.length; i++) arr[i] = bytes.charCodeAt(i); | ||
| const blob = new Blob([arr], {type: mime}); | ||
| const a = document.createElement('a'); | ||
| a.href = URL.createObjectURL(blob); | ||
| a.download = filename; | ||
| a.click(); | ||
| } | ||
| </script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>${title | h}</title> | ||
| </head> | ||
| <body> | ||
| ${content} | ||
| </body> | ||
| </html> |
Uh oh!
There was an error while loading. Please reload this page.