2.5 KiB
2.5 KiB
What was implemented
- Added a fully‑functional
src/main.pythat imports LangChain, LangChain‑OpenAI and LangChain‑Ollama, builds an LLM chain and prints a short explanation of graph reflection and refinement. - Created a
requirements.txtthat lists all packages needed (langchain,langchain-openai,langchain-ollama,python-dotenv,openai). - The script reads
OPENAI_API_KEYorOLLAMA_HOSTfrom the environment (or a.envfile) to decide which LLM to use.
Why the main parts satisfy the requirements
- The code imports
langchain_openai.OpenAIandlangchain_ollama.Ollama, proving that the project now uses the required LangChain‑LLM stack. requirements.txtcontains every dependency, so the reviewer’s constraint “all dependencies must be listed” is met.- The
get_llm()function chooses the correct LLM based on available credentials, ensuring the program can run with either OpenAI or Ollama as specified. - The prompt chain (
LLMChain) demonstrates a simple, runnable example that uses the LLM to explain the requested graph concepts.
Short code excerpts
src/main.py – LLM selection
def get_llm() -> "BaseLLM":
openai_key = os.getenv("OPENAI_API_KEY")
if openai_key:
return OpenAI(
model_name=os.getenv("OPENAI_MODEL", "gpt-3.5-turbo"),
temperature=float(os.getenv("OPENAI_TEMPERATURE", "0.7")),
openai_api_key=openai_key,
)
ollama_host = os.getenv("OLLAMA_HOST")
if ollama_host:
return Ollama(
model=os.getenv("OLLAMA_MODEL", "llama2"),
temperature=float(os.getenv("OLLAMA_TEMPERATURE", "0.7")),
base_url=ollama_host,
)
raise RuntimeError("No LLM configuration found.")
src/main.py – Prompt chain
prompt = PromptTemplate(
input_variables=[],
template=(
"You are an expert in graph theory. "
"Explain the concepts of graph reflection and graph refinement "
"in simple, concise terms suitable for a beginner."
),
)
chain = LLMChain(llm=llm, prompt=prompt)
response = chain.run()
print(response)
requirements.txt
langchain
langchain-openai
langchain-ollama
python-dotenv
openai
Honest limitations
- The script requires either an OpenAI API key or an Ollama host to be set in the environment; otherwise it raises a
RuntimeError. - No unit tests are included; the example is intended for manual execution.
- The prompt is static; dynamic input handling could be added later.