Spaces:
Sleeping
Sleeping
Update app/main.py
Browse files- app/main.py +8 -5
app/main.py
CHANGED
@@ -29,16 +29,19 @@ def extract_restext(response, is_chat=False):
|
|
29 |
return response['choices'][0]['text' if is_chat else 'message'].strip()
|
30 |
|
31 |
def ask_llama(llm: Llama, question: str, max_new_tokens=200, temperature=0.5, repeat_penalty=2.0):
|
32 |
-
|
|
|
|
|
|
|
33 |
return result
|
34 |
|
35 |
-
def chat_llama(llm: Llama, chat_history: dict, max_new_tokens=200, temperature=0.5, repeat_penalty=2.0):
|
36 |
-
|
37 |
-
|
38 |
|
39 |
# TESTING THE MODEL
|
40 |
print("Testing model...")
|
41 |
-
assert ask_llama(PHllm,
|
42 |
print("Checking Translators.")
|
43 |
assert t.translate("Hello!") == "สวัสดี!"
|
44 |
assert e.translate("สวัสดี!") == "Hello!"
|
|
|
29 |
return response['choices'][0]['text' if is_chat else 'message'].strip()
|
30 |
|
31 |
def ask_llama(llm: Llama, question: str, max_new_tokens=200, temperature=0.5, repeat_penalty=2.0):
|
32 |
+
prompt = f"""<|begin_of_text|>
|
33 |
+
<|start_header_id|> user <|end_header_id|> {question} <|eot_id|>
|
34 |
+
<|start_header_id|> assistant <|end_header_id|>"""
|
35 |
+
result = extract_restext(llm.complete(prompt, max_tokens=max_new_tokens, temperature=temperature, repeat_penalty=repeat_penalty, stop=["<|eot_id|>", "<|end_of_text|>"])).replace("<|eot_id|>", "").replace("<|end_of_text|>", "")
|
36 |
return result
|
37 |
|
38 |
+
# def chat_llama(llm: Llama, chat_history: dict, max_new_tokens=200, temperature=0.5, repeat_penalty=2.0):
|
39 |
+
# result = extract_restext(llm.create_chat_completion(chat_history, max_tokens=max_new_tokens, temperature=temperature, repeat_penalty=repeat_penalty, stop=["<|eot_id|>", "<|end_of_text|>"]), is_chat=True)
|
40 |
+
# return result
|
41 |
|
42 |
# TESTING THE MODEL
|
43 |
print("Testing model...")
|
44 |
+
assert ask_llama(PHllm, "Hello!, How are you today?", max_new_tokens=5) #Just checking that it can run
|
45 |
print("Checking Translators.")
|
46 |
assert t.translate("Hello!") == "สวัสดี!"
|
47 |
assert e.translate("สวัสดี!") == "Hello!"
|