[線上演講筆記] Open-Source AI Projects at UC Berkeley & LMSys: Vicuna and Chatbot Arena

講者資訊

image-20231229105428746

UC Berkeley 的 Wei-Lin Chiang (Winston Chiang) 於 12/29(五) 來陽明交大演講, 主題是有關 Large Language Model (LLM), 尤其是將會提及他們在 UC Berkeley 開發的一個十分知名 LLM – Vicuna. 該LLM今年推出後即已有+500 citations, 超過百萬次下載, 江韋霖是主要作者之一. 歡迎有興趣的老師同學踴躍參與.

時間:112.12.29(五) 10:30-12:00

地點: 陽明交大工程三館 114室

演講者: Wei-Lin Chiang, 江韋霖 (University of California, Berkeley)

演講題目: Open-Source AI Projects at UC Berkeley & LMSys: Vicuna and Chatbot Arena

演講內容

Why Vicuna ?

image-20231229105447713

image-20231229105451665

image-20231229105522393

  • GPT-3 只使用 “Few-Shot” 開始產生其他語言結果。
  • LLM 成果遠遠比 NLP 的成效更好,開始大量投入相關的開發。

image-20231229105717094

  • 一開始 GPT3 只能 complete ,無法達到 Q&A 。

image-20231229105910058

  • 透過 “Instruct-GPT” 讓只會 Complete 的 GPT3 開始能做 Q7A

image-20231229105948247

image-20231229110601205

  • Stanford 做了 Alpaca ,於是 UC Berkeyley 也想做。

image-20231229110710361

  • 七萬筆數據。

image-20231229110926813

image-20231229111404311

  • 價錢便宜一半,資料量級跟 Stanford 差不多。

Vicuna - Demo site

https://chat.lmsys.org/

  • Data 經過清洗

image-20231229112737416

  • Blog 的影響:

    • 500 引用
    • 3M 訪問
    • 看圖的 model 也做了。

Vicuna - Limitation

image-20231229113011081

  • 數學, coding 有限制,回答不好。
  • 後來多拿相關資料去優化。

接下來面對問題:

  • 成功來自於「高質量」的數據 (data)

  • 支出不便宜,但是資料搜集不易。

  • 沒有好的 Evaluation 機制。

  • Benchmark 可能已經被 LLM 看過了。

Chat Area

image-20231229114908831

  • 開放的 ChatGPT (免費)
  • 有許多 model (開源)
  • 學校希望有更多回饋,與相關 RLHF 的資料。
    • 放上所有開源 models
    • 讓使用者評分相關問題,誰回答比較好。
    • 作為資料的搜集。

Onging Effort ?

  • 開始跟 HuggingFace 合作

image-20231229115703592

Q&A

  • LMSyS 是一個學生組織,未來發展方向是做開源 LLM 的 research 。
  • 很多開源模型都是使用外部 hosted (HuggingFace …)

更多參考:

[TIL][Heroku][Golang] 使用 Github Release 來 Deploy 服務到 Heroku

image-20231228233157290

Github Action 上的 CICD - Go Build

經常在教同學要打造自己的 side Project 的時候,要透過 Github 把自己的實際產品的想法表現出來。 其中,很重要的除了「文件的撰寫上」,那麼就會是「CICD」的實踐。


範例程式 Repo:

kkdai/bookmark-makerserver: A IFTTT MakerServer to help you post your tweet to github issue as a bookmark


在 Github Action 上有一個 Golang 基本的 CICD 工具 Golang Build

name: Go

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:

  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4

    - name: Set up Go
      uses: actions/setup-go@v5
      with:
        go-version: 1.21

    - name: Build
      run: go build -v ./...

    - name: Test
      run: go test -v ./...

這個就是 Github Action 提供的基本範本 ,可以讓你在 Pull Request 的時候跟 Merge 之後來跑 Go Build 的相關指令。

image-20231229000236139

Github 上的部署到 Heroku 的設定

