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
2 changes: 2 additions & 0 deletions cookbook/pocketflow-a2a/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:
raise ValueError("LLM returned empty or filtered response")
return r.choices[0].message.content

def search_web(query):
Expand Down
3 changes: 3 additions & 0 deletions cookbook/pocketflow-agent-skills/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ def call_llm(prompt: str) -> str:
model="gpt-4o",
messages=[{"role": "user", "content": prompt}],
)
if not response.choices or response.choices[0].message is None or response.choices[0].message.content is None:

raise ValueError("LLM returned empty or filtered response")
return response.choices[0].message.content
2 changes: 2 additions & 0 deletions cookbook/pocketflow-agent/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:
raise ValueError("LLM returned empty or filtered response")
return r.choices[0].message.content

def search_web_duckduckgo(query):
Expand Down
4 changes: 4 additions & 0 deletions cookbook/pocketflow-agentic-rag/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:

raise ValueError("LLM returned empty or filtered response")

return r.choices[0].message.content
elif os.environ.get("GEMINI_API_KEY"):
from google import genai
Expand Down
6 changes: 6 additions & 0 deletions cookbook/pocketflow-chat-guardrail/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def call_llm(messages):
temperature=0.7
)

if not response.choices or response.choices[0].message is None or response.choices[0].message.content is None:


raise ValueError("LLM returned empty or filtered response")


return response.choices[0].message.content

if __name__ == "__main__":
Expand Down
6 changes: 6 additions & 0 deletions cookbook/pocketflow-chat-memory/utils/call_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def call_llm(messages):
temperature=0.7
)

if not response.choices or response.choices[0].message is None or response.choices[0].message.content is None:


raise ValueError("LLM returned empty or filtered response")


return response.choices[0].message.content

if __name__ == "__main__":
Expand Down
6 changes: 6 additions & 0 deletions cookbook/pocketflow-chat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def call_llm(messages):
temperature=0.7
)

if not response.choices or response.choices[0].message is None or response.choices[0].message.content is None:


raise ValueError("LLM returned empty or filtered response")


return response.choices[0].message.content

if __name__ == "__main__":
Expand Down
3 changes: 3 additions & 0 deletions cookbook/pocketflow-cli-hitl/utils/call_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ def call_llm(prompt: str) -> str:
{"role": "user", "content": prompt}
]
)
if not response.content or response.content[0].text is None:

raise ValueError("LLM returned empty or filtered response")
return response.content[0].text

if __name__ == "__main__":
Expand Down
3 changes: 3 additions & 0 deletions cookbook/pocketflow-code-generator/utils/call_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ def call_llm(prompt):
{"role": "user", "content": prompt}
]
)
if not response.content or response.content[0].text is None:

raise ValueError("LLM returned empty or filtered response")
return response.content[0].text

if __name__ == "__main__":
Expand Down
4 changes: 4 additions & 0 deletions cookbook/pocketflow-coding-agent/utils/call_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:

raise ValueError("LLM returned empty or filtered response")

return r.choices[0].message.content
elif os.environ.get("GEMINI_API_KEY"):
from google import genai
Expand Down
4 changes: 4 additions & 0 deletions cookbook/pocketflow-debate/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:

raise ValueError("LLM returned empty or filtered response")

return r.choices[0].message.content
elif os.environ.get("GEMINI_API_KEY"):
from google import genai
Expand Down
4 changes: 4 additions & 0 deletions cookbook/pocketflow-deep-research/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:

raise ValueError("LLM returned empty or filtered response")

return r.choices[0].message.content
elif os.environ.get("GEMINI_API_KEY"):
from google import genai
Expand Down
2 changes: 2 additions & 0 deletions cookbook/pocketflow-fastapi-background/utils/call_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:
raise ValueError("LLM returned empty or filtered response")
return r.choices[0].message.content

if __name__ == "__main__":
Expand Down
3 changes: 3 additions & 0 deletions cookbook/pocketflow-gradio-hitl/utils/call_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def call_llm(message: str):
response: ChatCompletion = client.chat.completions.create(
model=model, messages=[{"role": "user", "content": message}]
)
if not response.choices or response.choices[0].message is None or response.choices[0].message.content is None:

raise ValueError("LLM returned empty or filtered response")
return response.choices[0].message.content


Expand Down
4 changes: 4 additions & 0 deletions cookbook/pocketflow-heartbeat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:

raise ValueError("LLM returned empty or filtered response")

return r.choices[0].message.content
elif os.environ.get("GEMINI_API_KEY"):
from google import genai
Expand Down
2 changes: 2 additions & 0 deletions cookbook/pocketflow-hello-world/utils/call_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:
raise ValueError("LLM returned empty or filtered response")
return r.choices[0].message.content

if __name__ == "__main__":
Expand Down
8 changes: 8 additions & 0 deletions cookbook/pocketflow-invoice/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:

raise ValueError("LLM returned empty or filtered response")

return r.choices[0].message.content
elif os.environ.get("GEMINI_API_KEY"):
from google import genai
Expand All @@ -31,6 +35,10 @@ def call_llm_with_image(prompt, image_base64):
{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{image_base64}"}}
]}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:

raise ValueError("LLM returned empty or filtered response")

return r.choices[0].message.content
elif os.environ.get("GEMINI_API_KEY"):
from google import genai
Expand Down
4 changes: 4 additions & 0 deletions cookbook/pocketflow-judge/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:

