1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

外部流出に怯えないで日本語でジピる

Last updated at Posted at 2023-04-20
  1. https://gpt4all.io/index.html からインストーラを落として導入し
  2. モデル vicuna-13b を取得して
  3. 準備完了、日本語で会話できます

以下すべて削除

  • gpt4all で日本語が不自由ぽかったので前後に翻訳をかませてみた
  • Python3.10

チャットの準備

shell
git clone --recursive https://github.com/nomic-ai/pygpt4all.git
pushd ./pygpt4all/pyllamacpp && sh ./install.sh && popd
curl -LJO https://the-eye.eu/public/AI/models/nomic-ai/gpt4all/gpt4all-lora-quantized-ggml.bin
python pygpt4all/pyllamacpp/llama.cpp/migrate-ggml-2023-03-30-pr613.py gpt4all-lora-quantized-ggml.bin gpt4all-lora-quantized-ggjt.bin

翻訳の準備

shell
pip install argostranslate

チャットと翻訳を組合わせる

interactive.py
from sys import argv

from pyllamacpp.model import Model
import argostranslate.package
import argostranslate.translate


JA_EN = ('ja', 'en')
EN_JA = ('en', 'ja')

def install_package(from_code, to_code):
  # Download and install Argos Translate package
  argostranslate.package.update_package_index()
  available_packages = argostranslate.package.get_available_packages()
  package_to_install = next(
      filter(
          lambda x: x.from_code == from_code and x.to_code == to_code, available_packages
      )
  )
  argostranslate.package.install_from_path(package_to_install.download())

def translate(orignalText, from_code, to_code):
  translatedText = argostranslate.translate.translate(orignalText, from_code, to_code)
  return translatedText

def new_text_callback(text):
    print(text, end="", flush=True)

def translatedPrompt():
  model = Model('/gpt4all-lora-quantized-ggjt.bin', n_ctx=512)
  while True:
    try:
      prompt_ja = input('You: ')
      if prompt_ja == '':
        continue
      prompt_en = translate(prompt_ja, *JA_EN)
      new_text_en = model.generate(prompt_en, n_predict=55, new_text_callback=new_text_callback, n_threads=8)
      new_text_ja = translate(new_text_en, *EN_JA)
      print(f'AI: {new_text_ja}')
    except KeyboardInterrupt:
      break

def main():
  install_package(*JA_EN)
  install_package(*EN_JA)
  translatedPrompt()

if __name__ == '__main__':
  main()

会話をお楽しみください

shell
python ./interactive.py

遅いし賢くない、素直に課金した方が良い

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?