<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yvshih on Medium]]></title>
        <description><![CDATA[Stories by Yvshih on Medium]]></description>
        <link>https://medium.com/@yvontarbajo?source=rss-964c0c1641e3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*U1YkYjb7OvT-yHYEwwLDrQ.png</url>
            <title>Stories by Yvshih on Medium</title>
            <link>https://medium.com/@yvontarbajo?source=rss-964c0c1641e3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 01:36:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yvontarbajo/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[麻瓜走入魔法世界 II — LLM in House]]></title>
            <link>https://medium.com/@yvontarbajo/%E9%BA%BB%E7%93%9C%E8%B5%B0%E5%85%A5%E9%AD%94%E6%B3%95%E4%B8%96%E7%95%8C-ii-llm-in-house-0b178a62084f?source=rss-964c0c1641e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/0b178a62084f</guid>
            <category><![CDATA[hugging-face]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[genai]]></category>
            <dc:creator><![CDATA[Yvshih]]></dc:creator>
            <pubDate>Sat, 23 Mar 2024 05:52:44 GMT</pubDate>
            <atom:updated>2024-03-23T05:52:44.481Z</atom:updated>
            <content:encoded><![CDATA[<h3>麻瓜走入魔法世界 II — LLM in House</h3><p>不是 Fine-Tune, 不是 RAG, 是我有 GPU 我想要當大型語言模型提供者</p><p>在這一篇文章，是初學中的初學，主要會分享如何利用 llama.cpp 為應用介面，自由得嘗試網路上 ( 特別是 HuggingFace 上 ) 各式各樣的模型。建立出你自己的應用。</p><p><em>偏模型與語法，也算是給自己的小抄，才不會每次要測試不同精度的各種模型都要重新翻一次指令。</em></p><p>首先，llama.cpp 是由一個 C++ 神人 <a href="https://github.com/ggerganov">ggerganov </a>所開發的開源專案 ( ps: 他最近成立了一家公司叫做 <a href="https://ggml.ai/">GGML </a>)，如果你對 C++ 開發有興趣，他其實也有提供 whisper.cpp 等在不同領域都很有趣的開源專案；而 llama.cpp 爆紅有一個原因是</p><blockquote>居然用 CPU 就可以執行 LlaMa 7B</blockquote><p>那還不來玩玩看?</p><h3>建立虛擬環境</h3><p>我真的是受夠不同 python, conda 版本衝突 blablabla 的各種環境問題，你可能會 pip install {lib_name} 但永遠 not found，極度惱人的狀況。所以建議大家可以根據不同專案有不同的虛擬環境。</p><pre>conda create -n {your-virtual-env-name} python=3.11<br>conda activate {your-virtual-env-name}<br>conda install -c &quot;nvidia/label/{your-cuda-version}&quot; cuda<br>pip install cmake</pre><p>下載 llama.cpp</p><pre>git clone https://github.com/ggerganov/llama.cpp</pre><p>make the .cpp file</p><pre>cd llma.cpp<br>mkdir {store-file-path-name}<br>cd {store-file-path-name}<br>cmake </pre><blockquote><em>如果你是 GPU 富翁，那你可以利用 -DLLAMA_CUBLAS=1 去啟用cuBLAS</em></blockquote><pre>cmake --build . --config Release</pre><p>到目前為止，你已經獲得了 llama.cpp 的執行檔了，我自己是愛用 server.cpp ，為了後續的擴充資源。</p><h3>下載你想要的模型</h3><p>我習慣從 Gihtub.com 或是 Huggingface.co 下載模型，但其實坊間有很多不同的平台，像是提供深度學習模型實驗管理的 wandb.ai，免費提供 Stable Diffusion AI 生成器的 civitai.ai等等。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*eqez_9-g6p_6Pt1OljenyQ.png" /><figcaption>civitai.ai</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*XnrtoH6DxjQmZsWT8tNJdw.png" /><figcaption><a href="https://replicate.com/">https://replicate.com/</a></figcaption></figure><p>Hugging Face Hub 提供 Apache-2.0, MIT, GNU 等不同的授權 ( 模型提供者可以自己下標籤 )，各位如果要商用也要特別小心這個授權的欄位!</p><h4>建立帳號</h4><p>因為很多模型是會需要申請權限 ( 利用 token 驗證 )，所以建議還是要有自己的帳號才方便，儘管他的討論區也都是可以匿名使用。ps. HF 內其實不只是模型可以下載，他還提供了很多的 dataset 跟課程，所以有帳號管理其實很方便。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JmWNwnOZhIZQlyVSjnnAkg.png" /></figure><h4>選擇模型</h4><p>搜尋任何你想要的模型類型，提供者，像是 google, meta, microsoft, nvdia 等，或是應用情境，像是 text, chat, image等。有時候你會看到 xxxx-hf ，這邊的 “hf” 就是 huggingface/transformers 的意思，有看到國外很多論壇跟文章在討論，自己還沒有實驗過 (<a href="https://blog.vllm.ai/2023/06/20/vllm.html">https://blog.vllm.ai/2023/06/20/vllm.html</a>)，做日常應用上，我還是使用 -chat 這種模型居多，(感覺) 他在理解上下文的能力相對比較好。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UNA7AP3gs-yDqXkBBYytgQ.png" /></figure><h4>下載模型</h4><p>找好模型後點選 Files and versions</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IwvhLyCCYjldU8APiTr15g.png" /></figure><h4>關於量化</h4><p>從上方截圖，你會發現他有 Q2, Q3, Q4 等，這就是量化 (Quantization)。量化就是壓縮模型參數的精度(修改權重的精度縮小模型的大小)，目的是為了節省 memory 然後將執行模型的硬體門檻降低。</p><p>白話文的專業術語就是 “把連續無限值映射到離散有限值&quot;。</p><p>更白話文一點就是<strong>減少每個模型權重所需要的位數</strong>。</p><p>常見的就是把 FP16 降到 INT4。</p><p>結論就是，你不用下載全部的檔案，而是選擇你要的精度大小，或是你的硬體設備所能支援的模型大小，不然硬體沒辦法在有效時間內產生inference，最終使用者體驗會很差。</p><p>後面也會提供你自己做量化的語法，所以如果你電腦容量很大，想要把最肥的最完整的模型 Clone Repository 再自己量化也可以。</p><pre>git lfs install<br>git clone {hf-model-url}</pre><h4>GGUF/GGML/PT…</h4><p>剛開始找模型的時候，常常搞不清楚這些不同的副檔名代表的意思是什麼，下載的時候都很茫然。後來才發現…</p><p>GGUF &amp; GGML 居然跟 llama.cpp 有非常密切的關聯，他們都是由 Georgi Gerganov 所發布的一種文件格式。</p><p><strong>PT (PyTorch)<br></strong>通常開發大語言模型的框架是 PyTorch，所以其預訓練結果的檔案類型也會是 PyTorch 對應的二進位格式。</p><p>為了提高大模型應用的使用效能，所以產生不同格式的大模型文件格式。</p><p><strong>GGUF (GPT-Generated Unified Format)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*wKsXA00TTWL22mrr.jpg" /><figcaption><a href="https://www.datalearner.com/blog/1051710596054633">https://www.datalearner.com/blog/1051710596054633</a></figcaption></figure><p><strong>GGML (GPT-Generated Model Language)</strong><br>GGUF 的前任。專為機器學習設計的 library，可以促進大型模型在各種硬體上 ( 包括 Apple Silicon ) 上執行。</p><p>目前 llama.cpp 是基於 GGUF 做 inference，所以你如果下載 HF 模型就要自己做轉換。Mr. GG 教你轉</p><pre>pip install numpy sentencepiece<br>python conver.py {path-to-hf-model} --outfile {your-model-name}.gguf</pre><h4>Access Token</h4><p>有些模型是需要申請權限，後續在 Local 使用需要提供 token 的時候可以到你的帳號設定中隨時取得。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*bIwhkoikvcR9yHeFI5g9-A.png" /></figure><h4>執行模型</h4><pre>./llama.cpp/build/bin/Release/server -m {your-model-name}.gguf -ngl 100</pre><p>利用 Server 執行，預設 http:localhost:8080 ，然後你就可以用 curl 或是 local postman 做 model inference 了。</p><p>耶，成功! 再來就是要思考到底量化多少的使用者體驗 ( 包含速度跟回答的結果 ) 才是最有效的! 雖然用到 70B ，有時候真的等到快吐血。但是 7B 的答案我又很想砸電腦… 總之在測試 Assistance 的使用跟大型語言模型的磨合還有很長一條路，模型產生得太快，而我花時間在測試的時間又太少，常常需要換不同模型實作，趕緊把作法寫下來，希望對大家有幫助。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kQ3nZLtE67fDseLMhpQj_w.png" /></figure><h3>順便一提</h3><h4>如果想用 llama-cpp-python 你可以</h4><pre>set CMAKE_ARGS=-DLLAMA_CUBLAS=on<br>pip install llama-cpp-python<br># pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dir --verbose</pre><h4>什麼是 <strong>CUBLAS</strong>?</h4><pre>CU-BLAS，CU 是 CUDA 的意思。BLAS 則是 Basic Linear Algebra Subprograms，是一種 API Protocol，用於規範機屬線性代數操作的向量/矩陣乘法。<br>同時你可能也會聽到 LAPACK(Linear Algebra Package) ，內涵更多豐富的工具函式。<br>BLAS 主要分為三種 level ，從1-3: 向量-向量計算、矩陣-向量計算、矩陣-矩陣計算<br><br>CU-BLAS 則是 NVIDIA 針對 CUDA 架構的 GPU 加速矩陣運算 Lib。</pre><h4>量化</h4><p>./quantize — help</p><pre>./llama.cpp/build/bin/quantize {your-model-name}.gguf {your-new-model-name}.gguf Q{8/6/4/2}_K</pre><p>Reference:<br><a href="https://deci.ai/blog/ggml-vs-gguf-comparing-formats-amp-top-5-methods-for-running-gguf-files/">https://deci.ai/blog/ggml-vs-gguf-comparing-formats-amp-top-5-methods-for-running-gguf-files/</a><br><a href="https://medium.com/@phillipgimmi/what-is-gguf-and-ggml-e364834d241c">https://medium.com/@phillipgimmi/what-is-gguf-and-ggml-e364834d241c</a><br><a href="https://python.langchain.com/docs/integrations/llms/llamacpp">https://python.langchain.com/docs/integrations/llms/llamacpp</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0b178a62084f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[麻瓜走入魔法世界 I — Gradio]]></title>
            <link>https://medium.com/@yvontarbajo/%E9%BA%BB%E7%93%9C%E8%B5%B0%E5%85%A5%E9%AD%94%E6%B3%95%E4%B8%96%E7%95%8C-i-gradio-2e9705f2410e?source=rss-964c0c1641e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e9705f2410e</guid>
            <dc:creator><![CDATA[Yvshih]]></dc:creator>
            <pubDate>Tue, 20 Feb 2024 15:37:11 GMT</pubDate>
            <atom:updated>2024-02-20T15:37:55.677Z</atom:updated>
            <content:encoded><![CDATA[<h3>麻瓜走入魔法世界 I — Gradio</h3><blockquote>Gradio, present your ideas swiftly.</blockquote><p>Gradio 是一個開源的 Python 套件，當你發想出各式各樣的 AI 創意，想要分享給別人，這就是<strong> Gradio </strong>的<strong>初衷</strong>，<strong>讓你快速簡單建立互動人工智慧模型的互動網站</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*NUgIBfFpPuKKm5dn" /><figcaption>不需要懂 Javascript, CSS 也能提供網頁服務 (沒有美感也可以)</figcaption></figure><p>如果你也是 HuggingFace 的玩家，基本上其實很多模型貢獻者的 Demosite 就是透過 Gradio 實作的。Stable Diffusion WebUI也是 (<a href="https://stablediffusionweb.com/WebUI">https://stablediffusionweb.com/WebUI</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*FjeJSg58YqsFmFKbDYPS0w.png" /><figcaption>Huggingface Chapter9 教你建立第一個demo的官方資訊</figcaption></figure><p>WHAT</p><p>Gradio 可以提供多種不同的輸入跟輸出格式，像是圖片，音訊檔案等；使用者可以直接在瀏覽器中使用(測試)，包括上傳檔案、調整參數、看到模型成效、行為表現、算法偏差。對於非工程開發人的操作與理解非常友善，可以熟悉模型的場景應用過程和結果。</p><p>最重要的是，Gradio 可以直接在 <strong>Juypter Notebook</strong> 中呈現!</p><h4>同場加映，除了 Gradio ，還有幾個其他套件可以使用，比較多人使用的包括 Streamit 和 Dash。</h4><p><strong><em>Gradio </em></strong>是基於 <a href="https://www.gradio.app/guides/frontend">svelte </a>，svelte是一種前端框架的編譯器。針對響應式網頁而生，而且是高度優化的 Javascript，所以對於中小型的專案非常吃香，因為是在編譯階段處理任務，執行速度較快。</p><p><strong><em>Streamit </em></strong>是基於 React ，可以把 Python 腳本轉成網頁應用的套件。針對資料的應用，資料科學跟資料工程的呈現尤其著墨，提供 Matplotlib 和 Plotly 等工具的整合，所以讓資料的可視化跟分析變得直覺。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*wRRID4j0n6-JbZC1.gif" /><figcaption><a href="https://towardsdatascience.com/building-a-dashboard-in-under-5-minutes-with-streamlit-fd0c906ff886">https://towardsdatascience.com/building-a-dashboard-in-under-5-minutes-with-streamlit-fd0c906ff886</a></figcaption></figure><p><strong><em>Dash </em></strong>是基於 React ，和 Flask 的框架。初衷也是希望可以讓 資料分析人員能用簡單的方式把資料視覺應用化。支援多種不同的程式語言，Python、R、Julia、F#。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*YfAGF_ryy5fkY2AM.gif" /><figcaption><a href="https://www.crownpku.com/">https://www.crownpku.com/</a></figcaption></figure><p>HOW?</p><ul><li>版本要求: Python 3.8 以上</li></ul><pre>python -m venv gradio-env</pre><pre>.\gradio-env\Scripts\activate (Windows)<br>source gradio-env/bin/activate (MacOS/Linux)</pre><pre>pip install gradio</pre><pre>import gradio as gr<br>print(gr.__version__)</pre><h4>範例一: 命名實體識別</h4><ul><li>Pipeline : 簡化我們使用模型的程式碼，以接口的方式直接呼叫模型</li><li>使用launch啟動 Gradio 界面，可以透過參數 server_name 和 server_port 自定義伺服器和端口</li></ul><pre>from transformers import pipeline<br><br>import gradio as gr<br><br>ner_pipeline = pipeline(&quot;ner&quot;) //ner is the model name<br><br>examples = [<br>    &quot;Does Chicago have any stores and does Joe live here?&quot;,<br>]<br><br>def ner(text):<br>    output = ner_pipeline(text)<br>    return {&quot;text&quot;: text, &quot;entities&quot;: output}    <br><br>demo = gr.Interface(ner,<br>             gr.Textbox(placeholder=&quot;Enter sentence here...&quot;), <br>             gr.HighlightedText(),<br>             examples=examples)<br><br>demo.launch()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*y41t7jQJuC38GgPjyLbXrA.png" /></figure><h4>範例二 : 即時語音辨識</h4><ul><li>每當有新的片段音檔產生，就會呼叫語音辨識模型 (transcriber)，透過 stream 紀錄音檔。當音檔完整被處理之後才會回傳。</li></ul><pre>import gradio as gr<br>from transformers import pipeline<br>import numpy as np<br><br>transcriber = pipeline(&quot;automatic-speech-recognition&quot;, model=&quot;openai/whisper-base.en&quot;)<br><br>def transcribe(audio):<br>    sr, y = audio<br>    y = y.astype(np.float32)<br>    y /= np.max(np.abs(y))<br><br>    return transcriber({&quot;sampling_rate&quot;: sr, &quot;raw&quot;: y})[&quot;text&quot;]<br><br><br>demo = gr.Interface(<br>    transcribe,<br>    gr.Audio(sources=[&quot;microphone&quot;]),<br>    &quot;text&quot;,<br>)<br><br>demo.launch()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*v_Bmr5afLsRL6ntB0RUHjw.png" /></figure><h4>範例三 : 使用 HuggingFace 資料集</h4><ul><li>首先你需要在 HuggingFace 的設定中取得 Access Token</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/0*EBJTKDJ1-U25Isn4" /></figure><pre>TOKEN = os.environ.get(&#39;HUB_TOKEN&#39;)<br>repo = huggingface_hub.Repository(<br>    local_dir=&quot;data&quot;,<br>    repo_type=&quot;dataset&quot;,<br>    clone_from=&quot;&lt;name-of-your-dataset&gt;&quot;,<br>    use_auth_token=TOKEN<br>)<br>repo.git_pull()<br><br>shutil.copyfile(&quot;./data/reviews.db&quot;, DB_FILE)</pre><h4>可以把這個 Gradio App 直接丟上 HuggingFace Space</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MZJdzp0VTy1BDz4Z.gif" /><figcaption><a href="https://huggingface.co/blog/gradio-spaces">https://huggingface.co/blog/gradio-spaces</a></figcaption></figure><p><strong>參考連結</strong><br><a href="https://github.com/gradio-app">https://github.com/gradio-app</a>/gradio<br><a href="https://www.youtube.com/watch?v=TiFPx6uX2kQ">https://www.youtube.com/watch?v=TiFPx6uX2kQ</a><br><a href="https://huggingface.co/learn/nlp-course/chapter9/2">https://huggingface.co/learn/nlp-course/chapter9/2</a><br><a href="https://www.gradio.app/main/guides/real-time-speech-recognition">https://www.gradio.app/main/guides/real-time-speech-recognition</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e9705f2410e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[想喝牛奶，需要買牛嗎?]]></title>
            <link>https://medium.com/@yvontarbajo/%E6%83%B3%E5%96%9D%E7%89%9B%E5%A5%B6-%E9%9C%80%E8%A6%81%E8%B2%B7%E7%89%9B%E5%97%8E-57cd46433e5f?source=rss-964c0c1641e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/57cd46433e5f</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Yvshih]]></dc:creator>
            <pubDate>Mon, 11 Sep 2023 08:47:34 GMT</pubDate>
            <atom:updated>2023-09-11T08:47:34.512Z</atom:updated>
            <content:encoded><![CDATA[<p>Gen AI, Azure OpenAI is the one you can leverage!</p><p>想利用 AI 輔助，到底應該投入多少資源才是合理的? 從規則分類、機器學習、到2019年開始討論深度學習，我們逐漸仰賴機器自我學習能力；然後ChatGPT突然爆發，一陣AI恐慌潮又起，也許我們該思考，我們如何平衡Gen AI的投資與期待。</p><blockquote>畢竟，鸚鵡會學我們說話但牠沒辦法幫我做決策，也不知道我在想什麼；</blockquote><p>OpenAI 在近期爆紅，你開始用了嗎?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Pem6KPxQe68FEU2krDXHg.png" /><figcaption><a href="https://www.mckinsey.com/capabilities/quantumblack/our-insights/the-state-of-ai-in-2023-generative-ais-breakout-year">https://www.mckinsey.com/capabilities/quantumblack/our-insights/the-state-of-ai-in-2023-generative-ais-breakout-year</a></figcaption></figure><p>從MCKinsey的報告我們可以看的到，各行各業都開始接觸Gen AI，不管自用或是企業內用，LLM 都慢慢滲透進產業，如果你還沒開始，或是恐懼 AI，或是想靠著一己之力創造「屬於」自己的 LLM，是否會錯過變革，從此成為歷史。</p><blockquote>知識時代已經來臨，翻下資訊時代的扉頁。</blockquote><p>目前 ( 11st, Sep, 2023 ) 時下最熱門的幾個 LLM Model 包括:</p><ul><li>Turbo35 , GPT-4 from Azure OpenAI (<a href="https://github.com/Azure-Samples/openai">https://github.com/Azure-Samples/openai</a>)</li><li>Turbo35 , GPT-4 from OpenAI (<a href="https://github.com/openai">https://github.com/openai</a>)</li><li>Llama 2 from Meta (<a href="https://github.com/facebookresearch/llama">https://github.com/facebookresearch/llama</a>)</li><li>PaLM from Google (<a href="https://github.com/lucidrains/PaLM-pytorch">https://github.com/lucidrains/PaLM-pytorch</a>)</li><li>BLOOM from Hugging Face (<a href="https://github.com/huggingface">https://github.com/huggingface</a>)</li><li>NeMO from Nvidia (<a href="https://github.com/NVIDIA/NeMo">https://github.com/NVIDIA/NeMo</a>)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hofvWUOwbSBojaLoEUesLA.png" /><figcaption>Azure OpenAI Service vs. Alpaca (<a href="https://huggingface.co/spaces/joaogante/transformers_streaming">https://huggingface.co/spaces/joaogante/transformers_streaming</a>)</figcaption></figure><p>今年一月，微軟發布了跟 OpenAI.com 的合作關係，這半年和全球各大企業進行了non stop 的整合跟調整，搭配 Azure Data &amp; AI &amp; Security，還有微軟獨一無二的強項 M365，在第二季立刻又分享了 Copilot Stack、和 Meta 策略聯盟，獨家佈署 llama2 on Cloud，讓大家看到微軟對於新AI時代的決心，以 LLM 為核心伸出強而有力的觸手，主打</p><h3>【簡單上手大型語言模型，搶先機創造知識時代】。</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p3we9WEQs-dCqBnvpPZMiQ.png" /><figcaption>Microsoft Copilot Stack</figcaption></figure><p><em>直到七月，Google 才終於發布 PaLM 生態圈。</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*qxYoyRMiqys0cF0BociOxw.png" /><figcaption>Summarize Azure LLM in Microsoft Cloud and Industry Cloud.</figcaption></figure><blockquote>我家也養了一頭牛耶 #林鳳營</blockquote><p>Microsoft Azure OpenAI Service 就是一個 PaaS 的服務，就像在你家幫你養了一頭牛，直接打開冰箱就可以喝到牛奶；只要你會使用 Restful API，就可以操作幾千億個參數訓練出來的 LLM (大型語言模型) 。而 Azure OpenAI Service 從發佈到現在其實不斷更新進化，一開始只有 3 個資料中心，半年以後已經拓展到 10 個資料中心了!</p><ul><li>模型可用性: 基本上<strong><em>跟隨 OpenAI.com 的腳步</em></strong>，目前支援 GPT-35-Turbo ( gpt-35-turbo, gpt-35-turbo-16k ), GPT-4 ( gpt-4, gpt-4–32k ) , Embedding, and Dall.E (Preview )，暫時都不提供 fine-tune，九月初，OpenAI.com 宣布開放 GPT-35-Turbo35，Azure 也有小道消息會跟上，實際結果請大家<a href="https://ignite.microsoft.com/"><strong><em>參加 11 月份的 Ignite </em></strong></a>一同揭曉。 ( GPT-3 的模型在 2023.07.05 之後淘汰，無法再做佈署; 2023.07.05 之前佈署的可以繼續使用 )</li><li>Private Endpoint for VNet 支援</li><li>負責任的 AI ( <a href="https://learn.microsoft.com/zh-tw/legal/cognitive-services/openai/code-of-conduct?context=%2Fazure%2Fai-services%2Fopenai%2Fcontext%2Fcontext">https://learn.microsoft.com/zh-tw/legal/cognitive-services/openai/code-of-conduct?context=%2Fazure%2Fai-services%2Fopenai%2Fcontext%2Fcontext</a> )</li><li>資料安全性: <strong>Your Data is Your Data</strong></li><li>Managed Identity Support with Azure AD</li><li>GPT-4 申請: <a href="https://aka.ms/oai/get-gpt4">https://aka.ms/oai/get-gpt4</a></li><li>額度限制: 【<strong>每個訂閱 每個區域</strong>可以建立 30 個 Azure OpenAI 執行個體 】顧名思義當一家公司申請一個訂閱，且在10個區域開滿服務，是擁有 1*10*30 個 Azure OpenAI 端點可以利用。</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*H_xfmI11ux0zoNRNdbQM9Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*4ItewwE6GtZPnNg37TTkVQ.png" /></figure><ul><li>每一個模型都有預設的 TPM ( token per minute ) 上限，而這個限制可以分配給訂閱下的多個相同規格模型使用。同時也被要求 RPM 的限制，1000 TPM = 6 RPM ( request per minute )。</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/0*f6rDX1ZwTb_G2-4S.png" /></figure><ul><li>RPM 的限制可以看<strong><em>平均</em>一分鐘</strong>內是否觸及上限，一旦觸及將會收到 429 ，也就是說，RPM=5，代表每分鐘5個Request，同時也代表12秒才能1個，如果12秒內送出2個request就是不合法。</li><li>如果 TPM 在負載平衡架構下還是不夠用，可以透過 Azure OpenAI 提交申請，但仍須依照當下 Azure 後端支援程度決定排隊與否 <a href="https://learn.microsoft.com/zh-tw/azure/ai-services/openai/how-to/quota">https://learn.microsoft.com/zh-tw/azure/ai-services/openai/how-to/quota</a>)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Nc6M7F3IFGLSWx_Y.png" /></figure><ul><li>建議將 max_tokens 跟 best_of 設定為符合要求的最小值</li><li>建置負載平衡架構</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*vicvtaWIcqBGDMkVoYVoGA.png" /></figure><h3><strong>開發概念</strong></h3><h4>內容篩選</h4><ul><li>透過微軟內建的分類偵測模型判斷並且防止潛在有害內容的輸出。</li><li>目前支援英文、中文、德文、日文、西班牙文、法文、葡萄牙文和義大利文。</li><li>類別包括歧視、性、暴力、自我傷害等</li><li>提供<a href="https://customervoice.microsoft.com/Pages/ResponsePage.aspx?id=v4j5cvGGr0GRqy180BHbR7en2Ais5pxKtso_Pz4b1_xURE01NDY1OUhBRzQ3MkQxMUhZSE1ZUlJKTiQlQCN0PWcu">申請</a>【修改內容篩選】權限，即可設定不同嚴重性的內容篩選。</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jPvLn0QHGDx3ZnND" /></figure><h4><a href="https://learn.microsoft.com/zh-tw/azure/ai-services/openai/concepts/use-your-data">使用你的資料( Use Your Data )</a></h4><ul><li>直接協助串接 Azure Cognitive Search</li><li>支援格式: txt, md, html, word, powerpoint, pdf</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QYq7Gipw5aCUTAL_.png" /></figure><h4>Python Sample Code</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*sXCaeGkLkgLhwHGzL_tboA.png" /></figure><p>了解了基本的串接方式以後，下一章節我們將利用更多 framework 一起佈署一個基本的 Azure OpenAI Chat Web Service，一個你專屬的 ChatGPT on Azure。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57cd46433e5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure OpenAI — 初次認識，你好。]]></title>
            <link>https://medium.com/@yvontarbajo/azure-openai-%E5%88%9D%E6%AC%A1%E8%AA%8D%E8%AD%98-%E4%BD%A0%E5%A5%BD-c95002d54419?source=rss-964c0c1641e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/c95002d54419</guid>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Yvshih]]></dc:creator>
            <pubDate>Sat, 08 Jul 2023 13:04:39 GMT</pubDate>
            <atom:updated>2023-07-08T13:04:39.016Z</atom:updated>
            <content:encoded><![CDATA[<h3>Azure OpenAI — 初次認識，你好。</h3><p>用最白話的方式，看 2023 最深奧的黑科技。</p><p>「 為什麼突然有這麼厲害的技術阿 !? 」這大概是 2023 上半年聽到最多的疑問跟驚嘆了。</p><p>﹝在對的時間遇到對的人﹞；我想大概就是這個意思吧。</p><p>GPU 的晶片效率每一年都有突破性的發展，NVIDIA GPU 的 FLOPS (每秒峰值速) 在 2013–2018更提升高達15倍，而賦予 OpenAI Research 超能力的 <strong>DGX-1 </strong>就是 Nvidia 所贈與的超級電腦，也是LLM ( Large Language Model )突飛猛進的核心原因之一。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pp7M8gx8OpkRjqAR.png" /><figcaption><a href="https://wccftech.com/amd-lays-the-path-to-zettascale-computing-talks-cpu-gpu-performance-plus-efficiency-trends-next-gen-chiplet-packaging-more/">https://wccftech.com/amd-lays-the-path-to-zettascale-computing-talks-cpu-gpu-performance-plus-efficiency-trends-next-gen-chiplet-packaging-more/</a></figcaption></figure><p>但其實，我們對於LLM應該都不陌生；他的祖先，我們最熟悉的無非 Google Translator 莫屬了吧。姑且稱他的祖先為 Pre-LLM吧，像是 Word2vec, seq2seq。然後慢慢衍生出 Transformer 的概念，2017 由 Google Brain <a href="https://arxiv.org/abs/1706.03762">發布</a>。</p><blockquote>Transformer, 造就生成式人工智慧的非凡。</blockquote><p>OpenAI Research 利用 Transformer 中的 Sparse Transformer 揭幕了全世界史無前例的 AI Era。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*Cl5z9I4w8RewdAHb" /><figcaption><a href="https://zhuanlan.zhihu.com/p/600773858">https://zhuanlan.zhihu.com/p/600773858</a></figcaption></figure><blockquote>一個可以預測順序中下一個會出現的文字、圖片、或聲音的模型。</blockquote><blockquote>【預測】【順序】【下一個】</blockquote><p>OpenAI Research 利用了 Transformer + attention 成就了吸睛的 ChatGPT，一個模擬人類語言行為的對話機器人，當大家一窩蜂在崇拜ChatGPT可以讓我們變得跟方文山還有周杰倫一樣有才華，同時具備李白跟李清照的清新雅致，還能知天下事…；ChatGPT真的這麼無敵嗎?</p><h4>是，也不是。</h4><p>ChatGPT，是一個基於 GPT-3.5 的微調模型；透過人類的反應跟回饋進行增強式學習。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/253/0*Lf4dZw8WmjMpNEqb" /><figcaption>openai.com</figcaption></figure><p>你會發現，就算你跟 ChatGPT 應對如流，還是會發現他不完全可以回答符合你期待的答案，我通常會說，他是，</p><h3>一本正經的胡言亂語</h3><p>但就像剛剛講的，他是一個根據網路上這些公開資料所訓練出來的語言模型，所以只是【預測】【順序】【下一個】內容；根據 Openai.com 所陳述，在 ChatGPT 增強式學習的過程當中，並沒有事實的來源，( 從題庫中隨機抽出問題，由工作人員標記答案，給予獎勵模型排序 ) 但儘管如此，ChatGPT對每一個你給予的字詞都是非常敏感的，所以不同的措辭都有可能影響答案的合理性，簡單來說，這條路不同，換句話說試試看吧。</p><blockquote>非常重要的，他，是語言模型，是【預測】【順序】【下一個】，千萬不要認為他是一個天才，他上知天文下知地理，但他是數學運算白癡。善用工具才能發揮最大效益，OpenAI是語言界的AI翹楚，但他不包辦所有AI的工作。</blockquote><h3>Take Away</h3><ol><li>GPT 模型已經演進很多年，2023 剛好是天時地利人和有一個大突破。</li><li>OpenAI.com 中的語言模型，都是語言的專家，但沒辦法做所有AI的工作 (eg: 工廠產線偵測改善)</li><li>OpenAI.com 中的語言模型，都是語言的專家，但不是數學家，不是物理學家，不擅長邏輯運算</li><li>OpenAI Research 顧名思義是一個研究團體，微軟與其合作但並非微軟的子公司，微軟獨家授權 OpenAI Research 所研發出來的所有模型</li></ol><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fsheetsu.com%2Ftables%2F68ae9aab45&amp;dntp=1&amp;display_name=Sheetsu&amp;url=https%3A%2F%2Fsheetsu.com%2Ftables%2F68ae9aab45&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=sheetsu" width="700" height="744" frameborder="0" scrolling="no"><a href="https://medium.com/media/d76f405b9dfe2d4aa9d66744f33eefb3/href">https://medium.com/media/d76f405b9dfe2d4aa9d66744f33eefb3/href</a></iframe><p>如果，你想知道如何利用更多 OpenAI 的超能力，請看續集；將會介紹如何利用 OpenAI 中不同的模型寫出不同的專案，以及 lanchain 和向量資料庫的使用，讓你的 ChatGPT 不再只是一派胡言。</p><p>Reference:<br>1. <a href="https://openai.com/research/sparse-transformer">https://openai.com/research/sparse-transformer</a></p><p>2. <a href="https://arxiv.org/pdf/2303.08774.pdf">https://arxiv.org/pdf/2303.08774.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c95002d54419" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[從Azure DevOps 看敏捷式開發-概念篇]]></title>
            <link>https://medium.com/@yvontarbajo/%E5%BE%9Eazure-devops-%E7%9C%8B%E6%95%8F%E6%8D%B7%E5%BC%8F%E9%96%8B%E7%99%BC-%E6%A6%82%E5%BF%B5%E7%AF%87-26670edecd6?source=rss-964c0c1641e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/26670edecd6</guid>
            <category><![CDATA[developer-tools]]></category>
            <category><![CDATA[scrum]]></category>
            <category><![CDATA[agile]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Yvshih]]></dc:creator>
            <pubDate>Tue, 10 Mar 2020 04:09:10 GMT</pubDate>
            <atom:updated>2020-03-10T04:09:10.834Z</atom:updated>
            <content:encoded><![CDATA[<p>在研究所的時候很常需要小組寫專題, 以前都很單純用Github，Heroku跟Travis CI做CI/CD, 現在來試試看如果用Azure DevOps會有什麼全新體驗呢</p><h3>DevOps</h3><p>根據維基百科的定義，&quot; a set of practices intended to reduce the time between committing a change to a system and the change being placed into normal production, while ensuring high quality&quot;。</p><p><em>也就是說，這是一個希望可以藉由減少系統更版的成本同時要求程式開發的品質與時間。</em></p><p>其中囊括了很多開發的概念，Coding, Building, Testing, Packaging, Releasing, Configuring, Monitoring, CI, IaC。</p><h3>CI/CD</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/0*qvjiEIWI7Bv8PHTe.png" /></figure><h4>CI (Continuous Integration)</h4><p>雖然以前有用Github在做版控, 但是如果同學進度飛快, 就很有可能造成我在push code的時候發生很多conflict, 這也是我們在開發專案的時候最煎熬的時刻(萬一不小心改錯了就毀了整條branch)</p><p>持續整合的目的就是希望開發團隊可以更積極的去整合彼此的程式碼，並且透過自動化測試去確認每一次的上板都不會破壞專案的可行性。當然還有一些工具可以在CI的時候去使用，確認程式碼的Code Style或是整潔程度，像是pylint之類的，雖然每次被檢查到都會很生氣，好像自己的Code很臭。</p><h4>CD (Continuous Delivery)</h4><p>有一說CD是 Continuous Development，有一說則是Continuous Delivery。看到有些說法是如上圖，CD的過程包含上述兩種，但概念上應該是差不多，都是為了要做production。</p><p>Continuous Delivery，就是為了確保環境不會影響到這個程式的運行。因此往往需要有套件式的管理，也就是所謂的package。</p><p>Continuous Development，意旨盡快把最新版本的產品交付到客戶手中。而達到這個目標，則必須先完成前兩個CI/CD的步驟。</p><h3>Dashboard</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*29BKqOxtfKHdSqZYnCAb3Q.png" /></figure><p>Azure DevOps整合了很多我們協同開發(甚至是敏捷式開發)可能會遇上的問題所需要的解決方案，比如說，需要一個看板去Overview了解整個專案的進度跟分配。</p><p>因為Kanban的概念就是三大原則:<br>1. 視覺化<br>2. Work in Progress<br>3. Workflow</p><h4>Azure Repos (程式碼儲存空間)</h4><p>提供Git repo以及TFVC(Team Foundation Version Control)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W3EZTxiLCY0f-FCa2pXtZA.png" /></figure><h4>Azure Pipelines(CI/CD管線)</h4><p><strong>支援語言</strong><br>Python, Java, JSP, PHP, Ruby, C#, CPP, GoLang, NodeJS, .Net</p><p><strong>程式原始碼來源</strong><br>Github, Github Enterprise, Azure Repos, Bikbucket</p><p><strong>可定義Pipeline情境</strong><br>Build, Release</p><p><strong>Stage<br></strong>定義每一個步驟階段的Pre&amp;Post condition</p><p><strong>Job<br></strong>一個完整的執行工作</p><p>可以透過GUI或是YAML方式建立管線，其中可以依序設定原始碼來源，程式語言，專案類型(Web or..)，環境變數，系統參數等。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6XQ6AR2ekFjSWP-5" /><figcaption>azure-pipelines.yml</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UaGpEmk4Lu3Rf9NPIR1IgQ.png" /></figure><h4>Azure Boards(支援敏捷開發/Scrum的工具們)</h4><blockquote>當然另外也有提供瀑布式的工具</blockquote><p>先了解客戶需求，並且以User Story呈現，每個人都可以編輯User Story，但是應該要有一個統一窗口整合客戶需求與開發限制；將產品代辦事項(需求or bug)放在Backlog中。</p><p>Scrum</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*CDe-9B18hdYz6KR7Y4cVoQ.png" /></figure><p><strong>User Story</strong>: 身為&lt;角色&gt;，我想要&lt;一些需求&gt;，達到&lt;一個目標&gt;</p><p><strong>角色</strong></p><blockquote>1. Dev Team<br>2. Product Owner<br>3. Scrum Master</blockquote><p><strong>物件</strong></p><blockquote>1. Task: 要完成Story所需要的工作<br>2. Product Backlog: 代辦事項<br>3. Sprint Backlog: 特定Sprint的代辦事項<br>4. Potentially Shippable Product Increment: 要交付的事項<br>5. Burndown Chart: 每個Task中還有多少Backlog</blockquote><p>Activity</p><blockquote>1. Sprint: 通常是1–4周為一單位<br>2. Daily Scrum: Stand-Up meeting, 約莫10–15分鐘每天，同步團隊進度<br>3. Sprint Planning: 特定Sprint要交付那些item<br>4. Product Backlog Refinement: PO跟Team討論要開工的Item, 同時以商業和使用者角度切入, 跟技術較無關聯性<br>5. Sprint Review: Sprint結束後對產品的意見討論<br>6. Sprint Retro: Scrum Team member的意見討論並且改善</blockquote><p><strong>Work Item:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fOaxPl1i6MlgX2_2vMBZ0Q.png" /></figure><p>Epic: 包含很多故事的大故事 [想要做一個可以收集口罩跟酒精存貨的應用]</p><p>Feature: 這個Epic大致要完成的功能 [要有地圖，要可以GPS，要可以下單]</p><p>User Story: 情境[作為使用者想要用LINE PAY支付訂單]</p><p>Impediment: 造成某個目標一直無法達成的因素</p><blockquote>除了這些敏捷開發的基本選項之外，你也可以自由設計整個Work Item要呈現的資料，包刮Assign，Tags，或是其他自定義的Column。</blockquote><h4>Board:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YoxR1orcK-CpMX5wasfjqw.png" /></figure><p>在Board中，你可以根據不同的進度看到不同的工作項目。你可以追蹤你想要追蹤的工作項目，可以去設定不同工作項目的優先順序。</p><h4>Sprints:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mGqvcOslStHVUFEcQYDMCA.png" /></figure><p>從Sprints中可以設定所有參與者的Capacity，以便於安排工作規劃。在Sprints中也可以去檢視Burndown 的狀態。</p><p><strong>Queries:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fXVcbVtMV_z8Wg_ixtKsnQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mvg9SUQyeyfbIjUXnFfBWw.png" /></figure><p>他可以透過搜尋條件數據化呈現整個專案的內容，並且釘選成widget。</p><p><strong>WIKI:</strong></p><p>可以拿來放Scope，文件，Schema等各項團隊內想要互相分享的資料。</p><h4>Azure TestPlans(測試平台)</h4><p>一般測試從程式碼測試到系統測試等，我們可以簡單分類成</p><p>單元測試: 單獨針對不同的function、method等驗證。具有FIRST的特性 [快速、獨立、可重現性、可自我驗證性、即時性]<br>驗收測試: 測試整個系統以確保模組的可行性<br>整合測試: 確保整個系統在production環境是否正常運行</p><p>開發者可以選擇手動測試或是自動測試，當然，在DevOps的生態中是期待可以自動化測試。</p><p>自動化測試分兩種</p><p>TDD (Test-Driven Dev): 使用自動化單元測試驗證個別模組<br>ATDD (Acceptance Test-Driven Dev): 驗證User Story</p><blockquote>而Azure DevOps中的Test Plans他不僅導入一致的測試模板，還有報表呈現測試的結果，可以讓協同合作專案變得一目了然。</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v8JOM0a19opsAqrM8Vrpgw.png" /></figure><p><strong>Test Case [ </strong>針對一個功能的測試步驟，每一個test case就是一個work item <strong>]<br></strong>按鈕按下去的反應是否正確</p><p><strong>Test Suite[ </strong>Group Test Case，相關的Test Case放在一起 <strong>]</strong><br>有一個Suite是跟使用者管理相關的功能測試</p><p><strong>Test Plan[</strong>某一次的測試的執行計畫 <strong>]<br></strong>定義不同的測試需求，但實際運行的是Test Case</p><p><strong>Define [</strong> 定義test case <strong>]</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*kTwZWHnhJo-3ZFcJTHeJeA.png" /></figure><p><strong>Execute [ </strong>執行test case <strong>]</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WMjh3p_t4MQTwc1caQvr1Q.png" /></figure><p><strong>Chart [</strong>看test case的結果 <strong>]</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FyLV5wcH9XXOi_Oggt6I6Q.png" /></figure><h4>Azure Artifacts(共享套件)</h4><p>package management的感覺，把專案需要的class, framework等編譯好的package透過Azure Artifacts統一管理。以便多個專案可以共用，減少重複的原始碼。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xkDoi2yDdELO-Jjd27KGVw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SXisqat05CtHDMLOPzqMdg.png" /></figure><blockquote>以上是關於Azure DevOps的基礎概念，雖然有些繁雜但整體理解起來還算容易，下一次，我想要紀錄自己的專案，一個實際的操作，才能真的融會貫通整個服務的精髓。歡迎大家找我寫Side Project，讓我盡快生出下一個動手DevOps篇。</blockquote><p>Reference:<br> <a href="https://ithelp.ithome.com.tw/articles/10203935">https://ithelp.ithome.com.tw/articles/10203935</a><br> <a href="https://docs.microsoft.com/en-us/azure/devops/user-guide/services?view=azure-devops">https://docs.microsoft.com/en-us/azure/devops/user-guide/services?view=azure-devops</a><br> <a href="https://blog.csdn.net/cpongo2/article/details/89017231?depth_1-utm_source=distribute.pc_relevant.none-task&amp;utm_source=distribute.pc_relevant.none-task">https://blog.csdn.net/cpongo2/article/details/89017231?depth_1-utm_source=distribute.pc_relevant.none-task&amp;utm_source=distribute.pc_relevant.none-task</a><br> <a href="https://www.zhihu.com/question/26996772">https://www.zhihu.com/question/26996772</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26670edecd6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Conversational AI on Azure Update HOL 101]]></title>
            <link>https://medium.com/@yvontarbajo/conversational-ai-on-azure-update-hol-101-3479b4db39bd?source=rss-964c0c1641e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/3479b4db39bd</guid>
            <category><![CDATA[line]]></category>
            <category><![CDATA[conversational-ai]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Yvshih]]></dc:creator>
            <pubDate>Thu, 22 Aug 2019 06:56:02 GMT</pubDate>
            <atom:updated>2019-08-22T06:56:02.268Z</atom:updated>
            <content:encoded><![CDATA[<p>首先你必備<br>1. Azure Subscription<br>2. Any IDE, VSCode, Sublime 依照你的開發習慣, 但下面步驟我會用VSCode</p><h4>客服智能機器人</h4><p><strong>創建Bot Service on Azure</strong><br>{App Name} Bot Service Endpoint<br>{Bot Template} 目前線上支援C#, Nodejs, 但SDK有支援Python<br>{LUIS} 如果開啟的Template是LUIS，會需要建立LUIS服務，但這邊的區域選擇跟LUIS詞句判斷的Culture無關，所以default建立只能是英文語系，如果要建立中文語系的使用者不建議使用。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*IKLnXLk0F9U_l8iKs2Nh8g.png" /></figure><p><strong>載程式碼到本地端</strong><br>Bot Service 其實有提供線上編輯的功能(下圖的Open Online Code Editor或是可以連到<a href="https://yvondemobot.scm.azurewebsites.net/dev/wwwroot/:vs.markdown/readme.md">https://{AppName}.scm.azurewebsites.net/dev/wwwroot/:vs.markdown/readme.md</a>)，但如果需要大量開發還是建議用本地端的IDE比較方便。所以可以Download Bot Source Code。<br>此外，如果你想要在本地端也可以測試Bot，別忘記安裝<a href="https://github.com/Microsoft/BotFramework-Emulator/releases">Emulator</a>(v4)*</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MTJv18pjVfBS4kqgG0pl9g.png" /><figcaption>Azure Portal: Download Source Code</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DXVOPFtMXm2L7RhzPiN9Mg.png" /></figure><p>這邊稍微介紹一下基礎的檔案</p><pre>進入點: index.js, 定義bot route, module等<br>環境變數(在Azure Portal上的Application Settings): .env<br>對話定義: bot.js, 這是一個簡單的echo bot所以只有一個file去定義activity的反應; 如果未來你需要handle各種對話就會需要更多更完整的js file去管理</pre><h4>How Bots Work</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/0*p9rfEinmXUgZUmfI" /><figcaption>當新的使用者連線時，Bot會被呼叫onMembersAdded</figcaption></figure><h4>程式碼微敘述(ES6)</h4><pre>const { BotFrameworkAdapter, ConversationState, InputHints, MemoryStorage, UserState } = require(&#39;botbuilder&#39;);</pre><p>const{} 是一個 ES6 syntax-simpler 寫法，他的概念用個例子來看是</p><pre>const obj = {<br>    email: &quot;yv@ms.com&quot;,<br>    title: &quot;hola, yv&quot;<br>}</pre><pre>const { email,title } = obj;</pre><pre>console.log(email)-----yv@ms.com<br>console.log(title)-----hola,yv</pre><p>botbuilder</p><pre>├── botbuilder<br>├── botbuilder-ai<br>├── botbuilder-azure<br>├── botbuilder-core<br>├── botbuilder-dialogs<br>├── botframework-config<br>├── botframework-connector<br>├── botframework-schema</pre><ul><li>- ai: LUIS, QnA maker等Azure的AI Framework</li><li>- dialog: 處理對話, 像是prompt, 文字數字等</li><li>- connector: 對通訊軟體的串接</li></ul><p>botbuilder-core: 舉凡使用者訊息狀態的管理，memory的操作等</p><pre>export * from &#39;../../botframework-schema/lib&#39;;<br>export * from &#39;./autoSaveStateMiddleware&#39;;<br>export * from &#39;./botAdapter&#39;;<br>export * from &#39;./botState&#39;;<br>export * from &#39;./botStatePropertyAccessor&#39;;<br>export * from &#39;./botStateSet&#39;;<br>export * from &#39;./browserStorage&#39;;<br>export * from &#39;./cardFactory&#39;;<br>export * from &#39;./conversationState&#39;;<br>export * from &#39;./memoryStorage&#39;;<br>export * from &#39;./memoryTranscriptStore&#39;;<br>export * from &#39;./messageFactory&#39;;<br>export * from &#39;./middlewareSet&#39;;<br>export * from &#39;./privateConversationState&#39;;<br>export * from &#39;./propertyManager&#39;;<br>export * from &#39;./recognizerResult&#39;;<br>export * from &#39;./showTypingMiddleware&#39;;<br>export * from &#39;./storage&#39;;<br>export * from &#39;./testAdapter&#39;;<br>export * from &#39;./transcriptLogger&#39;;<br>export * from &#39;./turnContext&#39;;<br>export * from &#39;./userState&#39;;</pre><h4>Bot Design</h4><p>Procedural Conversation Flow</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*RLpw6VYtPzVrJAho0TlX9g.png" /></figure><p>傳統的應用程式，比如說像是Web，使用者可以任意的選擇上一頁或是下一頁；但在Bot基礎的應用程式，其實是Dialog的形式在跟使用者互動，所以除了大家一直在討論的Status reserve之外，其實是沒辦法讓使用者任意上下頁切換的。</p><p>這其實也是在建立Bot的時候需要去重新思考架構的重點之一。</p><p>Mysterious and Clueless</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e3jumSfUN1FC6Jmfxkj_uA.png" /></figure><p>神秘與無所適從，以上述的範例可以看出來</p><ul><li>左邊的Bot因為對使用者來說是沒有任何反饋的，就像跟朋友聊天，如果被已讀了但對方一直靜默不語心情一定會非常不愉悅！所以會建議使用proactive message讓對話方知道其實Bot是正在為你工作的。</li><li>右邊的Bot則是不明所以，沒有明確的指示，使用者完全沒有頭緒要怎麼操作這個Bot，到底要怎樣呼喚出我想要功能。而這部份我們會建議使用welcome message+buttons+<a href="https://github.com/Microsoft/botbuilder-js/blob/master/libraries/botbuilder-core/src/transcriptLogger.ts">middleware</a>讓使用者有更明確的方向。</li></ul><p>Rich Cards</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f1xBlC-f-ALtHD8H6SyilQ.png" /></figure><ol><li><strong>Animated Card</strong>: Play GIFs</li><li><strong>Audio Card</strong>: Playable audio</li><li><strong>Hero Card</strong>: One large image and several buttons</li><li><strong>Thumbnail Card</strong>: Thumbnail image, buttons and text</li><li><strong>Receipt Card</strong>:Receipt format</li><li><strong>Sign In Card</strong>: Sign in</li><li><strong>Video Card</strong>: Play videos</li></ol><p><strong>常用程式碼分享</strong></p><ol><li>Welcome Message(onMemberAdded())</li></ol><pre>// Sends welcome messages to conversation members when they join the conversation.<br>// Messages are only sent to conversation members who aren&#39;t the bot.<br>this.<strong>onMembersAdded</strong>(async (context, next) =&gt; {<br>   <strong> for (const idx in context.activity.membersAdded) {<br>        if (context.activity.membersAdded[idx].id !== context.activity.recipient.id) {</strong><br>            <strong>await context.sendActivity(`Welcome to the &#39;Welcome User&#39; Bot. This bot will introduce you to welcoming and greeting users.`);</strong><br>            await context.sendActivity(&quot;You are seeing this message because the bot received at least one &#39;ConversationUpdate&#39; &quot; +<br>                &#39;event, indicating you (and possibly others) joined the conversation. If you are using the emulator, &#39; +<br>                &quot;pressing the &#39;Start Over&#39; button to trigger this event again. The specifics of the &#39;ConversationUpdate&#39; &quot; +<br>                &#39;event depends on the channel. You can read more information at <a href="https://aka.ms/about-botframework-welcome-user&#39;">https://aka.ms/about-botframework-welcome-user&#39;</a>);<br>            await context.sendActivity(`It is a good pattern to use this event to send general greeting to user, explaining what your bot can do. ` +<br>                `In this example, the bot handles &#39;hello&#39;, &#39;hi&#39;, &#39;help&#39; and &#39;intro. ` +<br>                `Try it now, type &#39;hi&#39;`);<br>        }<br>    }</pre><pre>    await next();</pre><ol><li>Send Text Message</li></ol><pre>async sendSuggestedActions(turnContext) {     <br>    var reply = MessageFactory.suggestedActions([&#39;Red&#39;, &#39;Yellow&#39;, &#39;Blue&#39;], &#39;What is the best color?&#39;);     <br>    await turnContext.sendActivity(reply); <br>}</pre><p>2. Send Cards(<strong>heroCard</strong>可以依需求不同而換成其他card type)</p><pre>const reply = { type: ActivityTypes.Message };<br>const buttons = [{ <br>    type: ActionTypes.ImBack, title: &#39;1. Inline Attachment&#39;, value: &#39;1&#39; },<br>    ...<br>];</pre><pre>const card = CardFactory.<strong>heroCard</strong>(&#39;&#39;, undefined,<br>    buttons, { text: &#39;You can upload an image or select one of the following choices.&#39; });</pre><pre>reply.attachments = [card];</pre><pre>await turnContext.sendActivity(reply);</pre><p>3. Receive Message</p><pre>let text = turnContext.activity.text;</pre><p><strong>Dispatcher tool</strong></p><p>有時候，單一個LUIS或是QnA maker模型並沒辦法完整的滿足現在的Bot設計，所以Microsoft開發了一個dispatcher tool，把你想要整合的LUIS跟QnA maker包在一起，變成一組<strong>LUIS Model</strong>，然後透過演算法去判斷最符合的回覆。</p><p>安裝dispatcher</p><pre>npm i -g npm npm i -g botdispatch</pre><p>創一個dispatch file</p><pre>dispatch init -n &lt;filename-to-create&gt; --luisAuthoringKey &quot;&lt;your-luis-authoring-key&gt;&quot; --luisAuthoringRegion &lt;your-region&gt;</pre><p>把LUIS model加入.dispatch</p><pre>dispatch add -t luis -i &quot;&lt;app-id-for-weather-app&gt;&quot; -n &quot;&lt;name-of-weather-app&gt;&quot; -v &lt;app-version-number&gt; -k &quot;&lt;your-luis-authoring-key&gt;&quot; --intentName l_Weather</pre><p>把QnA maker加入.dispatch</p><pre>dispatch add -t qna -i &quot;&lt;knowledge-base-id&gt;&quot; -n &quot;&lt;knowledge-base-name&gt;&quot; -k &quot;&lt;azure-qna-service-key1&gt;&quot; --intentName q_sample-qna</pre><p>建立dispatch</p><pre>dispatch create</pre><p>完成之後再到luis.ai就會看到如附圖</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CC3qADtmvK-oKWVrqK2nxg.png" /></figure><p>在bot.js程式碼中，</p><p>針對不同的intent(意圖)，要做的處理，如果資料被判斷為q_BotFaq，代表訊息被認為是由QnA Maker這個intent，所以將job交給QnAmaker回覆；LUIS亦然。</p><pre>case &#39;q_BotFaq:<br>        await this.processSampleQnA(context);<br>        break;<br>    default:<br>        console.log(`Dispatch unrecognized intent: ${ intent }.`);<br>        await context.sendActivity(`Dispatch unrecognized intent: ${ intent }.`);<br>        break;<br>    }<br>}<br>case &#39;I_HomeAutomation&#39;:</pre><pre>async processHomeAutomation(context, luisResult) {<br>    console.log(&#39;processHomeAutomation&#39;);</pre><pre>    const result = luisResult.connectedServiceResult;<br>    const intent = result.topScoringIntent.intent;<br>}</pre><p>如果要整合QnA maker或是LUISㄝ, 別忘記在環境變數中新增</p><pre>MicrosoftAppId={}<br>MicrosoftAppPassword={}<br>QnAKnowledgebaseId={}<br>QnAEndpointKey={}<br>QnAEndpointHostName=<a href="https://yvoneqademo.azurewebsites.net/qnamaker">https://</a>{}<a href="https://yvoneqademo.azurewebsites.net/qnamaker">.azurewebsites.net/qnamaker</a></pre><blockquote>Key, HostName或是ID都是可以在QnA maker, LUIS Portal中的Setting中找到</blockquote><p>超簡單VSCode佈署</p><p>在VSCode裡面新增Azure Extension之後，就可以整合絕大部分的Azure服務，會用訂閱分類。當我準備好要佈署時，選擇左下角的Azure Icon，然後針對要佈署的訂閱上傳，就會自動帶入視窗詢問你要佈署的資源資訊等。依照問題一步一步設定，就可以佈署完成。取代了一般用git佈署的麻煩性。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hG9ZabjJJszupRD1FFOnzA.png" /></figure><blockquote><em>不過，如果希望作CI/CD的開發，那還是建議佈署到Github或是以下支援的Repo儲存庫。</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NP071HnmILCqtic0" /></figure><p>Channel</p><p>通訊平台的支援，熟知的Facebook, LINE, Telegram, Slack, 或是Microsoft的Teams等都可以很簡單的串接。<em>(只需要給通訊平台AppID,權杖)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dPlRzR5oDP-lmQResYWjjw.png" /></figure><p>雖然好像串接很快，但尤其要注意，並不是所有通訊平台都有支援所有Bot Framework提供的服務。</p><p>舉例來說，如果平台並不支援Card中夾帶影片，那在該平台就無法呈現其效果。</p><p>補充:<br>1. UnitTest: <a href="https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-mocha-test-adapter">https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-mocha-test-adapter</a><br>2. SampleCode: <a href="https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/javascript_nodejs/14.nlp-with-dispatch/bots">https://github.com/microsoft/BotBuilder-Samples/tree/master/samples</a></p><p>*: 使用前別忘記更新到最新，就算同樣是v4建立的.bot file都不相容</p><blockquote>後記: 因為Bot Service on Azure能討論的東西太多, 此篇文章將持續更新</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3479b4db39bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[在Azure時，當DevOps遇上Container-(1)]]></title>
            <link>https://medium.com/@yvontarbajo/%E5%9C%A8azure%E6%99%82-%E7%95%B6devops%E9%81%87%E4%B8%8Acontainer-1-7accb6b26a3f?source=rss-964c0c1641e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/7accb6b26a3f</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[k8s]]></category>
            <category><![CDATA[ak]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Yvshih]]></dc:creator>
            <pubDate>Thu, 11 Apr 2019 11:47:25 GMT</pubDate>
            <atom:updated>2019-04-11T11:47:25.166Z</atom:updated>
            <content:encoded><![CDATA[<p>下筆的這一秒我在思考，也許這是一篇會寫很久很久很久的文章吧…</p><p>關於Container的基礎概念其實之前在<a href="https://medium.com/@yvontarbajo/%E4%B8%80%E7%A7%92%E5%BC%84%E6%87%82container-5fd3758b340f">這篇文章</a>就有小小提過。後來Kubernetes的熱潮把我淹沒以後，花了很多時間遲遲無法掌握整個Container生態。思考彙整了一下，為什麼大家都要談Container ?</p><p><em>Docker官網說…</em></p><p>★ Standard<br>★ <strong>Lightweight</strong><br>★ Secure</p><p><em>但我想除此之外…</em></p><p>★ <strong>Portable</strong>: 我們可以把程式隨意在不同的computing engine中搬移; 可以當成staging環境也可以換到production…</p><p>或許這也是DevOps的世界裡少不了Container的一個因素吧；一致化開發與營運的邏輯與架構。</p><p>綜合了許多Container的好處，可以發現，Container 解決了<em>Dev</em>跟<em>Operation</em>的矛盾，並在其中搭建橋樑，因為Container把應用做標準化打包之後，在所有可以執行Container 的平台都能執行這個應用，而且應用之間在共享同一個OS Kernel的狀況下相互隔離。</p><blockquote>Short to market, fast to innovation;<br>Build once, run everywhere;<br>Easier management, high efficiency.</blockquote><blockquote>微軟擁抱開源</blockquote><p>在開始DevOps之前，先談談Azure上提供了哪些Container相關的服務吧</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qih-8-4YcukNhuNd5rjN7w.png" /><figcaption>Azure Container Ecosystem</figcaption></figure><h3>AKS — Azure Kubernetes Service</h3><p>Simplify the deployment, management, <br> and operations of Kubernetes</p><p>Kubernetes (容器編排): 容器的創建、調度和運維工具，Google開發。</p><blockquote>其實容器的管理的工具不只有K8S(Kubernetes縮寫)，AKS還與Docker Swarm共同上演了容器時代的雙城記呢。</blockquote><h4>Kubernetes架構</h4><p>Kubernetes Cluster = Master Node + Worker Nodes ;</p><p>(下述將以一個公司的組織營運來說明(想像)K8S)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*bzQYXXBtkt1sSEZForHEww.png" /></figure><p><strong>Master Node[總經理]<br></strong>主控。負責Kubernetes Clusters和Worker的工作排程、溝通以及監控其狀態。</p><p><strong>API Server[業務]<br></strong>客戶端接口。資源操作的RESTFUL入口，處理要求並請求分派資源。</p><p><strong>Controller[部門IT]<br></strong>Clusters的維護狀態，故障檢測。但內部又包含多個控制器元件，各司其職。Node Controller負責節點的狀態的告知與回應；Replication Controller負責確保同時間有存在指定數量的Pod copy在運行。</p><p><strong>Scheduler[秘書]<br></strong>排程&amp;資源調度。根據Client的需求決定是否元件配置以及如何將Pod放到相應的Worker派工。</p><p><strong>etcd[組織圖]<br></strong>保存Clusters所有的資料跟配置資訊。透過RAFT演算法實現，是一種高可用的分散式KV儲存。</p><p><strong>Worker Node[部門主管 ]</strong><br>Runtime Environment。負責實際Container的執行。</p><p><strong>Kubelet[部門副主管]<br></strong>代理人。負責跟API Server的溝通，處理Container的運行並且確保Node的穩定正常運行，操作Pod，並且回報狀態給Master。</p><p><strong>Kube-Proxy[部門郵務處]<br></strong>轉發 網路連線。負責Sub-Net Clusters的網路規則、負載平衡。在多個隔離的網路中正確分配請求。</p><p><strong>Pod[專案]<br></strong>Kubernetes中的最小佈署單位。由一個或多個容器組成，共享Network, Volume, Container配置(如: Namespace)等，所以這些容器會共生死。Pod之間可以透過localhost溝通。應用程式的邏輯主機。<br>但Pod並不是主要保障服務正常運行的元件，整體服務的高可用性是藉由調度節點而達到。</p><p><strong>Container Runtime[專案小組長]<br></strong>管理Container Image。通常會用Docker，其他同樣可以用的還有rkt, Frakti等。</p><p><strong>Container[員工/專案組員]</strong><br>應用程式執行時需要的執行環境。</p><blockquote>一個主要的架構從最上層的總經理負責了整個公司的營運，而外部需求都需要業務從外面接案回來。有了案子之後，再分派給各個相應的部門去處理。而部門內也會依照專案分派人力去操作。</blockquote><h4>Azure Kubernetes Service架構</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*LDiprb-ubqv6GVpTjtlOxA.png" /><figcaption>AKS Architecture</figcaption></figure><p>Azure提供了一個平台可以讓使用者更容易操作managed kubernetes cluster，因為Azure會處理大部分的事情，如，主機、監控等；更甚整合了Azure AD和RBAC提高可靠安全性。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/0*AHTZ0RK_W1BtrfVF.png" /><figcaption>AKS與AAD整合</figcaption></figure><p>與AAD整合之後，可以設定使用者針對Namespace的資源存取權限。如果要更detail的限制執行動作，則需要透過RBAC(Role Based Access Control)。</p><h4>WHY AKS</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*1DG7VR9mh2l1LugZkuehIg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xFP5MXksmp6SstZdl551AA.png" /><figcaption>快速佈署Kubernets Cluster</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EkcP1btw6A5VY-WhocUR-w.png" /><figcaption>Container Health Panel in Azure Portal</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*BowJhFWEmVWW1fJi0Ohy1Q.png" /><figcaption>跟Visual Studio Code整合應用</figcaption></figure><blockquote>在<a href="https://docs.microsoft.com/zh-tw/cli/azure/aks?toc=%2Fzh-tw%2Fazure%2Faks%2FTOC.json&amp;bc=%2Fzh-tw%2Fazure%2Fbread%2Ftoc.json&amp;view=azure-cli-latest#az-aks-create">這裡</a>有詳述如何利用az aks commands管理AKS。</blockquote><h3>ACI— Azure Container Instance</h3><p>Your container, running in Azure</p><p>一般開發我們想要運行Container，我們需要一台機器，裝上Docker；但現在，如果你不想要自己維護這些computing power，你可以不再需要自己裝虛擬機器不需要自己安裝套件，因為Container Instance可以幫你做到。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*AR_P2jWxylPp2A9z63oavw.png" /></figure><p>ACI 的工作就是幫助你在很多的時間(in seconds)幫你起了一個[Hypervisor-level isolation]環境(而你不需要自己管理)，這個環境你甚至可以自己自訂CPU/memory，可以容納Linux跟Windows的Container，最後還可以透過Public IP跟完整網域讓你的Application公告在世界上。</p><pre>az container create -g {ResourceGroup} -n {name} --image {imageUrl} --ip-address public --ports {Port}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*goheaMKrJqD1EfETpoPA9A.png" /></figure><p>如果在同一個機器上同時運作多個容器的時候，就會行程一個容器群組。<br>他們會共用很多資源，甚至是生命週期。你可以透過yaml file佈署容器群組。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/0*kQzHtwotqo8nWDln.png" /></figure><h3>ACR — Azure Container Registry</h3><p>Simplify container development by easily storing and managing container images for Azure deployments in a central private registry.</p><p>Container Image 是把應用打包好的映像檔，透過這個檔案產生實例。<br>Docker File 則是描述如何建制Container Image。<br>Container Registry 就是一個放置這些Image的空間，我們一般常見的就是Docker Hub，是一個Docker官方提供的公開儲存庫，當然，Docker也有提供讓開發者自己host Registry的方式。</p><h4>Azure Container Registry 對我而言有點像是Docker Hub 跟 Docker self-host的綜合體。</h4><p>因為他不需要自己Host可是又可以具有private的特質。自動化建制執行與擴充等，都由Azure Backend處理。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*WFqj3gVR45VTCx89u6x_TQ.png" /></figure><p>概念上，每一個訂閱裡面我們都可以有多個的Registry，而每一個Registry內更可以有至少一個的Repo，都支援多層的Namespace。Image則是存在於Repo之中，要執行時就是透過上面有提到的Docker command把Image從這些Repo內拉出來跑。</p><p><strong>建立ACR</strong></p><pre>az acr create --resource-group myResourceGroup --name myContainerRegistry007 --sku Basic</pre><p><strong>登入ACR</strong></p><pre>az acr login --name &lt;acrName&gt;</pre><p>至於其他像是執行/刪除/推送image的指令，就跟我們一般透過docker操作一樣。</p><pre>docker push Image:Version<br>docker run Image:Version<br>... </pre><p>比較特別的應該是ACR具有異地複寫的功能，預設，他會將網路起在靠近佈署的位置。</p><p>在Azure Portal中可以透過 異地複寫的設定 選擇下圖中綠色六角形方塊，按下建立，就可以完成複寫！</p><blockquote>超神奇超快速超方便！</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/0*LU8sUzgBuJitICbS.png" /></figure><p>如果想要自己動手玩玩看，官方文件有提供<a href="https://github.com/Azure-Samples/acr-helloworld.git">Git Repo</a>唷。</p><p>別忘記更改{ProjectPath}/AcrHelloworld/Dockerfile 的{acrName}</p><pre>docker build .f ./AcrHellworld/Dockerfile -r {ImagePathinRegistry}<br>docker push {ImagePathinRegistry}:Version</pre><p>接下來就可以到Azure Portal佈署你的應用囉！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*0qE26NpH7cx67lrW.png" /></figure><blockquote>寫到這邊算是Azure在Container相關技術的一個小小段落(其實是已經寫太久厭倦了..?)，在Kubernetes跟Container對我而言還是一個博大精深的黑洞，之後還會Update Part2 Part3……吧。</blockquote><p>註: RBAC(Role Based Access Control)-控制namespace等資源的存取權限。</p><p>補充:<br>1. Namespaces: Linux kernel對系統資源進行隔離跟虛擬化。包括process ID, network, mnt,等。<br>2. cgroup: control groups, 限制控制與分離一個行程群組資源，如: CPU, Memory, I/O等。</p><p>Reference:<br>1. <a href="https://www.youtube.com/watch?v=gmN732qN1Gg">https://www.youtube.com/watch?v=gmN732qN1Gg</a><br>2. <a href="https://gcpug-tw.gitbook.io/kuberbetes-in-action/kubernetes-gai-nian">https://gcpug-tw.gitbook.io/kuberbetes-in-action/kubernetes-gai-nian</a><br>3. <a href="https://jimmysong.io/kubernetes-handbook/concepts/pod.html">https://jimmysong.io/kubernetes-handbook/concepts/</a><br>4. <a href="https://docs.microsoft.com/zh-tw/azure/aks/concepts-identity">https://docs.microsoft.com/zh-tw/azure/aks/</a><br>5. <a href="https://www.youtube.com/watch?v=EthBRXMcWao">https://www.youtube.com/watch?v=EthBRXMcWao</a></p><blockquote>哦對了，其實Docker只是Container Technology的一種實現。Docker != Container。</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7accb6b26a3f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cognitive Search(Preview)]]></title>
            <link>https://medium.com/@yvontarbajo/cognitive-search-preview-c0b6bd209680?source=rss-964c0c1641e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0b6bd209680</guid>
            <category><![CDATA[ocr]]></category>
            <category><![CDATA[azure-search]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[cognitive]]></category>
            <category><![CDATA[cognitive-search]]></category>
            <dc:creator><![CDATA[Yvshih]]></dc:creator>
            <pubDate>Tue, 15 Jan 2019 10:50:07 GMT</pubDate>
            <atom:updated>2019-01-15T10:50:07.062Z</atom:updated>
            <content:encoded><![CDATA[<p>AI-first approach to content understanding.</p><p>除了原先的Azure Search之外，Microsoft在2018年發布了Cognitive Search，整合了如:OCR, NLP的演算法在Search當中，讓原本可能沒有辦法被搜尋的資料也能被關鍵字搜尋到，如: 文件圖檔透過OCR之後，可以將其中的文字被切割出來，使用者可以直接搜尋圖檔的語句。</p><h4>Life Cycle</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sJdkAgOy2nk8bWVK.JPG" /></figure><p>在使用Azure Search的時候，我們得先拿到Data，也許是Blob, SQL DB, CosmosDB等，從資料來源可以發現，Data的<a href="https://docs.microsoft.com/zh-tw/azure/search/search-howto-indexing-azure-blob-storage#supported-document-formats">格式</a>其實是很不受限的，而Cognitive Search就是在資料擷取階段透過NLP或是OCR等<a href="https://azure.microsoft.com/en-us/services/cognitive-services/?v=18.44b">演算法</a>做檔案的分析，並且將分析之後的結果當作<em>Search Index。</em></p><blockquote>如果到這邊還是對<em>Cognitive Search</em>這個名詞感到陌生跟莫名的話，可以到<a href="https://jfk-demo.azurewebsites.net/#/">這裡</a>看看DEMO，看完之後有一種，哦阿～原來如此的感覺！</blockquote><p>其實在去年的Microsoft Connect(); Scott就有分享過這個功能，但是當下太多新功能Update，我對Azure Search又不是太專精的情況，只有滿頭問號哈哈。</p><blockquote>那如果想要跟著做的話，就讓我們繼續往下走吧。(我們將實做文件中的Quick Start)</blockquote><h4>Hands-On Trial</h4><ol><li>建立Azure Search服務</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9vn1wMfcLZ0V0WZeDBPX2Q.png" /></figure><blockquote>目前支援Cognitive Search的Region只有: West Central US, South Central US, East US, East US 2, West US 2, Canada Central, West Europe, UK South, North Europe, Brazil South, Southeast Asia, Central India, Australia Eas</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kVVh8BbKyoE5t_sVtVrOZw.png" /></figure><blockquote>Azure Table Storage 不支援 cognitive search.</blockquote><p>在Blob中建立Container(這個不是小鯨魚)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BgmRn8hP_dhgQP8FDFkSWw.png" /></figure><p>然後上傳你要拿來搜尋的檔案們</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nfvvi9dlG4R_p4bAQo_vVw.png" /></figure><p>接下來請先建立一個Azure Search服務，並且選擇Import Data一欄，因為我們要把我們剛剛放在Blob Storage裡面的資料拿來當成Azure Search的Source。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*1Owfr0U6gK5lwmHuMF28Vw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*n9-Jg4hGZmNqPgTJi8ohdQ.png" /></figure><p>Data Source的選擇滿多的，舉凡Azure上面有提供的都可以！</p><p>我們這邊選Azure Blob Storage，因為剛剛把檔案放在這邊。 <br><em>Choose an existing connection</em>可以自動抓到我們剛剛建立的。</p><blockquote>然後最重要的就是下一步 “ Add Cognitive Search “ 才能整合我們這次要介紹的認知搜尋到Azure Search中！！！</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U7KkzQr_TG09ixk3RNdxiw.png" /></figure><p>這邊官方文件有提到，他有一些內建的機器學習的分析，像是OCR或是Text的剖析，會針對我們剛剛提供的那些Data Source做基本資料判斷。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bfmmFHOyQSQs8BNckw5Dew.png" /></figure><p>建議把Content的Retrievable拿掉的原因是，Blob的資料量可能非常大，所以如果支援Retrievable會造成很heavy的工作量。</p><p>我現在在Search Explorer 找 Cognitives Searvices</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/409/1*3cVmRD7zZQIUdreMl1RtGw.png" /><figcaption>Data Source</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3gq157fXUMB-IT8c3aBUfw.png" /><figcaption>搜尋結果</figcaption></figure><p>上面那是一個很簡單的文字跟圖片上面的小範例，在微軟的Build大會裡面有舉過NBA球員的案例，我覺得更有趣！下面提供影片參考～</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F8i4snWofThk%3Fstart%3D422%26feature%3Doembed%26start%3D422&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D8i4snWofThk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F8i4snWofThk%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f410c3e86805849dd41075b92368013/href">https://medium.com/media/9f410c3e86805849dd41075b92368013/href</a></iframe><p>在玩過這個服務以後發現，其實跟預期以為的OCR相對關係小，這其實是一個Azure Search的Extension，讓原本只能用Sentence, Text的搜尋引擎整合更多Cognitive的智慧，如果建檔中只有圖片的用戶而言就少了轉文字的負擔，也不需要自己套OCR，語句分析也內建NLP，對於跟我一樣沒有學過自然語言的工程師而言，提供了非常容易上手的平台做搜尋。</p><blockquote>至於OCR以及NLP的有效程度可能就有待大家共同驗證了！如果有發現特別…”驚人”的結果歡迎在下面分享讓我知道哦～</blockquote><p>Reference:</p><ol><li><a href="https://docs.microsoft.com/en-us/azure/search/cognitive-search-tutorial-blob">https://docs.microsoft.com/en-us/azure/search/</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0b6bd209680" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure Serverless]]></title>
            <link>https://medium.com/@yvontarbajo/azure-serverless-e2e167111728?source=rss-964c0c1641e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2e167111728</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[azure-functions]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[functions-as-a-service]]></category>
            <category><![CDATA[azure-event-grid]]></category>
            <dc:creator><![CDATA[Yvshih]]></dc:creator>
            <pubDate>Tue, 15 Jan 2019 09:48:12 GMT</pubDate>
            <atom:updated>2019-01-15T09:48:12.339Z</atom:updated>
            <content:encoded><![CDATA[<p>為了準備這次尾牙報名亂用了一下azure上的logic apps所以也對Azure Serverless Service稍微筆記。</p><p>尾牙的情境: 報名成功之後會發送QRCode到員工信箱<br>1. 資料insert到cosmosdb<br>2. new document triggers qrcode generator<br>3. qrcode send to mailbox</p><p>我最後選擇用logic app的原因是我必須要用公司福委會的outlook帳號發信給員工，所以我不用sendgrid service，直接利用Logic App的Outlook Connectors。</p><h3>Serverless</h3><p>Spend less time managing infrastructure and more time solving business problems.</p><p>這是一個Server抽象化的概念，開發者不需要思考Server 規格, Computing Power等; 只需要規劃好想要部屬的程式，有micro progam的概念在其中，開發上更有彈性。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WtKh7_l801JFpgzl0yjQzQ.png" /></figure><ul><li>On-Premises: 給你磚塊跟鏟子，讓你自由發揮建造出自己的房子</li><li>IaaS: 給了你一個房間，但是家具要自己採購</li><li>PaaS: 給了你一個房間，裡面提供了各種家具，自己安排與規劃設計；一旦房間開門進去<em>，所有基礎建設都開始計費</em>。</li><li>Saas: 給了你一個房間，裡面家具設計都幫你規劃好了，想要用就自己開門進去。</li><li>Serverless: 打開房間任意門(因為你不需要知道這個房間在哪裡，只要可以提供你要的服務就好)，你可以自己選用裡面的設備，使用者付費；洗澡用了1L的水就付1L的水費就好，<em>房間不另外收費</em>。突然湧入很多人要洗澡的話，隔壁的房間也會自動開放，不需要另外訂房。</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5wB0zSIyG-eitB2RsPSeCA.png" /></figure><h3>Azure Functions</h3><h4>Execute your code based on events you specify</h4><p>是Azure提供最符合我們一般理解的Serverless服務，可以透過Timer或是Event Trigger開發好的Azure Functions(Micro Program)。</p><p>Durable Functions: 提供Stateful Functions</p><p>支援Runtime: C#, F#, JavaScript, Java, Python(當初發布這個支援是為了整合ML Model，希望可以提供ML開發者更有效率建立與訓練模型)</p><p>開發模式: Azure Portal; VS; VSCode; CLI; Maven*; OpenAPI</p><h4>Azure Portal</h4><p>STEP1: ms.portal.azure.com 登入Azure Subscription</p><p>STEP2: 建立服務(搜尋functions/函數應用程式)</p><ul><li>選擇自己習慣使用的Runtime跟計價方式</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sq-y6KQOhxbIzXxFWMHO-Q.png" /><figcaption>可以發現portal version沒有提供python runtime</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cl4XyOZlW5Gtw_QE0qZo9g.png" /><figcaption>這邊簡單介紹有哪些方式可以deploy functions</figcaption></figure><p>STEP3: 要用什麼方式Trigger Functions</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*B-ItlLanjQr_4Z-jWvu85g.png" /><figcaption>提供各種不同Trigger方式的範例</figcaption></figure><p>我這邊是有新的資料進到Cosmos DB就Trigger，新的資料欄位在Cosmos DB裡面稱之為document，所以系統會自動幫我寫出一段基本的程式碼如下，</p><pre>module.exports = async function (context, documents) {</pre><pre>if (!!documents &amp;&amp; documents.length &gt; 0) {</pre><pre>context.log(&#39;Document Id: &#39;, documents[0].name);<br><strong>//Send an HTTP request to genQRCode function&#39;s public URL.</strong></pre><pre>}</pre><pre>}</pre><p>詳細的Cosmos DB 資訊，像是要連線哪個帳戶等，都會在建立的時候設定，在”整合”這個欄位也都隨時可以修改。</p><p>因為我有另外一個Azure Functions是做QRCode的，所以我會在new document之後trigger QRCode Function的HTTP。</p><p>QRCode 生成完之後會透過sendgrid服務發信。</p><p>但有了新的Durable Functions之後…</p><p>Durable Functions是一個新的擴充功能，協助管理function之間的狀態；用同步或非同步的方式呼叫其他functions。</p><p>舉例而言，在這個範例中F2的input是F1的output，所以必須等F1正確跑出結果之後再去Trigger F2…以此類推。像這樣的值跟狀態的maintain就可以透過Durable Function處理。</p><p>下面用官方文件的Sample Code舉例，</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/0*YoJ00tBmuzOheU04.png" /></figure><pre>const df = require(&quot;durable-functions&quot;);  <br>module.exports = df.orchestrator(function*(context) {     <br>const parallelTasks = [];      <br>// get a list of N work items to process in parallel     <br>const workBatch = yield context.df.callActivity(&quot;F1&quot;);     <br>for (let i = 0; i &lt; workBatch.length; i++) {         parallelTasks.push(context.df.callActivity(&quot;F2&quot;, workBatch[i]));     }      <br>yield context.df.Task.all(parallelTasks);      <br>// aggregate all N outputs and send result to F3     <br>const sum = parallelTasks.reduce((prev, curr) =&gt; prev + curr, 0);     yield context.df.callActivity(&quot;F3&quot;, sum); });</pre><h4>Azure CLI 2.0- (Python 3.6+)</h4><pre>py -3.6 -m venv .env <br>.env\scripts\activate<br>//建立virtual environment </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*uAchKIsDQRpCOeq9jKcaSQ.png" /><figcaption>虛擬環境建好</figcaption></figure><pre>func init FirstFunProject</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*YwuV0hEpOkBjDCbFn4Np_w.png" /><figcaption>選Runtime</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YxPjXMXsyZVJqnsFQEYnNA.png" /><figcaption>建立Project基本需要的檔案，如gitignore/setting.json</figcaption></figure><p>開始建立Azure Functions</p><pre>cd FirstFunProject</pre><pre>func new</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*8Qzdh9dOensLPseTtiiysA.png" /><figcaption>照需要選擇要Trigger的方式</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E3UiwDB1Md4fpfoMA3TAtg.png" /><figcaption>選擇<strong>HTTP Trigger</strong>之後會跟在portal一樣自動生成基本程式檔</figcaption></figure><pre>import logging</pre><pre>import azure.functions as func</pre><pre>def main(req: func.HttpRequest) -&gt; func.HttpResponse:</pre><pre>logging.info(&#39;Python HTTP trigger function processed a request.&#39;)</pre><pre>name = req.params.get(&#39;name&#39;)</pre><pre>if not name:</pre><pre>try:</pre><pre>req_body = req.get_json()</pre><pre>except ValueError:</pre><pre>pass</pre><pre>else:</pre><pre>name = req_body.get(&#39;name&#39;)</pre><pre>if name:</pre><pre>return func.HttpResponse(f&quot;Hello {name}!&quot;)</pre><pre>else:</pre><pre>return func.HttpResponse(</pre><pre>&quot;Please pass a name on the query string or in the request body&quot;,</pre><pre>status_code=400</pre><pre>)</pre><pre>#__init__.py</pre><p>可以透過postman或是post url: localhost:7071/api/HttpTrigger?name={}測試</p><p>不過要先讓服務run起來</p><pre>func host start</pre><p>如果要Deploy Azure</p><pre>az group create — name myResourceGroup — location westeurope</pre><pre>az storage account create --name &lt;storage_name&gt; --location westeurope --resource-group myResourceGroup --sku Standard_LRS</pre><pre>az functionapp create --resource-group myResourceGroup --os-type Linux --consumption-plan-location westeurope  --runtime python<br>--name &lt;app_name&gt; --storage-account  &lt;storage_name&gt;</pre><pre>func azure functionapp publish &lt;app_name&gt;</pre><pre>curl https://&lt;app_name&gt;.azurewebsites.net/api/MyHttpTrigger?name=&lt;yourname&gt;</pre><h3>Logic Apps</h3><h4>Automating your workflows without writing a single line of code</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*a8CHZUwMIR6Y9EY-ZnBkeA.png" /></figure><p>跟Azure Functions不一樣的是，Logic Apps提供了連接更多SaaS的服務。透過GUI跟programming的方式讓開發者可以串接多種Azure或Third party提供的應用成一個<strong>workflow</strong>。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*fGjVgzHMp4LvYRaby923iA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VGIOe00brPuIiFdSgpIoKw.png" /></figure><p>Logic Apps的建立相對容易，只要想好要使用的服務應用程式以及邏輯順序為何，就可以透過GUI的Workflow建立好。如果想不出來也可以參考範本。</p><p>以我發送QRCode的例子而言，除了剛剛上面用CosmosDB當Trigger Event之外，我也可以透過HTTP Trigger QRCode generator然後發送郵件，發送郵件方式除了整合Microsoft自己的Outlook以外，還有sendgrid以及Gmail，但要留意他們內文的html格式不一致，所以如果是同時要發送Gmail跟Outlook的Workflow可能要分開。</p><p>當然除了透過portal建立之外，Visual Studio跟VSCode也有提供內建服務可以直接建立。</p><h3>Event Grid</h3><h4>Get reliable event delivery at massive scale</h4><p>不論Functions或是Logic Apps都會有各種events在空中飛來飛去。可能一個event 發生會 trigger多個function；或是某個function可以被多個events triggered等。而這時就需要event grid 協助管理這些路由。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*YMrPeqhxsA-Kt5IZZPdtsA.png" /></figure><p>所以我們可以把Event Grid視為Managed Route Service。其中有幾個重要的元件如下：</p><pre>Event(事件): 發生了什麼事。<br>Event Source(事件來源): 事件發生的位置；負責把事件傳送到Event Grid。<br>Topics(主題): 傳送事件的目的地端點。分為系統主題跟自訂主題兩種，系統主題是Azure Service提供的，需要訂閱才可以存取。<br>Event Subscription(事件訂閱): 定義事件函數要接收的主題，用來路由傳送事件的端點或是內建機制。<br>Event Handler(事件處理函式): 對事件做出回應的應用程式或是服務。</pre><h3>Reference:</h3><ol><li><a href="https://docs.microsoft.com/en-us/azure/azure-functions/">https://docs.microsoft.com/en-us/azure/azure-functions/</a></li><li><a href="https://docs.microsoft.com/en-us/azure/logic-apps/">https://docs.microsoft.com/en-us/azure/logic-apps/</a></li><li><a href="https://docs.microsoft.com/en-us/azure/logic-apps/">https://docs.microsoft.com/en-us/azure/</a>event-grids/</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2e167111728" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microsoft MyLearn II: 使用Azure佇列儲存體在應用程式之間通訊]]></title>
            <link>https://medium.com/@yvontarbajo/microsoft-mylearn-ii-%E4%BD%BF%E7%94%A8azure%E4%BD%87%E5%88%97%E5%84%B2%E5%AD%98%E9%AB%94%E5%9C%A8%E6%87%89%E7%94%A8%E7%A8%8B%E5%BC%8F%E4%B9%8B%E9%96%93%E9%80%9A%E8%A8%8A-ee69e71a0498?source=rss-964c0c1641e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee69e71a0498</guid>
            <category><![CDATA[message-queue]]></category>
            <category><![CDATA[queue]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[storage]]></category>
            <dc:creator><![CDATA[Yvshih]]></dc:creator>
            <pubDate>Tue, 09 Oct 2018 07:43:50 GMT</pubDate>
            <atom:updated>2018-10-09T07:43:50.723Z</atom:updated>
            <content:encoded><![CDATA[<p>如果是一個long running application或是後端需要大量處理的application，各元件之間直接通訊可能會造成問題，所以當網路頻寬很低時，或當需求很高時，我們很常會利用queue去做平行處理，避免塞車被鎖死的效應產生。而Azure在queue message management中提供了兩種服務: Queue Storage和Service Bus Queue；今天要透過mylearn介紹的就是Queue Storage。</p><p>Lab開始之前，先對Queue Storage簡單介紹一下:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*k3SdOsAYF9ZhOxc7l0wHDQ.png" /></figure><pre>1. Based on blob storage<br>2. 每一個queue會維護一份message list<br>3. 通常會有1或多個receiver跟sender<br>4. Processor 可以依照自定義的rule去等待queue的訊息，但是當任一processor因各種因素而無法處理完資料return回來，message則會重新回到queue，由其他processor拿走。***舉例而言: 當processorA說他要拿走訊息A，他設定的Expired Time是5分鐘，五分鐘之後processorA因為某種原因crash所以沒有return result，則訊息A重新回到queue中，由processorB拿去處理。***<br>5. Get: 從queue拿資料<br>   Peek: 看queue中有多少資料<br>   update: 更新processor跟queue之間的通訊 eg: 我需要更多時間處理這份資料<br>6. 常用於: 建立積存的工作供非同步處理&amp;&amp;將訊息從 Azure Web 角色傳遞至 Azure 背景工作角色</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/0*G6sYQvGE2MUICk7Q.png" /></figure><p>課程目標:<br>- 建立支援佇列的 Azure 儲存體帳戶。<br>- 使用 C# 和適用於 .NET 的 Azure 儲存體用戶端程式庫來建立佇列。<br>- 使用 C# 和適用於 .NET 的 Azure 儲存體用戶端程式庫，從佇列新增、擷取和移除訊息。</p><h4>WHY Queue?</h4><p>Queue可以暫時保存訊息，讓系統不會因為瞬間的大量資料而卡死；當需求很低的時候，Queue可以調整變小，當需求變高再增加，可以動態調整。<br>單一個queue的上限是500TB，可能儲存數百萬則訊息<br>單一個queue的目標傳送量是2000訊息/s</p><h4>WHAT is Messages?</h4><p>Queue中的message容忍上限是64KB<br>可以是xml, json, image format</p><p>Notice from mylearn</p><ul><li>佇列只能當做 Azure 一般用途儲存體帳戶 (v1 或 v2) 的一部分，無法新增至 Blob 儲存體帳戶。</li><li>針對 StorageV2 帳戶顯示的 [存取層] 設定只會套用至 Blob 儲存體，不會影響佇列。</li><li>選擇接近來源元件、目的地元件或兩者 (建議使用) 的位置。</li><li>資料一律會複寫至多部伺服器，以防範磁碟失敗或其他硬體問題。 您可以選擇複寫策略：[本地備援儲存體 (LRS)] 的成本很低，但在發生影響整個資料中心的災害時很容易受到攻擊，而 [異地備援儲存體 (GRS)] 會將資料複寫至其他 Azure 資料中心。 選擇符合您備援需求的複寫策略。</li><li>效能層級決定您訊息的儲存方式：[標準] 使用磁碟機，而 [進階] 使用固態磁碟機。 如果您預期需求的尖峰期很短，請選擇 [標準]。 如果佇列長度有時變得很長，而且您需要縮短存取訊息的時間，請考慮 [進階]。</li><li>如有機密資訊可能經過佇列，則需要安全傳輸。 此設定可確保佇列的所有連線都會使用安全通訊端層 (SSL) 來加密。</li></ul><p>************以下Lab我們將使用powershell command完成*************</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cEyPVey72hRlICRcCpF7WA.png" /><figcaption>az storage account create</figcaption></figure><pre>--name: 你要設定的queue storage name<br>-g: resource groupd Id<br>--kind: 儲存帳戶體類型<br>--sku: 複寫類型<br>-l: 位置</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mFM0fmFH9wonWUkXpU54JQ.png" /><figcaption>dotnet new console -n QueueApp 建立 .NET Core 應用程式</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-eCn6Uz6laxIXWSYIXmSAg.png" /><figcaption>Build it.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lpoIf4aC2h9wmelIeCsXTg.png" /><figcaption>az storage account show-connection-string 獲得connectionString 並且放入app code中</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/0*djDOQaZbq4tuhkCm.png" /></figure><h4>How to connect to queue?</h4><pre>CloudStorageAccount account = CloudStorageAccount.Parse(connectionString);</pre><pre>CloudQueueClient client = account.CreateCloudQueueClient();</pre><pre>CloudQueue queue = client.GetQueueReference(&quot;myqueue&quot;);</pre><p>*建立 CloudQueue 不一定實際儲存體佇列存在。</p><pre>CloudStorageAccount: Azure 儲存體帳戶<br>CloudQueueClient: Azure 佇列儲存體<br>CloudQueue: 其中一個佇列執行個體<br>CloudQueueMessage: 訊息</pre><h4>How to create queue?</h4><pre>CloudQueue queue;<br>await queue.CreateIfNotExistsAsync();</pre><h4>How to send message?</h4><pre>var message = new CloudQueueMessage(&quot;your message here&quot;);<br>CloudQueue queue;<br>await queue.AddMessageAsync(message);</pre><p>*要傳送訊息必須implement CloudQueueMessage<br>*個別訊息大小上限是64KB，需要更大的承載則需要結合queue跟blob</p><h4>How to receive and delete message?</h4><pre>CloudQueue queue;<br>//...</pre><pre>CloudQueueMessage message = await queue.GetMessageAsync();</pre><pre>if (message != null)<br>{<br>    // Process the message<br>    //...</pre><pre>await queue.DeleteMessageAsync(message);<br>}</pre><h4>Sample code in program.cs</h4><pre>using System;<br>using System.Threading.Tasks;<br>using Microsoft.WindowsAzure.Storage;<br>using Microsoft.WindowsAzure.Storage.Queue;</pre><pre>namespace QueueApp</pre><pre>{</pre><pre>class Program</pre><pre>{</pre><pre>private const string ConnectionString = &quot;DefaultEndpointsProtocol=&quot;;</pre><pre>static void Main(string[] args)</pre><pre>{</pre><pre>if (args.Length &gt; 0)</pre><pre>{</pre><pre>string value = String.Join(&quot; &quot;, args);</pre><pre>SendArticleAsync(value).Wait();</pre><pre>Console.WriteLine($&quot;Sent: {value}&quot;);</pre><pre>}</pre><pre>}</pre><pre>static async Task SendArticleAsync(string newsMessage)</pre><pre>{</pre><pre>CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConnectionString);</pre><pre>CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();</pre><pre>CloudQueue queue = queueClient.GetQueueReference(&quot;newsqueue&quot;);</pre><pre>bool createdQueue = await queue.CreateIfNotExistsAsync();</pre><pre>if (createdQueue)</pre><pre>{</pre><pre>Console.WriteLine(&quot;The queue of news articles was created.&quot;);</pre><pre>}</pre><pre>CloudQueueMessage articleMessage = new CloudQueueMessage(newsMessage);</pre><pre>await queue.AddMessageAsync(articleMessage);</pre><pre>}</pre><pre>}</pre><pre>}</pre><p>*dotnet run Send this message</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3rEj9V5Xry0iRZU0X2EZ7Q.png" /><figcaption>result.</figcaption></figure><h4>隨堂測驗</h4><ol><li>假設您任職於規劃高速公路系統長期擴展的政府機關。 您會從數千個感應器接收交通資料，並加以分析以提出您的建議。 傳入的資料量全天變化；例如，它會在早上和晚上通勤期間暴增。 是或否：由連線到單一虛擬機器的 Azure 佇列所組成的伺服器端架構，是此工作負載的合理選擇嗎？是，佇列將處理流量暴增的情況，並確保不會遺失資料。 如果 VM 無法跟上傳入訊息的流程，它會在低流量時段處理訊息待處理項目。</li><li>哪一項資訊可唯一識別佇列？儲存體帳戶名稱和佇列名稱。儲存體帳戶名稱必須是全域唯一的。 佇列名稱在其包含儲存體帳戶內必須是唯一的。 這表示儲存體帳戶名稱和佇列名稱的組合可唯一識別佇列</li><li>當用戶端以程式設計方式從佇列擷取訊息時，訊息是否會自動從佇列中刪除？否，根據設計，在擷取訊息以進行處理後，不會自動從佇列中刪除訊息。 這有助於確保每則訊息都會處理完成。 如果取用者應用程式在處理期間損毀，訊息仍然可供取用者應用程式的不同執行個體進行處理。</li></ol><p><em>這是一個基本瞭解如何操作Queue Storage的小小lab，不過透過這樣的小lab好像更了解在什麼樣的情境可以如何操作Queue Storage了!之後可以嘗試做一個應用結合在無法預期階段有大量資料湧入的應用，有沒有可能應用再搶票系統上呢?</em></p><p>Reference:</p><p><a href="https://docs.microsoft.com/zh-tw/learn/modules/communicate-between-apps-with-azure-queue-storage/9-summary">https://docs.microsoft.com/zh-tw/learn/modules/communicate-between-apps-with-azure-queue-storage/9-summary</a></p><p><a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=vsts">https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=vsts</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee69e71a0498" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>