Skip to content
Open
Show file tree
Hide file tree
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
27 changes: 22 additions & 5 deletions lib/prompt-templates/create-local-circuit-prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ async function fetchFileContent(url: string): Promise<string> {
}
}

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

export const createLocalCircuitPrompt = async () => {
const footprintNamesByType = getFootprintNamesByType()
const footprintSizes = getFootprintSizes()
Expand All @@ -38,11 +47,12 @@ export const createLocalCircuitPrompt = async () => {
"https://raw.githubusercontent.com/tscircuit/props/main/generated/COMPONENT_TYPES.md",
)) || ""

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

const generatedDocs =
(await fetchFileContent("https://docs.tscircuit.com/ai.txt")) || ""

const cleanedGeneratedDocs = cleanMarkdownDoc(generatedDocs)

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 @@ -118,6 +128,13 @@ keep in mind that num_pins can be replaced with a number directly infront of the

${cleanedPropsDoc}

### Generated tscircuit docs

Use these generated docs as the newest source of truth for APIs, component
usage, examples, and current tscircuit guidance:

${cleanedGeneratedDocs}

- Here is a list of unsupported components:

1- powersource
Expand Down
29 changes: 29 additions & 0 deletions tests/prompt-templates/create-local-circuit-prompt.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { afterEach, expect, test } from "bun:test"
import { createLocalCircuitPrompt } from "lib/prompt-templates/create-local-circuit-prompt"

const originalFetch = globalThis.fetch

afterEach(() => {
globalThis.fetch = originalFetch
})

test("createLocalCircuitPrompt includes generated tscircuit docs", async () => {
const fetchedUrls: string[] = []
globalThis.fetch = (async (input: RequestInfo | URL) => {
const url = input.toString()
fetchedUrls.push(url)

if (url.endsWith("/ai.txt")) {
return new Response("# AI docs\n\nGenerated docs marker\n\n<resistor />")
}

return new Response("# Props\n\n<board />\n\n<chip />")
}) as typeof fetch

const prompt = await createLocalCircuitPrompt()

expect(fetchedUrls).toContain("https://docs.tscircuit.com/ai.txt")
expect(prompt).toContain("### Generated tscircuit docs")
expect(prompt).toContain("Generated docs marker")
expect(prompt).toContain("<resistor />")
})