raise ValueError("LLM returned empty or filtered response")

return r.choices[0].message.content
elif os.environ.get("GEMINI_API_KEY"):
from google import genai
Expand Down
4 changes: 4 additions & 0 deletions cookbook/pocketflow-lead-generation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:

raise ValueError("LLM returned empty or filtered response")

return r.choices[0].message.content
elif os.environ.get("GEMINI_API_KEY"):
from google import genai
Expand Down
3 changes: 3 additions & 0 deletions cookbook/pocketflow-majority-vote/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ def call_llm(prompt):
{"role": "user", "content": prompt}
]
)
if not response.content or response.content[0].text is None:

raise ValueError("LLM returned empty or filtered response")
return response.content[0].text

if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions cookbook/pocketflow-map-reduce/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:
raise ValueError("LLM returned empty or filtered response")
return r.choices[0].message.content

# Example usage
Expand Down
6 changes: 6 additions & 0 deletions cookbook/pocketflow-mcp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:
raise ValueError("LLM returned empty or filtered response")
return r.choices[0].message.content

def get_tools(server_script_path=None):
Expand Down Expand Up @@ -126,6 +128,10 @@ async def _call_tool():
async with ClientSession(read, write) as session:
await session.initialize()
result = await session.call_tool(tool_name, arguments)
if not result.content or result.content[0].text is None:

raise ValueError("LLM returned empty or filtered response")

return result.content[0].text

return asyncio.run(_call_tool())
Expand Down
2 changes: 2 additions & 0 deletions cookbook/pocketflow-multi-agent/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ def call_llm(prompt):
model="gpt-4o-mini",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:
raise ValueError("LLM returned empty or filtered response")
return r.choices[0].message.content

# Example usage
Expand Down
4 changes: 4 additions & 0 deletions cookbook/pocketflow-newsletter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:

raise ValueError("LLM returned empty or filtered response")

return r.choices[0].message.content
elif os.environ.get("GEMINI_API_KEY"):
from google import genai
Expand Down
2 changes: 2 additions & 0 deletions cookbook/pocketflow-node/utils/call_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:
raise ValueError("LLM returned empty or filtered response")
return r.choices[0].message.content

if __name__ == "__main__":
Expand Down
4 changes: 4 additions & 0 deletions cookbook/pocketflow-notebook-lm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:

raise ValueError("LLM returned empty or filtered response")

return r.choices[0].message.content
elif os.environ.get("GEMINI_API_KEY"):
from google import genai
Expand Down
2 changes: 2 additions & 0 deletions cookbook/pocketflow-rag/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:
raise ValueError("LLM returned empty or filtered response")
return r.choices[0].message.content

def get_embedding(text):
Expand Down
4 changes: 4 additions & 0 deletions cookbook/pocketflow-self-healing-mermaid/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:

raise ValueError("LLM returned empty or filtered response")

return r.choices[0].message.content
elif os.environ.get("GEMINI_API_KEY"):
from google import genai
Expand Down
2 changes: 2 additions & 0 deletions cookbook/pocketflow-structured-output/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:
raise ValueError("LLM returned empty or filtered response")
return r.choices[0].message.content

# Example usage
Expand Down
2 changes: 2 additions & 0 deletions cookbook/pocketflow-supervisor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:
raise ValueError("LLM returned empty or filtered response")
return r.choices[0].message.content

def search_web(query):
Expand Down
2 changes: 2 additions & 0 deletions cookbook/pocketflow-tao/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def call_llm(prompt):
model=os.environ.get("OPENAI_MODEL", "openai/gpt-4.1-nano"),
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:
raise ValueError("LLM returned empty or filtered response")
return r.choices[0].message.content

if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions cookbook/pocketflow-text2sql/utils/call_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:
raise ValueError("LLM returned empty or filtered response")
return r.choices[0].message.content

# Example usage
Expand Down
3 changes: 3 additions & 0 deletions cookbook/pocketflow-thinking/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ def call_llm(prompt):
{"role": "user", "content": prompt}
]
)
if not response.content or response.content[0].text is None:

raise ValueError("LLM returned empty or filtered response")
return response.content[0].text

if __name__ == "__main__":
Expand Down
4 changes: 4 additions & 0 deletions cookbook/pocketflow-tool-crawler/utils/call_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def call_llm(prompt: str) -> str:
model="gpt-4",
messages=[{"role": "user", "content": prompt}]
)
if not response.choices or response.choices[0].message is None or response.choices[0].message.content is None:

raise ValueError("LLM returned empty or filtered response")

return response.choices[0].message.content

except Exception as e:
Expand Down
2 changes: 2 additions & 0 deletions cookbook/pocketflow-tool-embeddings/utils/call_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def call_llm(prompt):
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
if not r.choices or r.choices[0].message is None or r.choices[0].message.content is None:
raise ValueError("LLM returned empty or filtered response")
return r.choices[0].message.content

if __name__ == "__main__":
Expand Down
6 changes: 6 additions & 0 deletions cookbook/pocketflow-tool-pdf-vision/tools/vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ def extract_text_from_image(image: Image.Image, prompt: str = None) -> str:
}]
)

if not response.choices or response.choices[0].message is None or response.choices[0].message.content is None:


raise ValueError("LLM returned empty or filtered response")


return response.choices[0].message.content

if __name__ == "__main__":
Expand Down
Loading