avatarKitty Leung

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>

《壯志凌雲:獨行俠》:超越首集的經典之作

《壯志凌雲》(Top Gun)怎麼說也算是經典之作吧,當年不但成為現象級電影,多年來也為人津津樂道。

我以前當然也有看過,比較驚喜是重看時發現Tom Cruise的拍檔是《ER》的主角,還有Meg Ryan演配角。

因為不太記得《壯志凌雲》有多好看,所以在看《壯志凌雲:獨行俠》(Top Gun: Maverick)之前一晚特意重溫第一集。

現在重看第一集的感覺

現在重看第一集卻難以理解當年為甚麼會爆紅。我甚至看到不停打瞌睡,首先是飛機對戰的場面,我根本不知道哪架飛機在跟哪架飛機對戰,只見戰機飛來飛去,但我毫無緊張感,因為我完全分不清戰機型號,誰被打落對我來說也沒差。

再來就是他們在學堂到底學了甚麼呢?不清楚,一眾學員有甚麼個性?不清楚,只知道Tom Cruise在追女教師,噢,這根本是一部愛情片吧。歌是很動聽,但以現在的標準來看,第一集的水準其實很一般。

於是,我沒有抱著任何期待去看三十六年後的續集《壯志凌雲:獨行俠》,竟然大為驚喜。

如果第一集是經典,那第二集就是比經典更經典的經典之作,難怪上畫後叫好叫座,更成為Tom Cruise入行以來最賣座的電影。

這部續集不得了

首先,續集的劇情比第一集豐富多了。

電影設定在首集完結的三十年後,男主角依然是年青時那種衝動、自把自為、不願遵守規定的個性,所以縱使曾經立下大功,縱使飛行技術高超,依然未能成為大氣,要不是首集與他腥腥相識的同學Iceman的幫助,他大概早就被革職了。這次他的最後任務是到當年的學堂訓練一班Top Gun學員執行一項九死一生的任務,而學員各有個性,其中一位學員正是男主角舊拍檔的兒子,而對方對他一直抱有成見……

劇情其實沒有任何驚喜之處,往後的發展大概都可以猜想得到,但編得實在精彩,幾乎沒有任何冷場。每個角色的個性鮮明,學員要執行的任務清晰,訓練的過程詳盡,執行任務時夠驚險,每一部分也拍好拍滿,沒有任何欺場之處,既照顧到第一集支持者的懷舊情懷,又兼顧新觀眾的官能刺激,所以這部續集真是不得了。

相隔了36年,Tom Cruise當然老了,但相較起來,樣貎相差不遠,依然可以用型來形容,這其實也很不得了。

一定要在銀幕看啊

如果可以的話,就去看iMax吧,那絕對是無與倫比的體驗。

這一集的戰機對戰場面,我終於看得明明白白了,因此真的會感到緊張刺激。所以我看第一集時模模糊糊,到底是當年的技術不夠,抑或是因為我只在電視而不是大銀幕觀看呢?

看電影都是一期一會,錯過了就未必有機會再在大銀幕看了,往後就算在電視看這電影,雖然還是會被劇情吸引,但大概不會感受到這震撼吧。

我現在很久才會去一次戲院,一來家裏有很多串流電視節目可以看,二來去一次戲院要作許多安排和調動,但《壯志凌雲:獨行俠》絕對是值得在戲院看的電影。

(近期在戲院看的《奇異博士2: 失控多元宇宙》(Doctor Strange in the Multiverse of Madness)和《奇異女俠玩救宇宙》(台譯《媽的多元宇宙》(Everything Everywhere All at Once)其實都令我失望呢)

電影時間
電影
推薦電影
Top Gun Maverick
Top Gun
Recommended from ReadMedium