-
Notifications
You must be signed in to change notification settings - Fork 243
Add an adaptive prompt section describing the available context and what each template contains #1417
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
Open
ad4mou
wants to merge
3
commits into
main
Choose a base branch
from
feat/improve-context-by-explaining-templates-980
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add an adaptive prompt section describing the available context and what each template contains #1417
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 106 additions & 18 deletions
124
apps/backend/src/components/ai/nao-context-structure.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,116 @@ | ||
| import { Block, Italic, List, ListItem, Title } from '../../lib/markdown'; | ||
| import { Block, Br, Code, List, ListItem, Title } from '../../lib/markdown'; | ||
| import type { ContextPresence } from '../../utils/nao-config'; | ||
|
|
||
| /** Explains how the nao project context is laid out on disk. Shared by every system prompt. */ | ||
| export function NaoContextStructure() { | ||
| export function NaoContextStructure({ | ||
| templates, | ||
| repoNames = [], | ||
| contextPresence, | ||
| }: { | ||
| templates?: string[]; | ||
| repoNames?: string[]; | ||
| contextPresence?: ContextPresence; | ||
| }) { | ||
| const visibleTemplates = | ||
| templates && templates.length > 0 | ||
| ? TEMPLATE_DESCRIPTIONS.filter(({ name }) => templates.includes(name)) | ||
| : TEMPLATE_DESCRIPTIONS; | ||
| const repoPaths = repoNames.map((name) => `repos/${name}/`).join(', '); | ||
| const isPresent = (context: keyof ContextPresence) => contextPresence?.[context] !== false; | ||
|
|
||
| return ( | ||
| <Block> | ||
| <Title level={2}>How nao Works</Title> | ||
| <List> | ||
| <ListItem>All the context available to you is stored as files in the project folder.</ListItem> | ||
| <ListItem> | ||
| In the <Italic>databases</Italic> folder you can find the databases context, each layer is a folder | ||
| from the databases, schema and then tables. | ||
| </ListItem> | ||
| <ListItem> | ||
| Folders are named like this: database=my_database, schema=my_schema, table=my_table. | ||
| </ListItem> | ||
| <ListItem> | ||
| Databases folders are named following this pattern: type={`<database_type>`}/database= | ||
| {`<database_name>`}/schema={`<schema_name>`}/table={`<table_name>`}. | ||
| </ListItem> | ||
| <ListItem> | ||
| Each table has files describing the table schema and the data in the table (like columns.md, | ||
| preview.md, etc.) | ||
| </ListItem> | ||
| {[ | ||
| isPresent('rules') && ( | ||
| <ListItem key='rules'> | ||
| <Code>RULES.md</Code> — project-wide rules; read it for project conventions. | ||
| </ListItem> | ||
| ), | ||
| isPresent('semantics') && ( | ||
| <ListItem key='semantics'> | ||
| <Code>semantics/</Code> — metric and business definitions; read them before calculating or | ||
| interpreting a named metric. | ||
| </ListItem> | ||
| ), | ||
| isPresent('docs') && ( | ||
| <ListItem key='docs'> | ||
| <Code>docs/</Code> — business documentation; read the relevant files before answering domain | ||
| questions. | ||
| {isPresent('notionDocs') && ( | ||
| <> | ||
| {' '} | ||
| <Code>docs/notion/</Code> contains Notion content. | ||
| </> | ||
| )} | ||
| </ListItem> | ||
| ), | ||
| repoNames.length > 0 && ( | ||
| <ListItem key='repos'> | ||
| <Code>{repoPaths}</Code> — source repositories; read relevant dbt, SQL, application, or | ||
| documentation files to understand how data is produced. | ||
| </ListItem> | ||
| ), | ||
| isPresent('databases') && ( | ||
| <ListItem key='databases'> | ||
| <Code>databases/</Code> — warehouse context under{' '} | ||
| <Code> | ||
| type={'<database_type>'}/database={'<database_name>'}/schema={'<schema_name>'}/table= | ||
| {'<table_name>'}/ | ||
| </Code> | ||
| . Inside each table folder: | ||
| <Br /> | ||
| <List indent={1}> | ||
| {[ | ||
| <ListItem key='annotations'> | ||
| <Code>annotations.md</Code> — human-written notes about this table; often empty, | ||
| but when it has content it is authoritative — prefer it over the generated files | ||
| if they disagree. | ||
| </ListItem>, | ||
| ...visibleTemplates.map(({ name, description }) => ( | ||
| <ListItem key={name}> | ||
| <Code>{name}.md</Code> — {description} | ||
| </ListItem> | ||
| )), | ||
| ]} | ||
| </List> | ||
| </ListItem> | ||
| ), | ||
| ]} | ||
| </List> | ||
| </Block> | ||
| ); | ||
| } | ||
|
|
||
| const TEMPLATE_DESCRIPTIONS = [ | ||
| { | ||
| name: 'columns', | ||
| description: | ||
| 'table description, row count, columns with types and descriptions, plus available partitioning, clustering, or index details; read before writing SQL and never guess column names.', | ||
| }, | ||
| { | ||
| name: 'preview', | ||
| description: | ||
| 'a handful of sample rows showing value formats; this is a tiny, non-representative sample, so never infer null rates, volumes, or value distributions from it.', | ||
| }, | ||
| { | ||
| name: 'profiling', | ||
| description: | ||
| 'per-column statistics as JSONL, including null and distinct counts, min/max, and top values; read before filtering on a column value or making a data-quality claim.', | ||
| }, | ||
| { | ||
| name: 'query_history', | ||
| description: | ||
| 'real table usage: query count, common joins, and top queries as SQL; read to find established join keys and query patterns.', | ||
| }, | ||
| { | ||
| name: 'ai_summary', | ||
| description: ( | ||
| <> | ||
| an LLM-written overview of the table, data-quality caveats, and suggested uses; use for orientation, but | ||
| verify specifics against <Code>columns.md</Code> and <Code>profiling.md</Code>. | ||
| </> | ||
| ), | ||
| }, | ||
| ] as const; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.