From cce2effd7fbe5eea274ef6ee34c9143af17b58e5 Mon Sep 17 00:00:00 2001 From: zachary62 Date: Mon, 5 May 2025 16:27:23 -0400 Subject: [PATCH] disable cache when retrying --- nodes.py | 11 ++++++----- utils/call_llm.py | 1 - utils/crawl_github_files.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/nodes.py b/nodes.py index 9a48d2f..0e3fa58 100644 --- a/nodes.py +++ b/nodes.py @@ -173,11 +173,10 @@ Format the output as a YAML list of dictionaries: - 5 # path/to/another.js # ... up to {max_abstraction_num} abstractions ```""" - response = call_llm(prompt, use_cache=use_cache) # Pass use_cache parameter + response = call_llm(prompt, use_cache=(use_cache and self.cur_retry == 0)) # Use cache only if enabled and not retrying # --- Validation --- yaml_str = response.strip().split("```yaml")[1].split("```")[0].strip() - # add whitespace to fix llm generation error(except -) abstractions = yaml.safe_load(yaml_str) if not isinstance(abstractions, list): @@ -345,7 +344,7 @@ relationships: Now, provide the YAML output: """ - response = call_llm(prompt, use_cache=use_cache) + response = call_llm(prompt, use_cache=(use_cache and self.cur_retry == 0)) # Use cache only if enabled and not retrying # --- Validation --- yaml_str = response.strip().split("```yaml")[1].split("```")[0].strip() @@ -487,7 +486,7 @@ Output the ordered list of abstraction indices, including the name in a comment Now, provide the YAML output: """ - response = call_llm(prompt) + response = call_llm(prompt, use_cache=(use_cache and self.cur_retry == 0)) # Use cache only if enabled and not retrying # --- Validation --- yaml_str = response.strip().split("```yaml")[1].split("```")[0].strip() @@ -616,6 +615,7 @@ class WriteChapters(BatchNode): "prev_chapter": prev_chapter, # Add previous chapter info (uses potentially translated name) "next_chapter": next_chapter, # Add next chapter info (uses potentially translated name) "language": language, # Add language for multi-language support + "use_cache": use_cache, # Pass use_cache flag # previous_chapters_summary will be added dynamically in exec } ) @@ -638,6 +638,7 @@ class WriteChapters(BatchNode): chapter_num = item["chapter_num"] project_name = item.get("project_name") language = item.get("language", "english") + use_cache = item.get("use_cache", True) # Read use_cache from item print(f"Writing chapter {chapter_num} for: {abstraction_name} using LLM...") # Prepare file context string from the map @@ -722,7 +723,7 @@ Instructions for the chapter (Generate content in {language.capitalize()} unless Now, directly provide a super beginner-friendly Markdown output (DON'T need ```markdown``` tags): """ - chapter_content = call_llm(prompt) + chapter_content = call_llm(prompt, use_cache=(use_cache and self.cur_retry == 0)) # Use cache only if enabled and not retrying # Basic validation/cleanup actual_heading = f"# Chapter {chapter_num}: {abstraction_name}" # Use potentially translated name if not chapter_content.strip().startswith(f"# Chapter {chapter_num}"): diff --git a/utils/call_llm.py b/utils/call_llm.py index 6e13975..cde3822 100644 --- a/utils/call_llm.py +++ b/utils/call_llm.py @@ -3,7 +3,6 @@ import os import logging import json from datetime import datetime -import requests # Configure logging log_directory = os.getenv("LOG_DIR", "logs") diff --git a/utils/crawl_github_files.py b/utils/crawl_github_files.py index feb5554..b86802c 100644 --- a/utils/crawl_github_files.py +++ b/utils/crawl_github_files.py @@ -156,7 +156,7 @@ def crawl_github_files( return [] if response.status_code != 200: - print(f"Error fetching the branches of {owner}/{path}: {response.status_code} - {response.text}") + print(f"Error fetching the branches of {owner}/{repo}: {response.status_code} - {response.text}") return [] return response.json()