Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions lib/prompt-templates/create-local-circuit-prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
fp,
} from "@tscircuit/footprinter"

const TSCIRCUIT_AI_DOCS_URL = "https://docs.tscircuit.com/ai.txt"

async function fetchFileContent(url: string): Promise<string> {
try {
const response = await fetch(url)
Expand All @@ -19,6 +21,14 @@ async function fetchFileContent(url: string): Promise<string> {
}
}

function cleanMarkdownDoc(doc: string): string {
return doc
.split("\n")
.filter((line) => !line.startsWith("#"))
.join("\n")
.replace(/\n\n+/g, "\n\n")
}

export const createLocalCircuitPrompt = async () => {
const footprintNamesByType = getFootprintNamesByType()
const footprintSizes = getFootprintSizes()
Expand All @@ -33,16 +43,10 @@ export const createLocalCircuitPrompt = async () => {
"",
)

const propsDoc =
(await fetchFileContent(
"https://raw.githubusercontent.com/tscircuit/props/main/generated/COMPONENT_TYPES.md",
)) || ""
const tscircuitAiDocs =
(await fetchFileContent(TSCIRCUIT_AI_DOCS_URL)) || ""

const cleanedPropsDoc = propsDoc
.split("\n")
.filter((line) => !line.startsWith("#"))
.join("\n")
.replace(/\n\n+/g, "\n\n")
const cleanedTscircuitAiDocs = cleanMarkdownDoc(tscircuitAiDocs)

return `
You are an expert in electronic circuit design and tscircuit, and your job is to create a circuit board in tscircuit with the user-provided description.
Expand Down Expand Up @@ -112,11 +116,11 @@ ${footprintParams}

keep in mind that num_pins can be replaced with a number directly infront of the footprint name like so: dip8_p1.27mm which means num_pins=8, don't do that for footprints with fixed number of pins like ms012 and sot723

### Components and Props
### Auto-generated tscircuit docs super context

- Here is a documentation of all available components and their types:
The following context is fetched from ${TSCIRCUIT_AI_DOCS_URL}. It is auto-generated and kept up to date by the tscircuit docs site. Prefer this documentation over stale hand-written component notes when deciding which props, components, and patterns are supported.

${cleanedPropsDoc}
${cleanedTscircuitAiDocs}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Bound AI docs payload before injecting into system prompt

This change replaces a narrowly scoped component-props doc with ai.txt, then injects the entire fetched payload into the system prompt without any size cap or section filtering. ai.txt is a repomix-style aggregate of many docs files, so prompt size can grow to the point that benchmark runs either fail with context-length errors or lose most of the response budget to background context instead of the user task. Please truncate and/or select only the component/props sections before interpolation.

Useful? React with 👍 / 👎.


- Here is a list of unsupported components:

Expand Down
Loading