avatarJohn Teehan

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2796

Abstract

quote><p id="3487">Run the following script with <code>root </code>priviledges:</p><div id="ca20"><pre>curl -fsSL https://ollama.com/install.sh | sh</pre></div><p id="5309">Once ollama is setup, open your terminal (in both <i>Windows </i>or <i>Linux</i>) and type the following command:</p><div id="9f60"><pre>ollama pull llama3</pre></div><figure id="5b90"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*_W7f8UlwxvS_rUo-0TR0rA.png"><figcaption>This pulling of the files will take some time (for me it took approx 5min)</figcaption></figure><p id="b703">Open your preffered python editor and create a folder with the name <code><i>local_llm</i></code><i>.</i></p><p id="f823">Inside this folder create a <code><b>requirements.txt</b></code><b> </b>file and paste the follwoing content.</p><div id="d102"><pre><span class="hljs-attr">ollama</span>==<span class="hljs-number">0.1</span>.<span class="hljs-number">8</span> <span class="hljs-attr">streamlit</span>==<span class="hljs-number">1.33</span>.<span class="hljs-number">0</span></pre></div><p id="ce14">Now, let’s create a file named <code>app.py</code> and add the following code:</p><div id="5ef4"><pre><span class="hljs-keyword">import</span> streamlit <span class="hljs-keyword">as</span> st <span class="hljs-keyword">import</span> ollama</pre></div><p id="3942">Next, we’ll create the Streamlit app. We’ll start by setting the title and initializing the message history:</p><div id="3676"><pre>st.title(<span class="hljs-string">"💬 Local LLMBot"</span>)

<span class="hljs-keyword">if</span> <span class="hljs-string">"messages"</span> <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> st.session_state: st.session_state[<span class="hljs-string">"messages"</span>] = [{<span class="hljs-string">"role"</span>: <span class="hljs-string">"assistant"</span>, <span class="hljs-string">"content"</span>: <span class="hljs-string">"How can I help you?"</span>}]</pre></div><p id="a189">Now, let’s display the chat history by iterating through the messages:</p><div id="5df4"><pre><span class="hljs-keyword">for</span> msg <span class="hljs-keyword">in</span> st.session_state.messages: <span class="hljs-keyword">if</span> msg[<span class="hljs-string">"role"</span>] == <span class="hljs-string">"user"</span>: st.chat_message(msg[<span class="hljs-string">"role"</span>], avatar=<span class="hljs-string">"🧑‍💻"</span>).write(msg[<span class="hljs-string">"content"</span>]) <span class="hljs-keyword">else</span>: st.chat_message(msg[<span class="hljs-string">"role"</span>], avatar=<span class="hljs-string">"🤖"</span>).write(msg[<span class="hljs-string">"content"</span>])</pre></div><p id="c986"><b><i>Creating the Response Generator</i></b></p><p id="f311"

Options

To generate responses using Ollama, we’ll create a function called <code>generate_response()</code>. This function will use the <code>ollama.chat()</code> function to generate responses in a streaming manner:</p><div id="41f7"><pre><span class="hljs-keyword">def</span> <span class="hljs-title function_">generate_response</span>(): response = ollama.chat(model=<span class="hljs-string">'llama3'</span>, stream=<span class="hljs-literal">True</span>, messages=st.session_state.messages) <span class="hljs-keyword">for</span> partial_resp <span class="hljs-keyword">in</span> response: token = partial_resp[<span class="hljs-string">"message"</span>][<span class="hljs-string">"content"</span>] st.session_state[<span class="hljs-string">"full_message"</span>] += token <span class="hljs-keyword">yield</span> token</pre></div><p id="4d2e"><b><i>Adding User Input and Generating Response</i></b><i>s</i></p><p id="2a90">Lastly, we’ll add a chat input field using Streamlit and create a function to handle the user’s input. When the user enters a message, we’ll append it to the messages list and display it in the chat window. We’ll then clear the <code>full_message</code> state variable and start streaming the response:</p><div id="d199"><pre><span class="hljs-keyword">if</span> prompt := st.chat_input(): st.session_state.messages.append({<span class="hljs-string">"role"</span>: <span class="hljs-string">"user"</span>, <span class="hljs-string">"content"</span>: prompt}) st.chat_message(<span class="hljs-string">"user"</span>, avatar=<span class="hljs-string">"🧑‍💻"</span>).write(prompt) st.session_state[<span class="hljs-string">"full_message"</span>] = <span class="hljs-string">""</span> st.chat_message(<span class="hljs-string">"assistant"</span>, avatar=<span class="hljs-string">"🤖"</span>).write_stream(generate_response) st.session_state.messages.append({<span class="hljs-string">"role"</span>: <span class="hljs-string">"assistant"</span>, <span class="hljs-string">"content"</span>: st.session_state[<span class="hljs-string">"full_message"</span>]})</pre></div><p id="a4eb"><b><i>Running the App</i></b></p><p id="6673">To run the app, simply execute the following command in your terminal:</p><div id="4de5"><pre>streamlit run app.py</pre></div><h2 id="4e58">Conclusion</h2><p id="b825">In this article, we’ve learned how to create a local chatbot using <i>Ollama </i>and <i>Streamlit</i>. By combining these powerful tools, you can build your own chatbot with a user-friendly interface, making it easy to interact with the ‘<i>llama3</i>’ model. This is just the beginning, and you can further customize and expand the functionality of your chatbot by integrating additional features and models.</p></article></body>

6 Best Ways To Quit Your Job

If you want to move on to greener pastures, you should do it right.

