loog

text-generation-webui を試す

January 26, 2024

https://github.com/oobabooga/text-generation-webui

インストールと起動

実に簡単です。

$ git clone https://github.com/oobabooga/text-generation-webui
$ cd text-generation-webui
$ ./start_linux.sh

GPUの種類を聞かれるので A:Nvidia と答えました。
勝手に起動します。

起動オプションをつけて起動

外部からのアクセスを許可し、USER/PW 認証を入れて、

--trust-remote-code | Set trust_remote_code=True while loading the model. Necessary for some models.

に対応させます。

./start_linux.sh --trust-remote-code --listen --gradio-auth _USER_NAME_:_PW_

モデルのダウンロード

ダウンロードようのスクリプトがあるので、使用しました。

$ python3 download-model.py https://huggingface.co/mmnga/ELYZA-japanese-Llama-2-13b-fast-instruct-gguf
$ python3 download-model.py https://huggingface.co/stabilityai/stable-code-3b

ダウンロードされた model は ./models に入ります。

起動後

model が選択されていない状態なので、model を選択します。

今回は ELYZA にしました。

ELYZA テスト

質問

python code of counting up from 1 to 100.

回答

for i in range(1,101):
    print(i)

質問

Python code for Scraping a title tag of www.yahoo.co.jp by selenium.

回答

from selenium import webdriver
import time

# ブラウザを開く
driver = webdriver.Chrome()
driver.implicitly_wait(5)

# タイトルタグを取得
title = driver.find_element_by_tag_name('title').text

print(title)

すばらしい!
書ききりました!!

stable-code-3b テスト

Python code for Scraping a title tag of www.yahoo.co.jp by selenium.

#!/usr/bin/env python
import re
from bs4 import BeautifulSoup
import requests
def getTitle():
    url = "https://www.google.com" # Yahoo.co.jp url
    req=requests.get(url).text
    soup=BeautifulSoup(req,'html.parser')
    titleTag = soup.findAll(['h1']) 
    result=' '.join((tag['data-ved'] for tag in titleTag))     # join()関数は引数リストからテキスト値を生成します。
                                    # list内の各要素に対して適用される関数はlambda式であらわされています。        
    return result[:10]                  # 返却値はstring型ですのでslice()メソッドで先頭だけ取得する方法が正しいですね。       
if __name__ == "__main__":           
    try:               
         res=repr(getTitle())      
         print res                    
    except Exception as e:          
         raise RuntimeError("%s\r\n %s")%(Exception,"This Error Occurred!"), sys.exc_info()[2])     

んー、、、Selenium じゃなくて、BeautifulSoup を使用し、また、Yahooの代わりに Google を使用しています。

モデルが小さい割にはすごいと思うけど、やはり、実用には耐えないな。
Prompt を工夫すると精度があがるのだろうか?