這邊也可以參考一下 Heroku 提供的基本設定教學與安裝 Github Action 的方法

name: Deploy

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: akhileshns/[email protected] # This is the action
        with:
          heroku_api_key: $
          heroku_app_name: "YOUR APP's NAME" #Must be unique in Heroku
          heroku_email: "YOUR EMAIL"

image-20231229000801996

原本設定: Merge 到 Master / Main 的時候 Deploy

但是裡面的設定都是 Push Master/Main 得時候才會啟動。這樣子其實有點麻煩,每一次的 Merge 到 Master/Main branch 都會發動部署。會讓像是 Document Update 的 PR 也會發動重複的 Deploy 。

如何改成透過 Github Release 來 Deploy?

這邊如果需要透過 Draft a new release 直接來選擇 deploy 到 Heroku 的話。就需要做以下修改。

name: Deploy

on:
  release:
    types: [created]

透過這個方式,就可以讓 Deploy 變得更加的直覺,

完成版之後的 CICD 流程與未來展望:

  • Pull Request –> Go Build 檢查程式碼可編輯程度。
    • 未來可以考慮加上一些 Test Coverage 工具來做單元測試,甚至是更多相關測試內容。
  • Murged 之後,也是跑 Go Build
    • 未來可以加上一些自動化文件更新的 action
  • Release 之後,就會 Deploy 到 Heroku 。
    • 目前都是 Cloud Services ,如果有多雲平台或是 Dev / Product 不同 cluster 可以分開來。

參考文件

[論文心得] Gemini vs GPT-4V: A Preliminary Comparison and Combination of Vision-Language Models Through Qualitative Cases

論文名稱: Gemini vs GPT-4V: A Preliminary Comparison and Combination of Vision-Language Models Through Qualitative Cases

image-20231228114149669

https://arxiv.org/abs/2312.15011

快速總結

裡面透過之前微軟發表過的論文中的相關測試案例外,本篇論文也加上幾個類別的案例。 tl;dr GPT-4v 比較簡潔中確性高,但是 Gemini-Pro 的敘述比較清楚。 裡面有很多圖片與相關案例,蠻值得一讀。

幾個有趣案例

當個偵探

都有看出幾個相關的點,蠻適合拿來做一些 side-project 。 :p

image-20231228114214976

判斷鞋子的品牌

有判斷出 NIKE Air Force 1 我覺得蠻厲害的。

image-20231228114301430

讀論文第一頁圖片

成效不錯,如果沒有 arxiv 的資訊可以抽取。這會是一個方法。

image-20231228114621106

[年終回顧] 2023 年的回顧與展望

2023 年度回顧

做一張人在回顧許多記憶的圖片,寫實風格,有著AI機器人對話,英國旅行,父母與小學女兒一起出去玩的圖片。

懶人包

今年最令人懷念的就是:

  • 八月的時候,來了一趟去英國跟法國的旅遊。
  • 因為去年 LLM 大爆發,今年有幸可以參加一堆好玩的專案與內部訓練。 (共有 28 個 new Repositories)

到了這個年紀,可以從事自己喜愛的工作,家人開心在一起,還有健康身體,真的很重要。

數據總結

image-20231226210639947

image-20231226210713001

  • 總共讀完: 2418 分鐘, 14 本書 (有 1 本其他平台)

    • 2022: 24 本書。
  • 部落格文章撰寫上:

    • 2023: 59 篇文章
    • 2022: 53 篇文章
  • 健身運動:
    • 2023: 3595 mins
    • 2022: 3966 mins
  • Github Contribution 上面:
    • 2023: 1062
    • 2022: 828
  • 因為 LLM 今年有許多專案: (共有 28 個 new Repositories)

  • 聚會方面, 2023 比較解禁今年也比較有機會看到更多老朋友:
  • 4 月可以跟東吳大學同學們聚餐。
  • 12 月跟 Corel 的老朋友見面。

