From 1137d34898bdfd30500a0e3ca0135b7980e778ca Mon Sep 17 00:00:00 2001 From: Ming Lu Date: Thu, 21 Aug 2025 15:05:57 -0700 Subject: [PATCH 1/4] download llms.txt from docs when running cog init --- pkg/cli/init.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/pkg/cli/init.go b/pkg/cli/init.go index 43002454d7..7537e3180d 100644 --- a/pkg/cli/init.go +++ b/pkg/cli/init.go @@ -3,8 +3,11 @@ package cli import ( "embed" "fmt" + "io" + "net/http" "os" "path" + "time" "github.com/spf13/cobra" @@ -114,9 +117,29 @@ func processTemplateFile(fs embed.FS, templateDir, filename, cwd string) error { return fmt.Errorf("Error creating directory %s: %w", dirPath, err) } - content, err := fs.ReadFile(path.Join(templateDir, filename)) - if err != nil { - return fmt.Errorf("Error reading %s: %w", filename, err) + var content []byte + + // Special handling for AGENTS.md - try to download from Replicate docs + if filename == "AGENTS.md" { + console.Infof("Downloading latest AGENTS.md from Replicate docs...") + downloadedContent, err := downloadAgentsFile() + if err != nil { + console.Infof("Failed to download AGENTS.md: %v", err) + console.Infof("Using template version instead...") + // Fall back to template version + content, err = fs.ReadFile(path.Join(templateDir, filename)) + if err != nil { + return fmt.Errorf("Error reading template %s: %w", filename, err) + } + } else { + content = downloadedContent + } + } else { + // Regular template file processing + content, err = fs.ReadFile(path.Join(templateDir, filename)) + if err != nil { + return fmt.Errorf("Error reading %s: %w", filename, err) + } } if err := os.WriteFile(filePath, content, 0o644); err != nil { @@ -127,6 +150,31 @@ func processTemplateFile(fs embed.FS, templateDir, filename, cwd string) error { return nil } +func downloadAgentsFile() ([]byte, error) { + const agentsURL = "https://replicate.com/docs/reference/pipelines/llms.txt" + + client := &http.Client{ + Timeout: 10 * time.Second, + } + + resp, err := client.Get(agentsURL) + if err != nil { + return nil, fmt.Errorf("failed to fetch AGENTS.md: %w", err) + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("failed to fetch AGENTS.md: HTTP %d", resp.StatusCode) + } + + content, err := io.ReadAll(resp.Body) + if err != nil { + return nil, fmt.Errorf("failed to read response body: %w", err) + } + + return content, nil +} + func addPipelineInit(cmd *cobra.Command) { const pipeline = "x-pipeline" cmd.Flags().BoolVar(&pipelineTemplate, pipeline, false, "Initialize a pipeline template") From b1b532023c422ba3735facc13150f1c055e79a17 Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Thu, 21 Aug 2025 16:13:22 -0700 Subject: [PATCH 2/4] remove info message --- pkg/cli/init.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/cli/init.go b/pkg/cli/init.go index 7537e3180d..6a0f35274b 100644 --- a/pkg/cli/init.go +++ b/pkg/cli/init.go @@ -121,7 +121,6 @@ func processTemplateFile(fs embed.FS, templateDir, filename, cwd string) error { // Special handling for AGENTS.md - try to download from Replicate docs if filename == "AGENTS.md" { - console.Infof("Downloading latest AGENTS.md from Replicate docs...") downloadedContent, err := downloadAgentsFile() if err != nil { console.Infof("Failed to download AGENTS.md: %v", err) From d9c5dfa7021c7494822a76966bef97bad29e67dd Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Thu, 21 Aug 2025 16:17:18 -0700 Subject: [PATCH 3/4] lint --- pkg/cli/init-templates/pipeline/main.py | 9 ++++++--- pkg/cli/init.go | 10 +++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pkg/cli/init-templates/pipeline/main.py b/pkg/cli/init-templates/pipeline/main.py index 09ce7b59d7..0a9be36239 100644 --- a/pkg/cli/init-templates/pipeline/main.py +++ b/pkg/cli/init-templates/pipeline/main.py @@ -7,15 +7,18 @@ flux_schnell = replicate.use("black-forest-labs/flux-schnell") claude = replicate.use("anthropic/claude-3.5-haiku") + def run( prompt: str = Input(description="Describe the image to generate"), - seed: int = Input(description="A seed", default=0) + seed: int = Input(description="A seed", default=0), ) -> Path: - detailed_prompt = claude(prompt=f""" + detailed_prompt = claude( + prompt=f""" Generate a detailed prompt for a generative image model that will generate a high quality dynamic image based on the following theme: {prompt} - """) + """ + ) output_paths = flux_schnell(prompt=detailed_prompt, seed=seed) return Path(output_paths[0]) diff --git a/pkg/cli/init.go b/pkg/cli/init.go index 6a0f35274b..c5aaa88afd 100644 --- a/pkg/cli/init.go +++ b/pkg/cli/init.go @@ -151,26 +151,26 @@ func processTemplateFile(fs embed.FS, templateDir, filename, cwd string) error { func downloadAgentsFile() ([]byte, error) { const agentsURL = "https://replicate.com/docs/reference/pipelines/llms.txt" - + client := &http.Client{ Timeout: 10 * time.Second, } - + resp, err := client.Get(agentsURL) if err != nil { return nil, fmt.Errorf("failed to fetch AGENTS.md: %w", err) } defer resp.Body.Close() - + if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("failed to fetch AGENTS.md: HTTP %d", resp.StatusCode) } - + content, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("failed to read response body: %w", err) } - + return content, nil } From 5a72606c1db4c9b3cd19e902a0347ac8a23a5d22 Mon Sep 17 00:00:00 2001 From: Ming Lu Date: Fri, 22 Aug 2025 09:38:43 -0700 Subject: [PATCH 4/4] make error message not repeat --- pkg/cli/init.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/cli/init.go b/pkg/cli/init.go index c5aaa88afd..89dedd2a99 100644 --- a/pkg/cli/init.go +++ b/pkg/cli/init.go @@ -158,12 +158,12 @@ func downloadAgentsFile() ([]byte, error) { resp, err := client.Get(agentsURL) if err != nil { - return nil, fmt.Errorf("failed to fetch AGENTS.md: %w", err) + return nil, fmt.Errorf("%w", err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("failed to fetch AGENTS.md: HTTP %d", resp.StatusCode) + return nil, fmt.Errorf("HTTP %d", resp.StatusCode) } content, err := io.ReadAll(resp.Body)