docs: update the ask_data_insights docstring

PiperOrigin-RevId: 802362601
This commit is contained in:
Google Team Member
2025-09-02 19:21:04 -07:00
committed by Copybara-Service
parent 219815d2d7
commit aad153322e
@@ -50,8 +50,10 @@ def ask_data_insights(
Args:
project_id (str): The project that the inquiry is performed in.
user_query_with_context (str): The user's question, potentially including
conversation history and system instructions for context.
user_query_with_context (str): The user's original request, enriched with
relevant context from the conversation history. The user's core intent
should be preserved, but context should be added to resolve ambiguities
in follow-up questions.
table_references (List[Dict[str, str]]): A list of dictionaries, each
specifying a BigQuery table to be used as context for the question.
credentials (Credentials): The credentials to use for the request.
@@ -66,13 +68,17 @@ def ask_data_insights(
Example:
A query joining multiple tables, showing the full return structure.
The original question: "Which customer from New York spent the most last
month?"
>>> ask_data_insights(
... project_id="some-project-id",
... user_query_with_context="Which customer from New York spent the
most last month? "
... "Context: The 'customers' table joins with
the 'orders' table "
... "on the 'customer_id' column.",
... user_query_with_context=(
... "Which customer from New York spent the most last month?"
... "Context: The 'customers' table joins with the 'orders' table"
... " on the 'customer_id' column."
... ""
... ),
... table_references=[
... {
... "projectId": "my-gcp-project",
@@ -126,25 +132,20 @@ def ask_data_insights(
ca_url = f"https://geminidataanalytics.googleapis.com/v1alpha/projects/{project_id}/locations/{location}:chat"
instructions = """**INSTRUCTIONS - FOLLOW THESE RULES:**
1. **CONTENT:** Your answer should present the supporting data and then provide a conclusion based on that data.
2. **OUTPUT FORMAT:** Your entire response MUST be in plain text format ONLY.
3. **NO CHARTS:** You are STRICTLY FORBIDDEN from generating any charts, graphs, images, or any other form of visualization.
1. **CONTENT:** Your answer should present the supporting data and then provide a conclusion based on that data, including relevant details and observations where possible.
2. **ANALYSIS DEPTH:** Your analysis must go beyond surface-level observations. Crucially, you must prioritize metrics that measure impact or outcomes over metrics that simply measure volume or raw counts. For open-ended questions, explore the topic from multiple perspectives to provide a holistic view.
3. **OUTPUT FORMAT:** Your entire response MUST be in plain text format ONLY.
4. **NO CHARTS:** You are STRICTLY FORBIDDEN from generating any charts, graphs, images, or any other form of visualization.
"""
final_query_text = f"""
{instructions}
**User Query and Context:**
{user_query_with_context}
"""
ca_payload = {
"project": f"projects/{project_id}",
"messages": [{"userMessage": {"text": final_query_text}}],
"messages": [{"userMessage": {"text": user_query_with_context}}],
"inlineContext": {
"datasourceReferences": {
"bq": {"tableReferences": table_references}
},
"systemInstruction": instructions,
"options": {"chart": {"image": {"noImage": {}}}},
},
}