GALLM Unit 5 Note
GALLM Unit 5 Note
Chain-of-thought (CoT) reasoning allows LLMs to break down complex problems into
intermediate reasoning steps, improving accuracy and logical consistency.
Question: "If John has 3 apples and buys 5 more, then gives away 2, how many does he have
left?"
Without CoT:
With CoT:
ReAct (Reasoning + Action) is a framework that enables large language models (LLMs) to
reason step-by-step while also performing actions, such as interacting with APIs or external
applications. Unlike traditional LLM approaches, which either generate direct answers or rely
on external tools passively, ReAct allows models to dynamically integrate reasoning with
action execution.
1. Reasoning: The LLM thinks through the problem, breaking it into logical steps.
2. Action: Based on reasoning, the LLM interacts with external applications (e.g., search
engines, databases, APIs).
3. Observation: The LLM processes the external feedback and updates its reasoning.
4. Iteration: Steps 1-3 repeat until a final answer is reached.
Scenario: A user asks, "What will the temperature be in New York tomorrow?"
Step 1 (Reasoning): The LLM determines that it needs real-time weather data.
Step 2 (Action): The LLM calls a weather API: fetch_weather("New York",
"tomorrow").
Step 3 (Observation): The API returns {"temperature": 22°C, "condition":
"Sunny"}.
Step 4 (Final Response): The LLM responds, "The expected temperature in New York
tomorrow is 22°C with sunny weather."
To integrate an LLM into a chatbot or summarization tool (for example), the following steps
are taken:
1. Define the Use Case: Determine whether the LLM will be used for customer support,
text summarization, etc.
2. Choose an LLM: Select a suitable model (e.g., GPT for chatbots, BART for
summarization).
3. Develop a Prompting Strategy: Fine-tune the model with domain-specific prompts.
4. Optimize Performance: Implement caching, rate limiting, and token optimization to
enhance response time.
5. Integrate External APIs: Use real-time data sources for better responses.
6. Monitor & Update: Continuously improve based on user feedback.
CoT Approach: The model explains the formula: Sum = n(n+1)/2, then manually
applies it.
PAL Approach: The model generates and runs Python code:
n = 100
sum_n = n * (n + 1) // 2
print(sum_n)
LLMs (Large Language Models) are powerful AI tools that generate human-like text based
on input prompts. However, for real-world applications, they often require integration with
external data sources and applications to enhance their capabilities and provide more
relevant, up-to-date, and actionable responses.
LLM-Powered Applications
LLMs are trained on vast datasets, but they have limitations such as outdated knowledge and
lack of real-time data access. To overcome this, LLMs can be connected to:
To manage communication between the LLM, external data sources, and the application,
developers use orchestration libraries such as:
LangChain – Helps connect LLMs with APIs, databases, and memory storage.
LLamaIndex – Useful for retrieving information from external documents.
Haystack – Enables document search and retrieval for LLM-enhanced applications.
These libraries enable real-time data access, allowing LLMs to interact dynamically with
users and external systems.
Conclusion
LLMs alone have limitations, but integrating them with external applications, data sources,
and APIs through an orchestration library significantly enhances their functionality. This
approach allows businesses to build more intelligent, data-driven AI applications that
provide real-time, relevant, and accurate responses.
Example:
1. LLM Used:
Instead of OpenAI, we use GPT4All or Llama 2 (7B model), which can run
on a regular CPU.
These models are downloaded and executed locally without an internet
connection.
2. Data Sources (External Integrations):
A local SQLite database stores transaction details.
The LLM fetches real-time exchange rates from a simple API.
It processes and categorizes spending from a CSV file.
3. Orchestration:
We use LangChain to manage LLM interactions.
Pandas & Matplotlib help analyze and visualize spending patterns.
User:
LLM-Powered Response:
"You spent $420 on food in March 2024. That’s 12% more than February. Would you like
to set a budget limit?"
# Generate AI response
query = f"My food expense last month was ${food_expense}. How can I reduce
it?"
response = llm(query)
1. User Interface (UI): Enables users to interact with the LLM-powered application.
2. Orchestration Layer: Manages input processing, API calls, and response generation.
3. LLM Model: The core model that generates text-based outputs.
4. External Data Sources: Databases, APIs, or documents providing relevant
information.
5. Retrieval-Augmented Generation (RAG): Enhances responses by retrieving real-time
data.
6. Security & Monitoring: Ensures safe and optimized interactions.
LLMs integrate with APIs, databases, and external tools to enhance their responses. This
connection improves accuracy, updates real-time information, and ensures contextual
relevance.
Example:
A customer support chatbot using an LLM can connect to an e-commerce database via APIs.
When a user asks about order status, the chatbot retrieves real-time tracking details and
provides accurate responses instead of generating a generic reply.