gguf版、elyza-japanese-7b-instでチャットモードで会話してみました。(短期記憶あり)
前に投稿したyouri 7b chatとほとんど同じコードになります。
プロンプトの関数の中身が少し違います。
$ pip install llama-cpp-python
~ここからコード~
from llama_cpp import Llama
llm = Llama(model_path="./ELYZA-japanese-Llama-2-7b-instruct-q4_K_M.gguf",verbose=False)
DEFAULT_SYSTEM_PROMPT = """あなたは優秀なAIアシスタントです。質問に答えてください。"""
def get_prompt(message: str, chat_history: list[tuple[str, str]],
system_prompt: str) -> str:
texts = [f'[INST] <<SYS>>\n{system_prompt}\n<</SYS>>\n\n']
do_strip = False
for user_input, response in chat_history:
user_input = user_input.strip() if do_strip else user_input
do_strip = True
texts.append(f'{user_input} [/INST] {response.strip()} [INST] ')
message = message.strip() if do_strip else message
texts.append(f'{message} [/INST]')
return ''.join(texts)
messages = []
while True:
message = input("You: ")
if not message:
break
prompt = get_prompt(message, messages, DEFAULT_SYSTEM_PROMPT)
output = llm.create_completion(
prompt,
temperature=0.7,
max_tokens=400,
repeat_penalty=1.1,
)
print(output["choices"][0]["text"])