image-20231226213125460

雜項數字

image-20231226213208547

image-20231226213211321

image-20231226213307846

image-20231226213829531

[Golang] 使用 Golang 透過 Google Gemini Pro 來打造一個具有LLM 功能 LINE Bot (一): Chat Completion and Image Vision

image-20231216015206933

前提

上一次開始使用 tmc/langchaingo 打造一些基礎的 Golang 應用後,就在 12 月 13 號 Google 正式公開了 Gemini Pro 的相關 API 。本篇文章開始以下的事項:

  • Google Gemini Pro 有哪些資源可以學習?
  • 如何整合到 LINE Bot?
  • 打造一個回覆,圖片辨識的 Gemini Pro LINE Bot

系列文章:

  1. 使用 Golang 透過 Google Gemini Pro 來打造一個具有LLM 功能 LINE Bot (一): Chat Completion and Image Vision(本篇)
  2. 使用 Golang 透過 Google Gemini Pro 來打造一個具有LLM 功能 LINE Bot (二): 使用 Chat Session 與 LINEBot 快速整合出有記憶的 LINE Bot
  3. 使用 Golang 透過 Google Gemini Pro 來打造一個具有LLM 功能 LINE Bot (三): 使用 Gemini-Pro-Vision 來打造名片管理的聊天機器人

Google Gemini Pro 有哪些資源可以學習

image-20231216014823886

雖然才正式公佈不久,但是網路上其實有不少資源可以學習。我這邊列出一些資源: (直接問 Gemini Pro 出來的)

image-20231216015049307

這裡也有一些我覺得蠻重要的資訊:

如何取得 Google Gemini Pro - API Keys

到 Google AI Studio : https://makersuite.google.com/app/apikey

image-20231216015529412

目前價位如下,還有一些免費額度可以用:

Image

如何整合 LINE Bot?

程式碼: https://github.com/kkdai/linebot-gemini-pro

這邊主要先整入兩個主要功能 : ChatSession 跟 Image ,相關程式碼都在 gemini.go

Chat Completion

// Gemini Chat Complete: Iput a prompt and get the response string.
func GeminiChatComplete(req string) string {
	ctx := context.Background()
	client, err := genai.NewClient(ctx, option.WithAPIKey(geminiKey))
	if err != nil {
		log.Fatal(err)
	}
	defer client.Close()
	model := client.GenerativeModel("gemini-pro")
	cs := model.StartChat()

	send := func(msg string) *genai.GenerateContentResponse {
		fmt.Printf("== Me: %s\n== Model:\n", msg)
		res, err := cs.SendMessage(ctx, genai.Text(msg))
		if err != nil {
			log.Fatal(err)
		}
		return res
	}

	res := send(req)
	return printResponse(res)
}

這個主要是處理一個 Chat Session ,就是類似 OpenAI 的 Chat Completion。 加強解釋一些東西:

  • 回傳資料 res := send(req) 其中的 res 不能直接用,需要透過 printResponse(res) 拿回來。

其實也就是拿出最接近的那個答案中的本文:

func printResponse(resp *genai.GenerateContentResponse) string {
	var ret string
	for _, cand := range resp.Candidates {
		for _, part := range cand.Content.Parts {
			ret = ret + fmt.Sprintf("%v", part)
			fmt.Println(part)
		}
	}
	fmt.Println("---")
	return ret + "\n---"
}

Gemini Pro Vision / 圖片相關 API

func GeminiImage(imgData []byte) (string, error) {
	ctx := context.Background()
	client, err := genai.NewClient(ctx, option.WithAPIKey(geminiKey))
	if err != nil {
		log.Fatal(err)
	}
	defer client.Close()

	model := client.GenerativeModel("gemini-pro-vision")
	prompt := []genai.Part{
		genai.ImageData("png", imgData),
		genai.Text("Describe this image with scientific detail, reply in zh-TW:"),
	}
	log.Println("Begin processing image...")
	resp, err := model.GenerateContent(ctx, prompt...)
	log.Println("Finished processing image...", resp)
	if err != nil {
		log.Fatal(err)
		return "", err
	}

	return printResponse(resp), nil
}

