|
| 1 | +#!/bin/python |
| 2 | +import sys, os, datetime |
| 3 | +from common import GptParams |
| 4 | +from low_level_api_chat_cpp import LLaMAInteract |
| 5 | + |
| 6 | +def env_or_def(env, default): |
| 7 | + if (env in os.environ): |
| 8 | + return os.environ[env] |
| 9 | + return default |
| 10 | + |
| 11 | +AI_NAME = env_or_def("AI_NAME", "ChatLLaMa") |
| 12 | +MODEL = env_or_def("MODEL", "./models/llama-13B/ggml-model.bin") |
| 13 | +USER_NAME = env_or_def("USER_NAME", "USER") |
| 14 | +N_PREDICTS = int(env_or_def("N_PREDICTS", "2048")) |
| 15 | +N_THREAD = int(env_or_def("N_THREAD", "8")) |
| 16 | + |
| 17 | +today = datetime.datetime.today() |
| 18 | +DATE_YEAR=today.strftime("%Y") |
| 19 | +DATE_TIME=today.strftime("%H:%M") |
| 20 | + |
| 21 | +prompt=f"""Text transcript of a never ending dialog, where {USER_NAME} interacts with an AI assistant named {AI_NAME}. |
| 22 | +{AI_NAME} is helpful, kind, honest, friendly, good at writing and never fails to answer {USER_NAME}'s requests immediately and with details and precision. |
| 23 | +There are no annotations like (30 seconds passed...) or (to himself), just what {USER_NAME} and {AI_NAME} say aloud to each other. |
| 24 | +The dialog lasts for years, the entirety of it is shared below. It's 10000 pages long. |
| 25 | +The transcript only includes text, it does not include markup like HTML and Markdown. |
| 26 | +
|
| 27 | +{USER_NAME}: Hello, {AI_NAME}! |
| 28 | +{AI_NAME}: Hello {USER_NAME}! How may I help you today? |
| 29 | +{USER_NAME}: What year is it? |
| 30 | +{AI_NAME}: We are in {DATE_YEAR}. |
| 31 | +{USER_NAME}: Please tell me the largest city in Europe. |
| 32 | +{AI_NAME}: The largest city in Europe is Moscow, the capital of Russia. |
| 33 | +{USER_NAME}: What can you tell me about Moscow? |
| 34 | +{AI_NAME}: Moscow, on the Moskva River in western Russia, is the nation's cosmopolitan capital. In its historic core is the Kremlin, a complex that's home to the president and tsarist treasures in the Armoury. Outside its walls is Red Square, Russia’s symbolic center. |
| 35 | +{USER_NAME}: What is a cat? |
| 36 | +{AI_NAME}: A cat is a domestic species of small carnivorous mammal. It is the only domesticated species in the family Felidae. |
| 37 | +{USER_NAME}: How do I pass command line arguments to a Node.js program? |
| 38 | +{AI_NAME}: The arguments are stored in process.argv. |
| 39 | +
|
| 40 | + argv[0] is the path to the Node. js executable. |
| 41 | + argv[1] is the path to the script file. |
| 42 | + argv[2] is the first argument passed to the script. |
| 43 | + argv[3] is the second argument passed to the script and so on. |
| 44 | +{USER_NAME}: Name a color. |
| 45 | +{AI_NAME}: Blue. |
| 46 | +{USER_NAME}: What time is it? |
| 47 | +{AI_NAME}: It is {DATE_TIME}. |
| 48 | +{USER_NAME}:""" + " ".join(sys.argv[1:]) |
| 49 | + |
| 50 | +print("Loading model...") |
| 51 | +params = GptParams( |
| 52 | + n_ctx=2048, |
| 53 | + temp=0.7, |
| 54 | + top_k=40, |
| 55 | + top_p=0.5, |
| 56 | + repeat_last_n=256, |
| 57 | + n_batch=1024, |
| 58 | + repeat_penalty=1.17647, |
| 59 | + model=MODEL, |
| 60 | + n_threads=N_THREAD, |
| 61 | + n_predict=N_PREDICTS, |
| 62 | + use_color=True, |
| 63 | + interactive=True, |
| 64 | + antiprompt=[f"{USER_NAME}:"], |
| 65 | + input_prefix=" ", |
| 66 | + input_suffix=f"{AI_NAME}:", |
| 67 | + prompt=prompt, |
| 68 | +) |
| 69 | + |
| 70 | +with LLaMAInteract(params) as m: |
| 71 | + m.interact() |
0 commit comments