Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -38,10 +38,10 @@ def generate(
|
|
38 |
message: str,
|
39 |
chat_history: list[tuple[str, str]],
|
40 |
system_prompt: str,
|
41 |
-
max_new_tokens: int =
|
42 |
-
temperature: float = 0.
|
43 |
top_p: float = 0.9,
|
44 |
-
top_k: int =
|
45 |
repetition_penalty: float = 1.2,
|
46 |
) -> Iterator[str]:
|
47 |
conversation = []
|
@@ -51,7 +51,17 @@ def generate(
|
|
51 |
conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
|
52 |
conversation.append({"role": "user", "content": message})
|
53 |
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
inputs = tokenizer(chat, return_tensors="pt", add_special_tokens=False).to("cuda")
|
56 |
if len(inputs) > MAX_INPUT_TOKEN_LENGTH:
|
57 |
inputs = inputs[-MAX_INPUT_TOKEN_LENGTH:]
|
|
|
38 |
message: str,
|
39 |
chat_history: list[tuple[str, str]],
|
40 |
system_prompt: str,
|
41 |
+
max_new_tokens: int = 512,
|
42 |
+
temperature: float = 0.2,
|
43 |
top_p: float = 0.9,
|
44 |
+
top_k: int = 10,
|
45 |
repetition_penalty: float = 1.2,
|
46 |
) -> Iterator[str]:
|
47 |
conversation = []
|
|
|
51 |
conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
|
52 |
conversation.append({"role": "user", "content": message})
|
53 |
|
54 |
+
prompt = f"""### Instruction:
|
55 |
+
|
56 |
+
### Task:
|
57 |
+
根据巨杉数据库SequoiaDB的相关问题进行回答。
|
58 |
+
|
59 |
+
### Input:
|
60 |
+
{message}
|
61 |
+
|
62 |
+
### Response:
|
63 |
+
"""
|
64 |
+
chat = tokenizer.apply_chat_template(prompt, tokenize=False)
|
65 |
inputs = tokenizer(chat, return_tensors="pt", add_special_tokens=False).to("cuda")
|
66 |
if len(inputs) > MAX_INPUT_TOKEN_LENGTH:
|
67 |
inputs = inputs[-MAX_INPUT_TOKEN_LENGTH:]
|