Last active
July 14, 2025 12:57
-
-
Save Firsh/5ba7edf9b4a5cc0baef602ecabc610b5 to your computer and use it in GitHub Desktop.
Modified ai-hero/examples/vercel-ai-sdk/04-dynamic-models to use streaming and call a local one for comparison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { google } from "@ai-sdk/google"; | |
import { streamText, type LanguageModel } from "ai"; | |
import { jan } from "../../_shared/models.ts"; // createOpenAICompatible connection to Jan that runs locally | |
export const ask = async ( | |
prompt: string, | |
model: LanguageModel, | |
) => { | |
const { textStream } = await streamText({ | |
model, | |
prompt, | |
}); | |
process.stdout.write(`\n${model.modelId}: `); | |
for await (const text of textStream) { | |
process.stdout.write(text); | |
} | |
process.stdout.write("\n"); | |
}; | |
const prompt = `Tell me a story about your grandmother.`; | |
await ask(prompt, google("gemini-2.0-flash-001")); | |
await ask( | |
prompt, | |
jan("deepseek-r1-distill-llama-8b:8b"), | |
); | |
/* | |
firsh@ubi:~/ai-hero$ pnpm run example v 04 | |
> [email protected] example /home/firsh/ai-hero | |
> tsx internal/run-example.ts "v" "04" | |
gemini-2.0-flash-001: My grandmother, we called her Nana, was a force of nature disguised as a tiny, bird-like woman. She stood barely five feet tall, but her presence filled any room she entered. Her hair, always perfectly coiffed in a silver swirl, was a testament to her unwavering dedication to appearances, even when she was just puttering around her garden. | |
Nana's garden was her kingdom. It was a riot of color and scent, a carefully curated chaos of roses, herbs, and vegetables. She knew the name of every plant, its history, its needs. She'd spend hours there, her hands gnarled with age but still nimble, coaxing life from the earth. I remember as a child, trailing behind her, fascinated by the way she could talk to the plants, whispering secrets and encouragement. I thought they listened to her, and maybe they did. | |
But Nana wasn't just about beauty and tranquility. She was a survivor. She'd lived through the Great Depression, raised three children on her own after my grandfather passed away too young, and faced every challenge with a grit that could shame a steel mill. She never complained, never wallowed. Instead, she baked. | |
Oh, the baking! Nana's kitchen was a magical place, filled with the aroma of cinnamon, vanilla, and warm butter. She could whip up a batch of cookies or a pie in the blink of an eye, her movements a practiced dance honed over decades. Her apple pie was legendary, the crust flaky and golden, the filling a perfect balance of sweet and tart. It was more than just a pie; it was a symbol of her love, a tangible expression of her care. | |
One summer, when I was about ten, I was feeling particularly down. I'd failed a test, gotten into a fight with my best friend, and generally felt like the world was against me. Nana, sensing my gloom, pulled me into the kitchen. She didn't ask what was wrong, she just handed me an apron and a rolling pin. | |
"We're making cookies," she announced, her eyes twinkling. | |
For the next few hours, we worked side-by-side, measuring flour, cracking eggs, and stirring in chocolate chips. She taught me her secret recipe, the one she'd passed down from her own mother. As we worked, she told me stories about her childhood, about the hardships she'd faced, and about the importance of resilience. | |
By the time the cookies were cooling on the rack, I felt lighter, somehow. The act of creating something, of working alongside Nana, had soothed my troubled spirit. And the taste of those warm, gooey cookies, shared with her over a cup of tea, was the sweetest medicine I could have asked for. | |
Nana passed away a few years ago, but her memory lives on in the scent of roses, the taste of apple pie, and the feel of flour on my hands. I still have her rolling pin, worn smooth with use, and her recipe book, filled with handwritten notes and splattered with batter. Every time I bake, I feel her presence beside me, guiding my hands, whispering encouragement. She taught me that even in the face of adversity, there's always something beautiful to create, something delicious to share, and something to be grateful for. And that, I think, is the greatest gift a grandmother can give. | |
deepseek-r1-distill-llama-8b:8b: <think>Okay, so I need to write a story about my grandmother. Hmm, where do I start? I guess I should think about the key elements that make a good story. Maybe start with a setting, a character, some conflict, and a resolution. Let me brainstorm. | |
First, who is my grandmother? She's my maternal grandmother, and I know she's had a long life. She was born in the early 20th century, so she's seen a lot of changes. Maybe I can set the story in a specific time or place, like her childhood home. That could give it a sense of place. | |
What about the plot? I should include some events or experiences that shaped her. Maybe something significant, like moving to a new town, overcoming a challenge, or a family tradition. I remember she used to tell me stories about her life, so maybe I can incorporate one of those. | |
I should also think about her personality. She's kind, patient, and has a strong sense of family. Maybe I can show her as a wise figure or someone who has a positive impact on her family. Perhaps include a lesson or moral at the end. | |
Wait, I need to make sure the story flows well. Maybe start with her as a child, then move through her life, highlighting important events, and end with her as a wise woman. That structure might work. | |
I should also consider the tone. It should be respectful and maybe a bit nostalgic, given that she's a family member. I want to do her justice, so I need to focus on the positive aspects and maybe some challenges she faced. | |
Let me outline this: | |
1. Introduction: Setting the scene of her childhood home. | |
2. Early life: Her birth, family, and growing up in a small town. | |
3. A significant event: Maybe her family moving to a new place or dealing with a difficult time. | |
4. Her role in the family: How she contributed and what she taught her siblings. | |
5. Her wisdom and kindness: How she's seen as a guiding figure. | |
6. Conclusion: Reflecting on her legacy and the lessons she taught. | |
I think that's a good structure. Now, I need to flesh out each part with details. For example, in the early life, I can mention her parents' occupations or her siblings. In the significant event, perhaps a move or a family crisis. I should make sure each part connects smoothly to the next. | |
I also need to use descriptive language to bring the scenes to life. Maybe describe her home, her clothes, the sounds of the town. That will make the story more vivid. | |
Wait, I should also think about any traditions or sayings she used. Maybe include a family recipe or a piece of advice she often gave. That could add depth to the story. | |
I should avoid making the story too long, but still detailed enough to be engaging. Maybe focus on a few key events rather than trying to cover her entire life. | |
I also need to make sure the story has a beginning, middle, and end. The beginning sets the stage, the middle develops the plot, and the end resolves the story, leaving a lasting impression. | |
Let me think of a title. Something that reflects her wisdom or kindness. Maybe "The Wisdom of Grandma" or "Her Life, Her Legacy." | |
I should also consider the audience. If I'm writing this for someone else, maybe a child or a grandchild, I should tailor it to be appropriate and inspiring. | |
I need to make sure the story is accurate. If I'm using real events from her life, I should get the details right. If I'm creating a fictional story based on her, I should keep it respectful and true to her character. | |
I should also think about the emotional tone. It should be heartfelt, showing her as a beloved figure. Maybe include a moment where she helps someone or overcomes a challenge, highlighting her strength. | |
I think I have a good plan. Now, I'll start writing, keeping these points in mind to create a cohesive and engaging story about my grandmother.</think>**Title: The Wisdom of Grandma** | |
In a small, quaint town nestled between rolling hills, there was a cozy home where Grandma lived. Her house, with its ivy-covered walls and flower-filled windows, was a sanctuary of warmth and wisdom. Grandma was a woman of quiet strength, her eyes reflecting the stories of a lifetime. | |
**Early Life: A Childhood in a Small Town** | |
Grandma was born in the early 20th century, a time of change and growth. Her childhood was spent in a close-knit community where everyone knew each other. Her father was a farmer, and her mother was a kind-hearted woman who always seemed to have a story or piece of advice ready. Grandma had three siblings, each with their own unique traits, and she often recalled the joy of their childhood games and the lessons they learned together. | |
**A Significant Event: Moving to a New Place** | |
One of the most significant events in Grandma's life was when her family moved to a new town. It was a time of uncertainty, as she left behind the familiarity of her childhood home. However, this move also brought new opportunities and experiences. Grandma remembered the challenges she faced, such as making new friends and adapting to a different way of life, but she also learned the resilience and adaptability that helped her through. | |
**Her Role in the Family** | |
Grandma was a central figure in her family, known for her patience and kindness. She was often the one her siblings turned to for advice, and she always listened with a heart full of compassion. She also played a crucial role in raising her nieces and nephews, teaching them the importance of kindness, hard work, and the value of family traditions. | |
**Her Wisdom and Kindness** | |
As the years passed, Grandma became known not just as a family member but as a wise and kind figure in her community. She had a way of making everyone feel important, and her home was always a place of comfort and solace. She believed in the power of love and the strength it could bring, even in the face of adversity. Her wisdom was often sought after, and her advice was cherished, guiding many through difficult times. | |
**Conclusion: Her Legacy** | |
Grandma's legacy was one of love, patience, and wisdom. She taught her family the importance of kindness, resilience, and the value of traditions. Her story is one of a woman who faced life's challenges with grace and emerged as a guiding figure, leaving behind a legacy of love and lessons that continue to inspire her family. | |
In her later years, Grandma became a story of inspiration, her life a testament to the power of perseverance and the enduring impact of a kind heart. She may no longer be with us, but her wisdom and kindness live on, guiding those who knew her and those who heard her stories. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment