Spaces:
Sleeping
Sleeping
Commit
·
ca63886
1
Parent(s):
8827263
Fixed prompt
Browse files
api/routers/analytics_chatbot.py
CHANGED
|
@@ -16,7 +16,6 @@ error_logger = logging.getLogger("error_logger")
|
|
| 16 |
password=os.environ['REDIS_PASSWORD']
|
| 17 |
host = os.environ['REDIS_HOST']
|
| 18 |
port = os.environ['REDIS_PORT']
|
| 19 |
-
print('password:', password)
|
| 20 |
|
| 21 |
router = APIRouter()
|
| 22 |
agent=ChatbotAgent()
|
|
|
|
| 16 |
password=os.environ['REDIS_PASSWORD']
|
| 17 |
host = os.environ['REDIS_HOST']
|
| 18 |
port = os.environ['REDIS_PORT']
|
|
|
|
| 19 |
|
| 20 |
router = APIRouter()
|
| 21 |
agent=ChatbotAgent()
|
src/genai/analytics_chatbot/utils/nodes.py
CHANGED
|
@@ -2,7 +2,7 @@ import requests
|
|
| 2 |
from langchain_core.messages import SystemMessage , HumanMessage , FunctionMessage
|
| 3 |
from .state import State
|
| 4 |
from .tools import RetrieverBackup
|
| 5 |
-
from .schemas import ResponseFormatter , CompareBodyFormatter,
|
| 6 |
from .prompts import chatbot_prompt , get_body_prompt , fetch_last_message_prompt , fetch_parameters_prompt, fetch_endpoint_prompt, backup_retrieval_prompt
|
| 7 |
from .utils import generate_api_knowledge , process_query, get_endpoint_info
|
| 8 |
from src.genai.utils.models_loader import llm_gpt
|
|
@@ -19,12 +19,12 @@ class FetchLastMessage:
|
|
| 19 |
print('Message:',state['messages'])
|
| 20 |
template = fetch_last_message_prompt
|
| 21 |
messages=[SystemMessage(content=template)]+state['messages']
|
| 22 |
-
result = self.llm.
|
| 23 |
-
print('Latest Message:', process_query(result.
|
| 24 |
if len(state['messages'])>11:
|
| 25 |
state["messages"] = state["messages"][-9:]
|
| 26 |
return {
|
| 27 |
-
'latest_message': process_query(result.
|
| 28 |
}
|
| 29 |
|
| 30 |
|
|
|
|
| 2 |
from langchain_core.messages import SystemMessage , HumanMessage , FunctionMessage
|
| 3 |
from .state import State
|
| 4 |
from .tools import RetrieverBackup
|
| 5 |
+
from .schemas import ResponseFormatter , CompareBodyFormatter, ParameterFormatter, EndpointFormatter
|
| 6 |
from .prompts import chatbot_prompt , get_body_prompt , fetch_last_message_prompt , fetch_parameters_prompt, fetch_endpoint_prompt, backup_retrieval_prompt
|
| 7 |
from .utils import generate_api_knowledge , process_query, get_endpoint_info
|
| 8 |
from src.genai.utils.models_loader import llm_gpt
|
|
|
|
| 19 |
print('Message:',state['messages'])
|
| 20 |
template = fetch_last_message_prompt
|
| 21 |
messages=[SystemMessage(content=template)]+state['messages']
|
| 22 |
+
result = self.llm.invoke(messages)
|
| 23 |
+
print('Latest Message:', process_query(result.content))
|
| 24 |
if len(state['messages'])>11:
|
| 25 |
state["messages"] = state["messages"][-9:]
|
| 26 |
return {
|
| 27 |
+
'latest_message': process_query(result.content)
|
| 28 |
}
|
| 29 |
|
| 30 |
|
src/genai/analytics_chatbot/utils/prompts.py
CHANGED
|
@@ -66,13 +66,15 @@ Then the expected output is:
|
|
| 66 |
'''
|
| 67 |
|
| 68 |
fetch_last_message_prompt = '''
|
| 69 |
-
You are an
|
| 70 |
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
|
| 74 |
-
2. Rewrite it as a **complete, grammatically correct sentence**, inferring any missing words, implied subjects, or context from earlier messages.
|
| 75 |
-
3. Return **complete final rewritten user query** as plain text. No explanations, no extra text, no quotes.
|
| 76 |
|
| 77 |
'''
|
| 78 |
|
|
|
|
| 66 |
'''
|
| 67 |
|
| 68 |
fetch_last_message_prompt = '''
|
| 69 |
+
You are an AI assistant that reads an entire conversation between a human and an AI. Your task is to detect the human's most recent intention, taking into account the full conversation history.
|
| 70 |
|
| 71 |
+
- Carefully consider all previous human messages to understand context.
|
| 72 |
+
- Focus on the latest goal, request, or intention, even if it is expressed briefly or implicitly.
|
| 73 |
+
- Detect the latest intention in **one complete, clear sentence** that is self-contained and understandable without needing the previous conversation.
|
| 74 |
+
- Do not simply repeat the latest message verbatim. Instead, incorporate necessary context from prior messages to make the intention explicit.
|
| 75 |
+
- Ignore AI responses unless they are needed to clarify the human's current intention.
|
| 76 |
|
| 77 |
+
Output only what the user wants now. Nothing else. Make the output as short as possible in just one sentence.
|
|
|
|
|
|
|
| 78 |
|
| 79 |
'''
|
| 80 |
|