TDM 19000 - LangChain

LangChain is a framework designed to build applications by connecting LLMs to external data sources. We will use it here to help connect Ollama to our retrieval chains and prompts to the model.

from langchain_ollama import OllamaLLM

# Choose to use the llama3.2 model that uses 2 threads !!
# You can build `llama3.2-2` ahead of time, using the same methods from earlier in the week.
llm = OllamaLLM(model="llama3.2-2")

Now we should be able to give queries systematically to the LLM! Try writing a few questions or prompts, and sending them to the model, all at once. The LLM will take time to respond to each. Do not worry; your session might look frozen, while the llm.invoke command is running, but the answers will appear.

questions = ["my first question is...", "my second question is....", ....]

for q in questions:
    print(f"\nQuestion: {q}")
    print("Answer:", llm.invoke(q))