In this video it shows different use cases of running LLM models using Ollama in your local machine/ Laptop. In this demo it runs the Ollama in Windows OS. It runs the Google’s gemma2:2b LLM model for this demonstration.
Some use cases demonstrated in this video:
- Text generation – Can you write a poem on sheep and shepherd for a school project?
- Language translation – Translate this sentence to Hindi “Once upon a time there were sheep and a shepherd”
- Summarization – Summarize the below paragraph in 2-3 short sentences
- Sentiment analysis – Can you analyze the sentiment in the below sentences
- Chatbot and virtual assistant – Please provide python code to build a chatbot using Llama APIs
Please note: Always keep your Ollama tool and the respective model up to date by updating them regularly.
I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: programmerworld1990@gmail.com
Details and screenshot:
The Paragraph used in some of the above prompts are as below:
“The sun dipped below the horizon, painting the sky in hues of orange and purple. Blossom, a young ewe with fur as white as freshly fallen snow,
nestled her flank against the warmth of the elder ewe, Willow. The air was thick with the scent of wild thyme and clover as twilight descended upon
the hillside.Willow hummed a soft melody, her low bleat vibrating through the air. “Blossom, dear one,” she said, nudging Blossom gently, “You’ll learn soon enough
the art of the shepherd’s guidance.”Blossom tilted her head, gazing at the vast expanse of green pasture stretched before them. For as long as she could remember, she felt a comforting
sense of belonging amongst the others – the constant bleating, the playful jostling for the best patches of grass, and the shared camaraderie in
sharing stories under the watchful gaze of the moon.”
Complete output from Windows command window:
C:\Work\Ollama>ollama run gemma2:2b
>>> Can you write a poem on sheep and shepherd for a school project?
The sunbeams dance upon the green,
Where woolly shapes in fields convene.
A thousand eyes, a silent plea,
To follow where the Shepherd leads them free.
He stands, a silhouette of grace,
Against the sky's warm morning face.
His voice a balm across the land,
"Come gather close, my woolly band."
They bleat and hum in gentle tune,
A rhythmic dance beneath the moon.
Each step he takes, each guiding hand,
Protects these creatures of the strand.
Through fields of emerald green they roam,
Beneath his watchful eye, a peaceful home.
He shares their burdens, light and strong,
His love and care for every one all along.
The sun descends in fiery hues,
Painting clouds with golden dews.
They graze in silence, gentle peace,
Their quiet trust, a gentle release.
As shadows lengthen, day gives way,
The Shepherd's voice bids them to stay.
"Come home tonight," a final call,
Safe and warm, within his watchful thrall.
>>> Can you write a poem on sheep and shepherd for a school project?
Beneath the sun's embrace so bright,
A gentle field of green delight.
Rows of wool in shades of white,
Awaiting Shepherd's guiding light.
He moves amongst them, calm and strong,
His weathered face, where life has clung.
His voice, a balm on morning breeze,
"Come forth, my flock, to freedom ease."
Ears twitch, they rise, then softly tread,
>>> Can you write a short story on sheep and shepherd for a school project?
The sun, a giant yolk in the sky, painted the hills with hues of orange and pink. Old Elias
hummed a tuneless melody as he walked his flock through the valley. The sheep, their wool
shimmering like spun moonlight, followed him silently, each bleating chime filling the air with
a gentle chorus.
He wasn't much to look at, with his wrinkled face etched by years under the sun and weathered
hands callused from tending these creatures for decades. But Elias had an unspoken connection
with his sheep. He knew their every twitch of foot or snort of frustration as they grazed on
the emerald hillsides. He understood when a lamb needed extra care, how to soothe a bleating
mother hen, even how to predict the harshest storms by the subtle movements of his flock.
Today, though, was different. A young sheep named Fawn had been restless, her gentle demeanor
replaced with an anxious tremor in her gait. Elias knelt beside her, brushing away a stray leaf
stuck in her wool. "What troubles you, little one?" he murmured softly. Fawn trembled more,
and he gently touched her side with his calloused hand.
A deep sigh echoed from the flock, Fawn's mother bleating a worried tune. It was the sound of a
hawk circling overhead – its shadow stretching long across the green meadows. "We must move,"
Elias said, his voice firm yet comforting. He gathered his sheep and began to lead them through
a maze of trees, guiding them towards the steep, rocky path leading to the shelter of the
mountain pass.
The journey was perilous. The wind whipped around them, sending gusts of icy air that nipped at
their wool-clad bodies.
>>> Translate this sentence to Hindi "Once upon a time there were sheep and a shepherd"
?? ??? ??? ?? ??????? ?? ???? ????
Here's the breakdown:
* **?? ??? ???:** Once in a time
* **??:** Were
* **???????:** Shepherd (a male shepherd)
* **?? ????:** and his
>>> Summarize the below paragraph in 2-3 short sentences: "The sun dipped below the horizon, painting
... the sky in hues of orange and purple. Blossom, a young ewe with fur as white as freshly fallen s
... now,
... nestled her flank against the warmth of the elder ewe, Willow. The air was thick with the scent o
... f wild thyme and clover as twilight descended upon
... the hillside.
...
... Willow hummed a soft melody, her low bleat vibrating through the air. “Blossom, dear one,” she sa
... id, nudging Blossom gently, "You’ll learn soon enough
... the art of the shepherd's guidance."
...
... Blossom tilted her head, gazing at the vast expanse of green pasture stretched before them. For
... as long as she could remember, she felt a comforting
... sense of belonging amongst the others – the constant bleating, the playful jostling for the best
... patches of grass, and the shared camaraderie in
... sharing stories under the watchful gaze of the moon."
...
Blossom, a young ewe, enjoys the comfort of her flock as twilight descends. Willow, a wise
elder ewe, assures Blossom she will learn the guidance of the shepherd's ways, while also
highlighting the inherent sense of community within the flock.
>>> Can you analyze the sentiment in the below sentences: "The sun dipped below the horizon, painting
... the sky in hues of orange and purple. Blossom, a young ewe with fur as white as freshly fallen s
... now,
... nestled her flank against the warmth of the elder ewe, Willow. The air was thick with the scent o
... f wild thyme and clover as twilight descended upon
... the hillside.
...
... Willow hummed a soft melody, her low bleat vibrating through the air. “Blossom, dear one,” she sa
... id, nudging Blossom gently, "You’ll learn soon enough
... the art of the shepherd's guidance."
...
... Blossom tilted her head, gazing at the vast expanse of green pasture stretched before them. For
... as long as she could remember, she felt a comforting
... sense of belonging amongst the others – the constant bleating, the playful jostling for the best
... patches of grass, and the shared camaraderie in
... sharing stories under the watchful gaze of the moon."
The overall sentiment of these sentences is **peaceful, serene, and hopeful.**
Here's a breakdown:
* **Visual imagery:** The descriptions of the sunset ("sun dipped below the horizon") and
natural elements like "wild thyme and clover" create a calm and idyllic scene.
* **Focus on connection:** The emphasis on Willow guiding Blossom (and the mention of shared
stories under the moon) implies a sense of security, belonging, and wisdom being passed down
within the flock.
* **Warmth and comfort:** The descriptions of "warmth," "gentle" nudging, and "completing
sense of belonging" all point towards an idyllic feeling of calm and acceptance.
Overall, these sentences paint a picture of peace and harmony within the flock, implying a
journey of learning and growing that is both reassuring and joyful.
>>> Please provide python code to build a chatbot using Llama APIs
It's great you're exploring chatbots! While I can't *directly* execute Python code or provide
a full-fledged application here, I can give you the conceptual outline and guidance on how to
approach building a Llama-powered chatbot in Python.
**Key Components:**
1. **Llama Model Access (API Key):**
- You need an API key from a service like Hugging Face Inference API or Google Cloud AI
Platform (for access to Llama models). This will allow you to make requests to the model.
2. **Python Libraries:**
- `transformers`: For easy integration with Llama and other language models. Install it
using `pip install transformers`.
- `requests`: For making API calls to your chosen provider.
**Code Structure (Conceptual Example):**
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
import requests # for handling the API calls
import torch # for handling model computation
# 1. Load the Llama Model and Tokenizer
model_name = "your_llama_model_name"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
def generate_response(user_input, model):
"""Generates a response based on user input."""
input_ids = tokenizer.encode(user_input, return_tensors="pt") # convert the text to
an array suitable for the Llama model
output = model.generate(input_ids, max_length=100) # generate output
response = tokenizer.decode(output[0], skip_special_tokens=True) # decode the
generated tokens back to text
return response
# Example usage:
user_input = "Hello there! How are you?"
response = generate_response(user_input, model)
print(f"Response: {response}")
```
**Explanation:**
* **Loading:** We'll use `AutoModelForCausalLM` and `AutoTokenizer` from
`transformers` to load the Llama model and tokenizer.
* **Generating Text:** The `generate_response()` function takes user input, encodes it
using the tokenizer, and calls the Llama model's generate() method to produce a
response. The `max_length` parameter controls how long the generated text should be.
* **Output:** The generated response is decoded from tokens back into human-readable
text.
**Steps for Development:**
1. **API Key/Account:** Get your API key (e.g., from Hugging Face Inference API) to
interact with Llama models.
2. **Library Installation:** Install the required libraries (`transformers`,
`requests`) using `pip install`.
3. **Llama Model Selection:** Choose a suitable Llama model from providers like:
- Hugging Face ([https://huggingface.co/models](https://huggingface.co/models))
4. **User Input Handling:** Implement a way to receive user input from the user (e.g.,
text input).
5. **Model Inference:** Use `generate_response()` to pass the user input through the
model and get the response.
6. **Output Display:** Print or display the generated response to the user.
**Additional Considerations:**
* **Contextualization:** For more sophisticated chatbots, you'll likely want to
implement some form of context management (e.g., storing previous interactions). This
could be done using:
- A simple dictionary for storing the conversation history.
- More complex techniques like a state manager or memory system if needed.
* **Advanced Features:** Consider adding:
- Question Answering capabilities (e.g., extract information from text)
- Memory and context management to maintain conversation flow.
**Important Notes:**
* You'll need an API key and the appropriate setup for your chosen Llama model
provider.
Let me know if you have any more specific questions! Happy coding!
>>> exit
Goodbye! ? I hope this helps with your chatbot project. Let me know if you've got other questions later on.
>>> quit
You're quitted! See you around. ? ?
>>> Send a message (/? for help)