Spaces:
Paused
Paused
Update generate_answer.py
Browse files- generate_answer.py +2 -2
generate_answer.py
CHANGED
|
@@ -13,13 +13,13 @@ tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct", tr
|
|
| 13 |
|
| 14 |
|
| 15 |
def generate_answer(question):
|
| 16 |
-
prompt_template = PromptTemplate(template="Answer the following question within
|
| 17 |
input_variables=["question"], output_variables=["answer"])
|
| 18 |
# Model loading
|
| 19 |
format_prompt = prompt_template.format(question=question)
|
| 20 |
encoded_input = tokenizer(format_prompt, return_tensors='pt')
|
| 21 |
# Run the model
|
| 22 |
-
output = model.generate(**encoded_input, max_length=
|
| 23 |
# Decode the model output to text
|
| 24 |
decoded_output = tokenizer.decode(output[0])
|
| 25 |
# response_text = decoded_output.split('\n\n', 1)
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
def generate_answer(question):
|
| 16 |
+
prompt_template = PromptTemplate(template="Answer the following question within 1000 words: {question}",
|
| 17 |
input_variables=["question"], output_variables=["answer"])
|
| 18 |
# Model loading
|
| 19 |
format_prompt = prompt_template.format(question=question)
|
| 20 |
encoded_input = tokenizer(format_prompt, return_tensors='pt')
|
| 21 |
# Run the model
|
| 22 |
+
output = model.generate(**encoded_input, max_length=4000) # Use generate method for text generation
|
| 23 |
# Decode the model output to text
|
| 24 |
decoded_output = tokenizer.decode(output[0])
|
| 25 |
# response_text = decoded_output.split('\n\n', 1)
|