Skip to content

Commit 4149015

Browse files
authored
update to multi-cell prompt (#6640)
## 📝 Summary <!-- Provide a concise summary of what this pull request is addressing. If this PR fixes any issues, list them here by number (e.g., Fixes #123). --> Only added for multi-cell (chat-panel, generate with AI) AI generation ## 🔍 Description of Changes <!-- Detail the specific changes made in this pull request. Explain the problem addressed and how it was resolved. If applicable, provide before and after comparisons, screenshots, or any relevant details to help reviewers understand the changes easily. --> ## 📋 Checklist - [x] I have read the [contributor guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md). - [ ] For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on [Discord](https://marimo.io/discord?ref=pr), or the community [discussions](https://github.com/marimo-team/marimo/discussions) (Please provide a link if applicable). - [x] I have added tests for the changes made. - [x] I have run the code and verified that it works as expected.
1 parent ccd8b37 commit 4149015

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

marimo/_server/ai/prompts.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
FIM_SUFFIX_TAG = "<|fim_suffix|>"
1717
FIM_MIDDLE_TAG = "<|fim_middle|>"
1818

19-
language_rules = {
19+
LANGUAGES: list[Language] = ["python", "sql", "markdown"]
20+
language_rules: dict[Language, list[str]] = {
2021
"python": [
2122
"For matplotlib: use plt.gca() as the last expression instead of plt.show().",
2223
"For plotly: return the figure object directly.",
@@ -33,6 +34,15 @@
3334
}
3435

3536

37+
language_rules_multiple_cells: dict[Language, list[str]] = {
38+
"sql": [
39+
'SQL cells start with df = mo.sql(f"""<your query>""") for DuckDB, or df = mo.sql(f"""<your query>""", engine=engine) for other SQL engines.',
40+
"This will automatically display the result in the UI. You do not need to return the dataframe in the cell.",
41+
"The SQL must use the syntax of the database engine specified in the `engine` variable. If no engine, then use duckdb syntax.",
42+
]
43+
}
44+
45+
3646
def _format_schema_info(tables: Optional[list[SchemaTable]]) -> str:
3747
"""Helper to format schema information from context"""
3848
if not tables:
@@ -166,10 +176,13 @@ def get_refactor_or_insert_notebook_cell_system_prompt(
166176

167177
if support_multiple_cells:
168178
# Add all language rules for multi-cell scenarios
169-
for lang in language_rules:
170-
if len(language_rules[lang]) > 0:
179+
for lang in LANGUAGES:
180+
language_rule = language_rules_multiple_cells.get(
181+
lang, language_rules.get(lang, [])
182+
)
183+
if language_rule:
171184
system_prompt += (
172-
f"\n\n## Rules for {lang}:\n{_rules(language_rules[lang])}"
185+
f"\n\n## Rules for {lang}:\n{_rules(language_rule)}"
173186
)
174187
elif language in language_rules and language_rules[language]:
175188
system_prompt += (

tests/_server/ai/snapshots/system_prompts.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,9 @@ Separate logic into multiple cells to keep the code organized and readable.
347347
7. If a variable is already defined, use another name, or make it private by adding an underscore at the beginning.
348348

349349
## Rules for sql:
350-
1. The SQL must use duckdb syntax.
350+
1. SQL cells start with df = mo.sql(f"""<your query>""") for DuckDB, or df = mo.sql(f"""<your query>""", engine=engine) for other SQL engines.
351+
2. This will automatically display the result in the UI. You do not need to return the dataframe in the cell.
352+
3. The SQL must use the syntax of the database engine specified in the `engine` variable. If no engine, then use duckdb syntax.
351353

352354
## Available variables from other cells:
353355
- variable: `df`

0 commit comments

Comments
 (0)