MCPcopy Index your code
hub / github.com/The-Pocket/PocketFlow-Tutorial-Codebase-Knowledge / call_llm

Function call_llm

utils/call_llm.py:128–158  ·  view source on GitHub ↗
(prompt: str, use_cache: bool = True)

Source from the content-addressed store, hash-verified

126
127# By default, we Google Gemini 2.5 pro, as it shows great performance for code understanding
128def call_llm(prompt: str, use_cache: bool = True) -> str:
129 # Log the prompt
130 logger.info(f"PROMPT: {prompt}")
131
132 # Check cache if enabled
133 if use_cache:
134 # Load cache from disk
135 cache = load_cache()
136 # Return from cache if exists
137 if prompt in cache:
138 logger.info(f"RESPONSE: {cache[prompt]}")
139 return cache[prompt]
140
141 provider = get_llm_provider()
142 if provider == "GEMINI":
143 response_text = _call_llm_gemini(prompt)
144 else: # generic method using a URL that is OpenAI compatible API (Ollama, ...)
145 response_text = _call_llm_provider(prompt)
146
147 # Log the response
148 logger.info(f"RESPONSE: {response_text}")
149
150 # Update cache if enabled
151 if use_cache:
152 # Load cache again to avoid overwrites
153 cache = load_cache()
154 # Add to cache and save
155 cache[prompt] = response_text
156 save_cache(cache)
157
158 return response_text
159
160
161def _call_llm_gemini(prompt: str) -> str:

Callers 5

execMethod · 0.90
execMethod · 0.90
execMethod · 0.90
execMethod · 0.90
call_llm.pyFile · 0.85

Calls 5

load_cacheFunction · 0.85
get_llm_providerFunction · 0.85
_call_llm_geminiFunction · 0.85
_call_llm_providerFunction · 0.85
save_cacheFunction · 0.85

Tested by

no test coverage detected