Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,13 +20,16 @@ text_generation = pipeline("text-generation", model=model, tokenizer=tokenizer,
|
|
| 20 |
# Wrap the pipeline in a LangChain HuggingFacePipeline
|
| 21 |
llm = HuggingFacePipeline(pipeline=text_generation)
|
| 22 |
|
| 23 |
-
# Initialize the prompt template
|
| 24 |
prompt = ChatPromptTemplate.from_messages([
|
| 25 |
("system", """
|
| 26 |
You are a helpful AI assistant. Your task is to engage in conversation with users,
|
| 27 |
answer their questions, and assist them with various tasks.
|
| 28 |
Communicate politely and maintain focus on the user's needs.
|
| 29 |
Keep responses concise, typically two to three sentences.
|
|
|
|
|
|
|
|
|
|
| 30 |
"""),
|
| 31 |
MessagesPlaceholder(variable_name="history"),
|
| 32 |
("human", "{input}"),
|
|
@@ -98,8 +101,9 @@ def chat_function(input_type, text_input=None, audio_input=None, history=None):
|
|
| 98 |
|
| 99 |
print(f"LLM response: {response}") # Debug information
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
|
|
|
| 103 |
|
| 104 |
# Generate audio for LLM response
|
| 105 |
audio_file = f"response_{uuid.uuid4()}.mp3"
|
|
|
|
| 20 |
# Wrap the pipeline in a LangChain HuggingFacePipeline
|
| 21 |
llm = HuggingFacePipeline(pipeline=text_generation)
|
| 22 |
|
| 23 |
+
# Initialize the prompt template with improved instructions
|
| 24 |
prompt = ChatPromptTemplate.from_messages([
|
| 25 |
("system", """
|
| 26 |
You are a helpful AI assistant. Your task is to engage in conversation with users,
|
| 27 |
answer their questions, and assist them with various tasks.
|
| 28 |
Communicate politely and maintain focus on the user's needs.
|
| 29 |
Keep responses concise, typically two to three sentences.
|
| 30 |
+
Always provide a complete and relevant response to the user's input.
|
| 31 |
+
Do not use generic greetings or incomplete phrases like "Hello?".
|
| 32 |
+
If you don't understand or can't answer, say so clearly and ask for clarification.
|
| 33 |
"""),
|
| 34 |
MessagesPlaceholder(variable_name="history"),
|
| 35 |
("human", "{input}"),
|
|
|
|
| 101 |
|
| 102 |
print(f"LLM response: {response}") # Debug information
|
| 103 |
|
| 104 |
+
# Post-process the response
|
| 105 |
+
if not response or not response.strip() or len(response.split()) < 3:
|
| 106 |
+
response = "I apologize, but I couldn't generate a meaningful response. Could you please rephrase your question or provide more context?"
|
| 107 |
|
| 108 |
# Generate audio for LLM response
|
| 109 |
audio_file = f"response_{uuid.uuid4()}.mp3"
|