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
20 changes: 10 additions & 10 deletions .cursor/rules/core_abstraction/batch.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class MapSummaries(BatchNode):
chunks = [content[i:i+chunk_size] for i in range(0, len(content), chunk_size)]
return chunks

def exec(self, chunk):
prompt = f"Summarize this chunk in 10 words: {chunk}"
def exec(self, prep_res):
prompt = f"Summarize this chunk in 10 words: {prep_res}"
summary = call_llm(prompt)
return summary

def post(self, shared, prep_res, exec_res_list):
combined = "\n".join(exec_res_list)
def post(self, shared, prep_res, exec_res):
combined = "\n".join(exec_res)
shared["summary"] = combined
return "default"

Expand Down Expand Up @@ -75,8 +75,8 @@ class LoadFile(Node):
filename = self.params["filename"] # Important! Use self.params, not shared
return filename

def exec(self, filename):
with open(filename, 'r') as f:
def exec(self, prep_res):
with open(prep_res, 'r') as f:
return f.read()

def post(self, shared, prep_res, exec_res):
Expand All @@ -89,8 +89,8 @@ class Summarize(Node):
def prep(self, shared):
return shared["current_file_content"]

def exec(self, content):
prompt = f"Summarize this file in 50 words: {content}"
def exec(self, prep_res):
prompt = f"Summarize this file in 50 words: {prep_res}"
return call_llm(prompt)

def post(self, shared, prep_res, exec_res):
Expand Down Expand Up @@ -154,9 +154,9 @@ class ProcessFile(Node):
full_path = os.path.join(directory, filename)
return full_path

def exec(self, full_path):
def exec(self, prep_res):
# Process the file...
return f"Processed {full_path}"
return f"Processed {prep_res}"

def post(self, shared, prep_res, exec_res):
# Store results, perhaps indexed by path
Expand Down
4 changes: 2 additions & 2 deletions .cursor/rules/core_abstraction/parallel.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class ParallelSummaries(AsyncParallelBatchNode):
# e.g., multiple texts
return shared["texts"]

async def exec_async(self, text):
prompt = f"Summarize: {text}"
async def exec_async(self, prep_res):
prompt = f"Summarize: {prep_res}"
return await call_llm_async(prompt)

async def post_async(self, shared, prep_res, exec_res_list):
Expand Down
12 changes: 6 additions & 6 deletions .cursor/rules/design_pattern/agent.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ class DecideAction(Node):
query = shared["query"]
return query, context

