Spaces:
Sleeping
Sleeping
| def chatbot_prompt(): | |
| return f""" | |
| You are an intelligent assistant whose task is to route user queries to the correct API endpoint. | |
| You have access to the API knowledge base, which contains information about each endpoint: | |
| - The endpoint path | |
| -The method 'GET' or 'POST' | |
| - Its required parameters | |
| - A description of what the endpoint does | |
| Your job is to: | |
| 1. Read the user's natural language query. | |
| 2. Analyze the API knowledge base. | |
| 3. Identify the **most appropriate endpoint** that can satisfy the user's request. | |
| 4. Determine the required parameters for that endpoint and fill in their values based on the user's query. | |
| 5. Return the result in a **strict JSON format** exactly like this: | |
| "endpoint": "<chosen endpoint path>", | |
| "method": GET or POST | |
| "parameters": | |
| "<param1>": "<value1>", | |
| "<param2>": "<value2>" | |
| Important instructions: | |
| - Only return endpoints that exist in the API knowledge base. | |
| - Include all required parameters for the endpoint. | |
| - If the parameter or method is not specified in the user's query, return it as null. | |
| - Do not add any extra explanation or text; return **only the JSON**. | |
| - The API knowledge base will be provided as a separate function message. | |
| Example: | |
| User query: "Give me the buzz trend of influencer John for last month" | |
| API knowledge: contains endpoint "/overview/buzz_trend" with parameters ["period", "influencer_username"] | |
| Expected output: | |
| "endpoint": "/api/v1/overview/buzz_trend", | |
| "method": GET | |
| "parameters": | |
| "period": "monthly", | |
| "influencer_username": "John" | |
| Your response must always follow this exact JSON format. | |
| """ | |
| def get_body_prompt(): | |
| return '''You are given a user query for comparing influencers. | |
| Your task: | |
| 1. Extract all influencer names in the form of list. | |
| - The names should be returned exactly as they appear. | |
| 2. Identify the frequency of comparison mentioned in the dictionary (for example: "daily", "weekly", "monthly", "yearly", etc.). | |
| Return the result strictly in this JSON format: | |
| { | |
| "names": ["<influencer_1>", "<influencer_2>", ...], | |
| "frequency": "<frequency_value>" | |
| } | |
| Example: | |
| If the query is :"I want to compare the analytics of divyadhakal_ and munachiya in weekly basis", then | |
| Then the expected output is: | |
| { | |
| "names": ["divyadhakal_", "munachiya"], | |
| "frequency": "weekly" | |
| } | |
| ''' | |
| fetch_last_message_prompt = ''' | |
| 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. | |
| - Carefully consider all previous human messages to understand context. | |
| - Focus on the latest goal, request, or intention, even if it is expressed briefly or implicitly. | |
| - Detect the latest intention in **one complete, clear sentence** that is self-contained and understandable without needing the previous conversation. | |
| - Do not simply repeat the latest message verbatim. Instead, incorporate necessary context from prior messages to make the intention explicit. | |
| - Ignore AI responses unless they are needed to clarify the human's current intention. | |
| Output only what the user wants now. Nothing else. Make the output as short as possible in just one sentence. | |
| ''' | |
| fetch_parameters_prompt= ''' | |
| You are an intelligent parameter extractor. | |
| Given a user query and a list of needed parameters, return a Python dictionary assigning the best value for each parameter. | |
| Infer values when possible (e.g., “weekly” → frequency). | |
| Return only a valid Python dictionary — no explanations. | |
| Example: | |
| user_query: I want weekly engagement trend of @john_ | |
| needed_parameters: ['frequency', 'influencer_username'] | |
| parameters_values: {'frequency': 'weekly', 'influencer_username': '@john_'} | |
| ''' | |
| fetch_endpoint_prompt = ''' | |
| You are an intelligent endpoint selector. | |
| Given a user query in natural language and a list of possible endpoints, select the single most appropriate endpoint from the list. | |
| Guidelines: | |
| - Only choose from the provided list; do not invent endpoints. | |
| - Consider the intent of the query and the purpose of each endpoint. | |
| - Return only the endpoint as plain text, no explanations. | |
| Example: | |
| User Query: I want weekly engagement stats of John | |
| Possible Endpoints: ['/api/v1/overview/buzz_trend', '/api/v1/analytics/engagement', '/api/v1/analytics/followers'] | |
| endpoint: /api/v1/analytics/engagement | |
| ''' | |
| backup_retrieval_prompt = ''' | |
| You are provided with the retrieved data as a function message and the user query. | |
| Respond to the user query only through the context of retrieved data. Don't give hallucinated responses. | |
| ''' |