Spaces:
Runtime error
Runtime error
Update
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ from typing import Iterator
|
|
3 |
import gradio as gr
|
4 |
import torch
|
5 |
|
6 |
-
from model import get_prompt, run
|
7 |
|
8 |
DEFAULT_SYSTEM_PROMPT = """\
|
9 |
You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.
|
@@ -12,7 +12,7 @@ If a question does not make any sense, or is not factually coherent, explain why
|
|
12 |
"""
|
13 |
MAX_MAX_NEW_TOKENS = 2048
|
14 |
DEFAULT_MAX_NEW_TOKENS = 1024
|
15 |
-
|
16 |
|
17 |
DESCRIPTION = """
|
18 |
# Llama-2 7B Chat
|
@@ -87,7 +87,8 @@ def process_example(message: str) -> tuple[str, list[tuple[str, str]]]:
|
|
87 |
|
88 |
def check_prompt_length(message: str, chat_history: list[tuple[str, str]], system_prompt: str) -> None:
|
89 |
prompt = get_prompt(message, chat_history, system_prompt)
|
90 |
-
|
|
|
91 |
raise gr.Error('The accumulated input is too long. Clear your chat history and try again.')
|
92 |
|
93 |
|
|
|
3 |
import gradio as gr
|
4 |
import torch
|
5 |
|
6 |
+
from model import get_prompt, run, tokenizer
|
7 |
|
8 |
DEFAULT_SYSTEM_PROMPT = """\
|
9 |
You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.
|
|
|
12 |
"""
|
13 |
MAX_MAX_NEW_TOKENS = 2048
|
14 |
DEFAULT_MAX_NEW_TOKENS = 1024
|
15 |
+
MAX_INPUT_TOKEN_LENGTH = 4000
|
16 |
|
17 |
DESCRIPTION = """
|
18 |
# Llama-2 7B Chat
|
|
|
87 |
|
88 |
def check_prompt_length(message: str, chat_history: list[tuple[str, str]], system_prompt: str) -> None:
|
89 |
prompt = get_prompt(message, chat_history, system_prompt)
|
90 |
+
input_ids = tokenizer([prompt], return_tensors='np')['input_ids']
|
91 |
+
if input_ids.shape[-1] > MAX_INPUT_TOKEN_LENGTH:
|
92 |
raise gr.Error('The accumulated input is too long. Clear your chat history and try again.')
|
93 |
|
94 |
|