|
<< Click to Display Table of Contents >> Navigation: »No topics above this level« AIG. - AI Google Gemini Integration |
MiniRobotLanguage (MRL)
AIG.Ask
Ask a Text-Based Question to the Google Gemini AI
Intention
Ask Command: Querying the AI with Text
The Ask command enables you to send a text-based question or prompt to the Google Gemini AI, leveraging its natural language understanding to generate a response.
This command is the primary interface for interacting with the AI, making it easy to integrate advanced AI capabilities into your MiniRobotLanguage (MRL) scripts. Whether you need explanations, creative text, or answers to complex queries, AIG.Ask delivers the response directly to your script for further processing.
It’s part of the AIG - Google Gemini API suite, designed to harness Google’s generative AI technology.
The Ask command sends a user-defined text prompt to the Google Gemini API via the AIG_ChatCompletion function, which constructs a JSON payload, makes an HTTP request, and processes the response.
You provide a question or instruction as the first parameter, and optionally specify a variable to store the AI’s response. If no variable is provided, the response is placed on the Top of Stack (TOS). The response is also stored in the AIG_GrokContent global variable for later retrieval using AIG.Get Content.
The command relies on pre-configured settings like the API key (AIG_Key), endpoint (AIG_EndPoint), and model (AIG_Model), which can be customized using other AIG commands.
The Ask command is crucial for:
•Automation: Integrate AI-generated responses into workflows, such as generating text or answering user queries programmatically.
•Interactivity: Create dynamic scripts that respond to user input with AI assistance.
•Versatility: Leverage the Gemini API’s capabilities for tasks like summarization, translation, or question answering.
•Ease of Use: Simplify interaction with a powerful AI model without needing to handle JSON or HTTP requests manually.
To use AIG.Ask, you need a valid API key set via AIG.Set Key and a configured endpoint (default or custom via AIG.Set Endpoint). Then, provide a text prompt as the first parameter.
Optionally, specify a variable to capture the response directly. The response length is capped by AIG_MaxToken (default 2048 tokens, adjustable via AIG.Set MaxToken), and its creativity can be tuned with AIG.Set Temperature and AIG.Set TopP.
Supported Google Gemini models (as of March 19, 2025) include:
•gemini-pro: Text-only, optimized for natural language tasks, 32K context.
•gemini-pro-vision: Multimodal (text and images), 32K context (image support not available in AIG.Ask).
•gemini-1.5-pro: Advanced text generation, 1M context (preview).
•gemini-1.5-flash: Cost-effective, fast responses, 1M context (preview).
Example Usage
AIG.Set Key|your_api_key_here
AIG.Ask|What is the capital of France?|$$ANS
DBP.AI Response: $$ANS
' Alternative: Stack-based retrieval
AIG.Ask|Summarize the history of artificial intelligence
POP.$$SUM
DBP.Summary: $$SUM
These examples demonstrate asking simple and complex questions, with results either stored in a variable or retrieved from the stack.
Illustration
┌──────────────────────┐
│ User Prompt │
├──────────────────────┤
│ "What is AI?" │
└──────────────────────┘
↓
┌──────────────────────┐
│ AI Response │
├──────────────────────┤
│ "Artificial Intelli…"│
└──────────────────────┘
Sending a question to the AI and receiving a response via AIG.Ask.
Syntax
AIG.Ask|P1[|P2]
Parameter Explanation
P1 - (Required) The text prompt or question to send to the AI (e.g., "What is the weather like today?").
P2 - (Optional) The variable where the AI’s response will be stored. If omitted, the response is placed on the Top of Stack (TOS).
Example
' Configure the AI
AIG.Set Key|your_api_key_here
AIG.Set Model|gemini-1.5-flash
AIG.Set MaxToken|500
' Ask a question
AIG.Ask|Translate "Hello World" to German|$$RES
DBP.Translation: $$RES
' Stack-based example
AIG.Ask|What are the benefits of AI?
POP.$$BEN
DBP.Benefits: $$BEN
ENR.
Remarks
- Requires a valid API key and endpoint; otherwise, it returns an error message (e.g., "Error: API key not set").
- The response format defaults to plain text ("text/plain") .
- Responses are limited to 8192 tokens max, configurable down to 1 token.
- Use AIG.Get Content to access the response later if needed.
Limitations
- Only supports text prompts; image-based queries require a different approach (not supported by AIG.Ask).
- Dependent on internet connectivity and Google API availability.
- Response time varies based on model complexity and network latency.
See also: