<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Justin K.</title>
    <description>The latest articles on DEV Community by Justin K. (@justin_k_5952a85663096a2).</description>
    <link>https://dev.to/justin_k_5952a85663096a2</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2533883%2F25498443-0c7a-417c-b533-03bbc1bdc225.png</url>
      <title>DEV Community: Justin K.</title>
      <link>https://dev.to/justin_k_5952a85663096a2</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/justin_k_5952a85663096a2"/>
    <language>en</language>
    <item>
      <title>Making My First AI Chat App: Learning From DevOps Pass AI's Ollama Integration</title>
      <dc:creator>Justin K.</dc:creator>
      <pubDate>Fri, 06 Dec 2024 15:12:04 +0000</pubDate>
      <link>https://dev.to/justin_k_5952a85663096a2/making-my-first-ai-chat-app-learning-from-devops-pass-ais-ollama-integration-1118</link>
      <guid>https://dev.to/justin_k_5952a85663096a2/making-my-first-ai-chat-app-learning-from-devops-pass-ais-ollama-integration-1118</guid>
      <description>&lt;p&gt;The blog i used as a source:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/devopspass-ai/workshop-make-your-first-ai-app-in-a-few-clicks-with-pythonollamallama3-31ib"&gt;https://dev.to/devopspass-ai/workshop-make-your-first-ai-app-in-a-few-clicks-with-pythonollamallama3-31ib&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After discovering DevOps Pass AI's guide on building an AI app with Ollama, I decided to explore how it works and document my questions and learnings along the way. Here's what I discovered while building my first AI chat application.&lt;/p&gt;

&lt;p&gt;Initial Questions I Had&lt;/p&gt;

&lt;p&gt;When I first read through the tutorial, several questions came to mind:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Why use Ollama instead of making direct API calls to OpenAI or other services?&lt;/li&gt;
&lt;li&gt;What makes Llama3 a good choice for a local AI model?&lt;/li&gt;
&lt;li&gt;How does the chat history persistence work, and why is it important?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's go through what I learned while exploring each of these aspects.&lt;/p&gt;

&lt;p&gt;Understanding the Local AI Setup&lt;/p&gt;

&lt;p&gt;The first interesting thing I noticed was the use of local AI through Ollama. After asking around and testing, I found some key advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No API costs or usage limits&lt;/li&gt;
&lt;li&gt;Complete privacy since everything runs locally&lt;/li&gt;
&lt;li&gt;No internet dependency after initial model download&lt;/li&gt;
&lt;li&gt;Surprisingly good performance with Llama3&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The setup process was straightforward: (Bash)&lt;/p&gt;

&lt;p&gt;ollama serve&lt;br&gt;
ollama pull llama3&lt;/p&gt;

&lt;p&gt;I was initially concerned about the 4.7GB model size, but the download was quick on my connection and it runs smoothly even on my modest development machine.&lt;/p&gt;

&lt;p&gt;Exploring the Chat Application&lt;/p&gt;

&lt;p&gt;The most intriguing part was how simple yet functional the chat application is. Let's break down what I learned about each component:&lt;/p&gt;

&lt;p&gt;Chat History Management&lt;/p&gt;

&lt;p&gt;I was particularly curious about how the chat history worked. The code uses a clever approach: (python)&lt;/p&gt;

&lt;p&gt;file_path = sys.argv[1] + '.json'&lt;br&gt;
if os.path.exists(file_path):&lt;br&gt;
    with open(file_path, 'r') as f:&lt;br&gt;
        messages = json.load(f)&lt;/p&gt;

&lt;p&gt;This means each chat session maintains its own history file. I tested this by starting multiple conversations: (Bash)&lt;/p&gt;

&lt;p&gt;python app1.py coding_help&lt;br&gt;
python app1.py devops_queries&lt;/p&gt;

&lt;p&gt;bashCopypython app1.py coding_help&lt;br&gt;
python app1.py devops_queries&lt;br&gt;
Each created its own JSON file, keeping conversations separate and persistent.&lt;br&gt;
The AI Response Handling&lt;br&gt;
One thing that caught my attention was the streaming response implementation:&lt;br&gt;
pythonCopystream = ollama.chat(&lt;br&gt;
    model='llama3',&lt;br&gt;
    messages=messages,&lt;br&gt;
    stream=True,&lt;br&gt;
)&lt;/p&gt;

&lt;p&gt;for chunk in stream:&lt;br&gt;
    print(chunk['message']['content'], end='', flush=True)&lt;br&gt;
This gives a much more natural feel to the conversation, as responses appear gradually like human typing rather than all at once.&lt;br&gt;
Testing Different Use Cases&lt;br&gt;
I experimented with various types of questions to understand the model's capabilities:&lt;/p&gt;

&lt;p&gt;Technical Questions&lt;br&gt;
Copy&amp;gt;&amp;gt;&amp;gt; How can I set up Kubernetes monitoring?&lt;br&gt;
The responses were detailed and technically accurate.&lt;br&gt;
Code Generation&lt;br&gt;
Copy&amp;gt;&amp;gt;&amp;gt; Write a Python function to monitor CPU usage&lt;br&gt;
It provided working code examples with explanations.&lt;br&gt;
Contextual Conversations&lt;br&gt;
Copy&amp;gt;&amp;gt;&amp;gt; What are the best practices for that?&lt;br&gt;
The model maintained context from previous questions effectively.&lt;/p&gt;

&lt;p&gt;What I Learned About Performance&lt;br&gt;
Some interesting observations about running AI locally:&lt;/p&gt;

&lt;p&gt;First response after starting is slightly slower (model warm-up)&lt;br&gt;
Subsequent responses are quick&lt;br&gt;
Response quality matches many cloud-based services&lt;br&gt;
No throttling or rate limits to worry about&lt;/p&gt;

&lt;p&gt;Questions I Still Have&lt;br&gt;
After building and testing the application, I'm curious about:&lt;/p&gt;

&lt;p&gt;How to fine-tune the model for specific use cases?&lt;br&gt;
Can we optimize the model for faster responses?&lt;br&gt;
What's the best way to handle errors or unexpected responses?&lt;/p&gt;

&lt;p&gt;Conclusion: Is It Worth Building?&lt;br&gt;
After experimenting with this setup, I'd say it's definitely worth trying if you:&lt;/p&gt;

&lt;p&gt;Want to learn about AI integration&lt;br&gt;
Need privacy-focused AI solutions&lt;br&gt;
Are interested in building custom AI tools&lt;br&gt;
Want to avoid API costs for AI services&lt;/p&gt;

&lt;p&gt;The learning curve is surprisingly gentle, and the results are impressive for a local setup.&lt;br&gt;
Questions for the Community&lt;/p&gt;

&lt;p&gt;Has anyone else built similar local AI applications?&lt;br&gt;
What other models have you tried with Ollama?&lt;br&gt;
How are you handling error cases in your AI applications?&lt;/p&gt;

&lt;p&gt;Let me know in the comments - I'm particularly interested in hearing about different use cases and improvements!&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