Photo by James Scott on Unsplash

There’s a memorable scene in one of the earlier seasons of television’s The Simpsons in which Homer Simpson determines that, given his current situation, he can afford to quit his job at the nuclear plant and take on a more pleasant and relatively stress-free gig at a bowling alley. Homer then leaves in a very loud, obnoxious manner, puts his boss in a headlock, and begins playing them like bongo drums. As Homer heads toward the door, dragging his boss — helplessly seething with rage — along, a coworker shouts out, “Hey! Way to play the boss’s head like a drum there, Homer!”

It’s a funny scene, but one that rarely gets played out in real life. And, needless to say, it’s not an example one should follow. While it worked out in the end for Homer Simpson, real life is not like a prime time animated show. Playing your boss’s head like a bongo is not only assault, but it’s nuking your bridges behind and ahead of you.

How should you quit your job?

Here are some suggestions.

1. Have a job or other income stream lined up.

You’ve just ended a primary income stream. Do you have a backup already in place or, at least, lined up? Do you have savings in place to cover you until a new income kicks in?

Even if you’ve resisted the devil’s temptation of quitting on the spot, and you’ve gone the traditional “two-week notice” route, it can take a week or two before a new job’s paychecks start arriving in your bank account.

At a minimum, have a month’s worth of bills, food, and other necessities saved up in your bank account if you already have a new job lined up that you can start immediately. Better yet is to have several months saved up. Six is usually a suitable buffer. A year is best. (Things are tough all over.)

If you have a secondary income stream, make sure it’s a stable one and adjust to fit your current needs.

Ideally, you’re leaving your job on decent terms and can count on that final paycheck and possibly owed vacation pay.

2. Set up a meeting with your boss or immediate supervisor

Meet with your boss or supervisor before openly announcing plans to move on. Not only is this more professional, but it will make management less likely to cause you problems. Really, your supervisor should be the first person to know about your plan, not the last.

A meeting like this also gives your company a chance to make a counter-offer or address whatever grievance you might have. Money or workplace issues may not be the reason you’re leaving, but if they are, this is their chance to make things right and save you the hassle of finding a new job.

Whether or not you expect a counter-offer, have a resignation letter prepared. Paper trails can be to your advantage, especially if they outline reasons for your leave. More importantly, a resignation letter can also help establish a timeline for your departure.

And nobody gets surprised.

Photo by Amy Hirschi on Unsplash

3. Be graceful, and show gratitude

In conversation with your soon-to-be-former bosses and in any written communication, try to express gratitude for the job they gave you. While you may not feel great sincerity in expressing such feelings, they go a long way in reducing friction and resentment on the part of your employer. This, in turn, will make transitioning to a new position at a new company less likely to fall victim to negative talk.

You could even go so far as to write your boss, supervisor, or both a note or card expressing your appreciation. Small gestures can have a big impact. No matter how eager you are to leave, I’d be surprised if you couldn’t come up with one or two nice things to say.

4. Give two weeks notice

The quickest way to build ill will between you and your soon-to-be-former employer is to simply walk out on the job or stop showing up. Give two weeks notice whenever possible. There’s nothing like being left in the lurch that may send a disgruntled employer over the edge to contact your next place of employment with a scathing indictment of your professionalism.

And would leaving be fair to the coworkers you leave behind? Coworkers talk as well. If you live in a small community, word gets around. Try to make your departure as professional as possible.

Granted, staying even two weeks from a particularly toxic or harmful work environment may not be the best idea, in which case, make it clear to your former bosses why you don’t feel like you can stay one more day. If it comes up elsewhere, you may have to explain your reasons for leaving abruptly, but if you need to leave, then leave.

Professional or not, your safety and well-being come first.

5. Make the transition easy if possible

Quitting your job is a significant change for you. It can be for your employer as well — particularly if you held a position of considerable authority and responsibility.

Assuming you’re not planning to leave in a dramatic huff, offer to help train your replacement. Ensure your coworkers or subordinates know where everything is, and that business is disrupted as little as possible with your departure.

It is an added sign of professionalism to make sure the i’s are dotted and t’s are crossed. Finish any incomplete paperwork or projects that you can, or make sure someone knows how to pick up where you left off.

Photo by Scott Graham on Unsplash

6. Leave on the best terms you can

Make efforts to leave on good terms. If you’ve given two weeks’ notice, don’t check out early. Continue to do the best job you can with the time you have left. Volunteer to do whatever you can to help with the transition. At the very least, make peace with your place of employment, so you aren’t carrying the baggage of a bad work experience with you out the door.

This is a hard thing to suggest if you’re leaving due to low pay, bad management, or an overall toxic environment. Management’s response may be unpredictable. If you stay in control and stay professional, you have the advantage.

You can turn a negative into a positive.

Never be afraid to quit when it’s time

Some people stay at bad jobs even when they know better ones are out there waiting for them. There could be many reasons — family, friends, insecurity — both financial and emotional, and more. But the truth is, bad jobs tend not to get better.

It’s difficult to tell the future, but if it seems like things can’t get any worse at your current job, what do you really have to lose at a new one? A job is just a way to pay your bills. It’s not something that is meant to control your entire life.

When you come right down to it, you’re the boss.

Thank you for reading. I’d love to share more with you via my Bi-Weekly Word Roundup newsletter sent to subscribers every other Sunday. It will feature news, productivity tips, life hacks, and links to top stories making the rounds on the Internet. You can unsubscribe at any time.

Life
Work
Self
Advice
Jobs
Recommended from ReadMedium