def exec(self, inputs):
query, context = inputs
def exec(self, prep_res):
query, context = prep_res
prompt = f"""
Given input: {query}
Previous search results: {context}
Expand Down Expand Up @@ -110,8 +110,8 @@ class SearchWeb(Node):
def prep(self, shared):
return shared["search_term"]

def exec(self, search_term):
return search_web(search_term)
def exec(self, prep_res):
return search_web(prep_res)

def post(self, shared, prep_res, exec_res):
prev_searches = shared.get("context", [])
Expand All @@ -124,8 +124,8 @@ class DirectAnswer(Node):
def prep(self, shared):
return shared["query"], shared.get("context", "")

def exec(self, inputs):
query, context = inputs
def exec(self, prep_res):
query, context = prep_res
return call_llm(f"Context: {context}\nAnswer: {query}")

def post(self, shared, prep_res, exec_res):
Expand Down
12 changes: 6 additions & 6 deletions .cursor/rules/design_pattern/mapreduce.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class SummarizeAllFiles(BatchNode):
files_dict = shared["files"] # e.g. 10 files
return list(files_dict.items()) # [("file1.txt", "aaa..."), ("file2.txt", "bbb..."), ...]

def exec(self, one_file):
filename, file_content = one_file
def exec(self, prep_res):
filename, file_content = prep_res
summary_text = call_llm(f"Summarize the following file:\n{file_content}")
return (filename, summary_text)

Expand All @@ -35,17 +35,17 @@ class CombineSummaries(Node):
def prep(self, shared):
return shared["file_summaries"]

def exec(self, file_summaries):
def exec(self, prep_res):
# format as: "File1: summary\nFile2: summary...\n"
text_list = []
for fname, summ in file_summaries.items():
for fname, summ in prep_res.items():
text_list.append(f"{fname} summary:\n{summ}\n")
big_text = "\n---\n".join(text_list)

return call_llm(f"Combine these file summaries into one final summary:\n{big_text}")

def post(self, shared, prep_res, final_summary):
shared["all_files_summary"] = final_summary
def post(self, shared, prep_res, exec_res):
shared["all_files_summary"] = exec_res

batch_node = SummarizeAllFiles()
combine_node = CombineSummaries()
Expand Down
10 changes: 5 additions & 5 deletions .cursor/rules/design_pattern/multi_agent.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ class AsyncHinter(AsyncNode):
return None
return shared["target_word"], shared["forbidden_words"], shared.get("past_guesses", [])

async def exec_async(self, inputs):
if inputs is None:
async def exec_async(self, prep_res):
if prep_res is None:
return None
target, forbidden, past_guesses = inputs
target, forbidden, past_guesses = prep_res
prompt = f"Generate hint for '{target}'\nForbidden words: {forbidden}"
if past_guesses:
prompt += f"\nPrevious wrong guesses: {past_guesses}\nMake hint more specific."
Expand All @@ -105,8 +105,8 @@ class AsyncGuesser(AsyncNode):
hint = await shared["guesser_queue"].get()
return hint, shared.get("past_guesses", [])

async def exec_async(self, inputs):
hint, past_guesses = inputs
async def exec_async(self, prep_res):
hint, past_guesses = prep_res
prompt = f"Given hint: {hint}, past wrong guesses: {past_guesses}, make a new guess. Directly reply a single word:"
guess = call_llm(prompt)
print(f"Guesser: I guess it's - {guess}")
Expand Down
44 changes: 22 additions & 22 deletions .cursor/rules/design_pattern/rag.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class ChunkDocs(BatchNode):
# A list of file paths in shared["files"]. We process each file.
return shared["files"]

def exec(self, filepath):
def exec(self, prep_res):
# read file content. In real usage, do error handling.
with open(filepath, "r", encoding="utf-8") as f:
with open(prep_res, "r", encoding="utf-8") as f:
text = f.read()
# chunk by 100 chars each
chunks = []
Expand All @@ -49,8 +49,8 @@ class EmbedDocs(BatchNode):
def prep(self, shared):
return shared["all_chunks"]

def exec(self, chunk):
return get_embedding(chunk)
def exec(self, prep_res):
return get_embedding(prep_res)

def post(self, shared, prep_res, exec_res_list):
# Store the list of embeddings.
Expand All @@ -62,13 +62,13 @@ class StoreIndex(Node):
# We'll read all embeds from shared.
return shared["all_embeds"]

def exec(self, all_embeds):
def exec(self, prep_res):
# Create a vector index (faiss or other DB in real usage).
index = create_index(all_embeds)
index = create_index(prep_res)
return index

def post(self, shared, prep_res, index):
shared["index"] = index
def post(self, shared, prep_res, exec_res):
shared["index"] = exec_res

# Wire them in sequence
chunk_node = ChunkDocs()
Expand Down Expand Up @@ -102,40 +102,40 @@ class EmbedQuery(Node):
def prep(self, shared):
return shared["question"]

def exec(self, question):
return get_embedding(question)
def exec(self, prep_res):
return get_embedding(prep_res)

def post(self, shared, prep_res, q_emb):
shared["q_emb"] = q_emb
def post(self, shared, prep_res, exec_res):
shared["q_emb"] = exec_res

class RetrieveDocs(Node):
def prep(self, shared):
# We'll need the query embedding, plus the offline index/chunks
return shared["q_emb"], shared["index"], shared["all_chunks"]

def exec(self, inputs):
q_emb, index, chunks = inputs
def exec(self, prep_res):
q_emb, index, chunks = prep_res
I, D = search_index(index, q_emb, top_k=1)
best_id = I[0][0]
relevant_chunk = chunks[best_id]
return relevant_chunk

def post(self, shared, prep_res, relevant_chunk):
shared["retrieved_chunk"] = relevant_chunk
print("Retrieved chunk:", relevant_chunk[:60], "...")
def post(self, shared, prep_res, exec_res):
shared["retrieved_chunk"] = exec_res
print("Retrieved chunk:", exec_res[:60], "...")

class GenerateAnswer(Node):
def prep(self, shared):
return shared["question"], shared["retrieved_chunk"]

def exec(self, inputs):
question, chunk = inputs
def exec(self, prep_res):
question, chunk = prep_res
prompt = f"Question: {question}\nContext: {chunk}\nAnswer:"
return call_llm(prompt)

def post(self, shared, prep_res, answer):
shared["answer"] = answer
print("Answer:", answer)
def post(self, shared, prep_res, exec_res):
shared["answer"] = exec_res
print("Answer:", exec_res)

embed_qnode = EmbedQuery()
retrieve_node = RetrieveDocs()
Expand Down
6 changes: 3 additions & 3 deletions .cursor/rules/design_pattern/workflow.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ Many real-world tasks are too complex for one LLM call. The solution is to **Tas
```python
class GenerateOutline(Node):
def prep(self, shared): return shared["topic"]
def exec(self, topic): return call_llm(f"Create a detailed outline for an article about {topic}")
def exec(self, prep_res): return call_llm(f"Create a detailed outline for an article about {prep_res}")
def post(self, shared, prep_res, exec_res): shared["outline"] = exec_res

class WriteSection(Node):
def prep(self, shared): return shared["outline"]
def exec(self, outline): return call_llm(f"Write content based on this outline: {outline}")
def exec(self, prep_res): return call_llm(f"Write content based on this outline: {prep_res}")
def post(self, shared, prep_res, exec_res): shared["draft"] = exec_res

class ReviewAndRefine(Node):
def prep(self, shared): return shared["draft"]
def exec(self, draft): return call_llm(f"Review and improve this draft: {draft}")
def exec(self, prep_res): return call_llm(f"Review and improve this draft: {prep_res}")
def post(self, shared, prep_res, exec_res): shared["final_article"] = exec_res

# Connect nodes
Expand Down
6 changes: 3 additions & 3 deletions .cursor/rules/guide_for_pocketflow.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ my_project/
from utils.call_llm import call_llm

class GetQuestionNode(Node):
def exec(self, _):
def exec(self, prep_res):
# Get question directly from user input
user_question = input("Enter your question: ")
return user_question
Expand All @@ -187,9 +187,9 @@ my_project/
# Read question from shared
return shared["question"]

def exec(self, question):
def exec(self, prep_res):
# Call LLM to get the answer
return call_llm(question)
return call_llm(prep_res)

def post(self, shared, prep_res, exec_res):
# Store the answer in shared
Expand Down
4 changes: 2 additions & 2 deletions .cursor/rules/utility_function/llm.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def call_llm(prompt, use_cache):
return cached_call.__wrapped__(prompt)

class SummarizeNode(Node):
def exec(self, text):
return call_llm(f"Summarize: {text}", self.cur_retry==0)
def exec(self, prep_res):
return call_llm(f"Summarize: {prep_res}", self.cur_retry==0)
```

- Enable logging:
Expand Down
Loading