幾件事情要注意:

  • model 不一樣,放錯會出事情: "gemini-pro-vision"
  • 資料一定要指定副檔名,超怪。 不過我都放 "png" 就過了。

快速部署

不想學那麼多,就準備好以下資料,就按下 Deploy

  • ChannelAccessToken
  • ChannelSecret
  • GOOGLE_GEMINI_API_KEY

成果與 Google Gemini Pro API 的一些特點:

1. 資料時效相當的新

image-20231216022242789

image-20231216022248154

時效蠻新的,很多資料都是 2023/07 之後。ChatGPT 這種就回答不出來。

  • ChatGPT GPT 3.5 是 2022
  • API GPT4 是 2023/04

image-20231216015049307

  • 像是以上的內容,因為許多資料都有 link 可以使用,貼到 LINE Bot 沒有太多問題。
  • 不過因為直接回 Markdown 可能要把相關語法刪除掉,才能正確顯示。
  • 這裡註解一下,因為 Gemini Pro 的 temperature 預設是 0.9 (refer)

接下來:

可以開始來玩玩 Function Calling 儘可能把相關內容試試看。 然後也可以等等 LangChainGo 什麼時後把 Gemini Pro 接起來

# 參考資料:

[Golang] 透過 Ollama 快速架設免費本地端的 ChatGPT,並且寫一個 LangChainGo 的應用

image-20231212012818576

前提

好久沒來寫 Golang 來寫文章了,就想說把之前看過關於 Golang LangChain 相關的文章來敘述一下。以下這篇文章主要參考了 Eli Bendersky 部落格的文章 - [Using Ollama with LangChainGo](https://eli.thegreenplace.net/2023/using-ollama-with-langchaingo/)

這裡也會詳細一點來介紹以下幾個部分:

  • 什麼是 Ollama 能拿來做些什麼?
  • 要如何使用 Ollama ?
  • 如何透過 Golang 連接 Ollama 並且串接 LangChain

接下來就開始吧!

什麼是 Ollama

image-20231211231527061

Ollama 是一個相當方便的工具,以往需要在本地端使用 llama 的話需要有以下的步驟:

  • 到 Meta AI 申請下載 link
  • 透過 LLAMA.cpp 把 LLAMA2 的 model 去轉換過後,讓你在 Mac OSX 上面可以執行並且讀取。 (當然還有做 Quantization, Optimization )
  • 然後執行 LLAMA.cpp 去跑起來 LLAMA 的 model 來跑你需要的功能。

但是使用 Ollama 卻相當的簡單

安裝 Ollama

參考 github 說明

curl https://ollama.ai/install.sh | sh

執行之後,就會下載模型

ollama run llama2

更多其他 Models :

Model Parameters Size Download
Neural Chat 7B 4.1GB ollama run neural-chat
Starling 7B 4.1GB ollama run starling-lm
Mistral 7B 4.1GB ollama run mistral
Llama 2 7B 3.8GB ollama run llama2
Code Llama 7B 3.8GB ollama run codellama
Llama 2 Uncensored 7B 3.8GB ollama run llama2-uncensored
Llama 2 13B 13B 7.3GB ollama run llama2:13b
Llama 2 70B 70B 39GB ollama run llama2:70b
Orca Mini 3B 1.9GB ollama run orca-mini
Vicuna 7B 3.8GB ollama run vicuna
➜  Documents ollama run llama2
pulling manifest
pulling 22f7f8ef5f4c... 100% ▕██████████████████████████████████████████████████████████████████████████████████▏ 3.8 GB
pulling 8c17c2ebb0ea... 100% ▕██████████████████████████████████████████████████████████████████████████████████▏ 7.0 KB
pulling 7c23fb36d801... 100% ▕██████████████████████████████████████████████████████████████████████████████████▏ 4.8 KB
pulling 2e0493f67d0c... 100% ▕██████████████████████████████████████████████████████████████████████████████████▏   59 B
pulling 2759286baa87... 100% ▕██████████████████████████████████████████████████████████████████████████████████▏  105 B
pulling 5407e3188df9... 100% ▕██████████████████████████████████████████████████████████████████████████████████▏  529 B
verifying sha256 digest
writing manifest
removing any unused layers
success

# 寫一首詩,但是他看不太懂:
>>> write me a potry
Sure, I'd be happy to write a short story for you! Can you give me some details on what you would like the story to be about? For example,
is it a romance, a mystery, a sci-fi adventure, or something else entirely? And how long would you like the story to be?


# 用中文問也是可以,但是回答會是英文:
>>> 寫一個笑話給我
Of course! Here's a short humorous story for you:

One day, a man walked into a library and asked the librarian, "Do you have any books on Pavlov's dogs and Schrödinger's cat?"

The librarian replied, "It rings a bell, but I'm not sure if it's here or not."


# 強迫要他回覆中文,看起來還可以:
➜  ollama-go ollama run llama2
>>> 寫一首詩給我,  reply in zh_tw
 Of course, I'd be happy to write a poem for you! Here it is:

紅色的陽光在天上照亮,
顯示出世界的美好。
每一個人都有自己的story,
filled with laughter, tears, and glory.

在沒有你的時候,我們會繁榮;
在你回來的時候,我們會歡喜。
你是我們的家,是我們的心靈伴侶,
不管 WHERE 你去,我們都会等你回來。

I hope you like it! Let me know if you have any requests or preferences for the poem.

透過 API Gateway 呼叫 Ollama

最方便的,架起了 Ollama 之後除了可以透過 ollama 來呼叫,更可以透過 API 來對本地端呼叫。

curl http://localhost:11434/api/generate -d '{
  "model": "llama2",
  "prompt": "very briefly, tell me the difference between a comet and a meteor",
  "stream": false
}'
------
{"model":"llama2","created_at":"2023-12-11T14:41:36.760949Z","response":"\nSure! Here's the difference between a comet and a meteor:\n\nComets are icy bodies that originate from the outer reaches of the solar system. They are composed of dust, ice, and rock, and they have a long, elliptical orbit around the sun. When a comet approaches the inner solar system, the sun's heat causes the comet to release gas and dust, creating a bright tail that can be seen from Earth.\n\nMeteors, on the other hand, are small rocks or pieces of debris that enter Earth's atmosphere. As they travel through the atmosphere, they burn up due to friction with the air, producing a bright streak of light in the sky, commonly known as a shooting star. The remains of the meteoroid can sometimes survive entry into the atmosphere and land on Earth as a meteorite.\n\nSo, while both comets and meteors are objects in space, the key difference is that comets are icy bodies that originate from outside the solar system, while meteors are small rocks or pieces of debris that originate from within the solar system (primarily from asteroids).","done":true,"context":.......}

寫一個簡單的 LangChain 跟 Ollama 的應用

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/tmc/langchaingo/llms"
	"github.com/tmc/langchaingo/llms/ollama"
	"github.com/tmc/langchaingo/schema"
)

func main() {
	llm, err := ollama.NewChat(ollama.WithLLMOptions(ollama.WithModel("llama2")))
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	completion, err := llm.Call(ctx, []schema.ChatMessage{
		schema.SystemChatMessage{Content: "Give a precise answer to the question based on the context. Don't be verbose."},
		schema.HumanChatMessage{Content: "What would be a good company name a company that makes colorful socks? Give me 3 examples."},
	}, llms.WithStreamingFunc(func(ctx context.Context, chunk []byte) error {
		fmt.Print(string(chunk))
		return nil
	}),
	)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(completion)
}

你可以透過 github 找到完整程式碼。