टास्क ऑर्केस्ट्रेशन

Gemini Robotics ER मॉडल, टास्क की योजना बना सकते हैं और जगह के बारे में जानकारी दे सकते हैं. साथ ही, यह अनुमान लगा सकते हैं कि किसी लक्ष्य को पूरा करने के लिए, कौनसी कार्रवाइयां करनी हैं और किन ऑब्जेक्ट को मूव करना है. इस पेज पर, किसी आइटम को कटोरे में रखने के टास्क को पूरा करने के लिए, कस्टम रोबोट एपीआई की मदद से पिक-ऐंड-प्लेस ऑपरेशन चलाने का उदाहरण दिया गया है.

पूरा कोड देखने के लिए, रोबोटिक्स कुकबुक देखें.

कस्टम रोबोट एपीआई का इस्तेमाल करना

इस उदाहरण में, कस्टम रोबोट एपीआई की मदद से टास्क ऑर्केस्ट्रेशन दिखाया गया है. इसमें, पिक-ऐंड-प्लेस ऑपरेशन के लिए डिज़ाइन किया गया मॉक एपीआई दिखाया गया है. इस टास्क में, नीले रंग के ब्लॉक को उठाकर, नारंगी रंग के कटोरे में रखना है:

ब्लॉक और कटोरे की इमेज

इस उदाहरण में, मॉक रोबोट एपीआई और टूल की इन परिभाषाओं का इस्तेमाल किया गया है:

Python

from google import genai
from google.genai import types

client = genai.Client()

def move(x, y, high):
    print(f"Mock Robot: Moving to coordinates: {x}, {y}, {'high above table' if high else 'down at table level'}")

def setGripperState(opened):
    print(f"Mock Robot: {'Opening gripper' if opened else 'Closing gripper'}")

robot_origin_y = 300
robot_origin_x = 500

move_declaration = types.FunctionDeclaration(
    name="move",
    description="Moves the arm to the given coordinates.",
    parameters=types.Schema(
        type=types.Type.OBJECT,
        properties={
            "x": types.Schema(type=types.Type.INTEGER, description="X coordinate relative to the origin"),
            "y": types.Schema(type=types.Type.INTEGER, description="Y coordinate relative to the origin"),
            "high": types.Schema(type=types.Type.BOOLEAN, description="Set to True to lift the robot arm above the scene. Set to False to place the gripper on the surface."),
        },
        required=["x", "y", "high"],
    ),
)

set_gripper_state_declaration = types.FunctionDeclaration(
    name="setGripperState",
    description="Opens or closes the robot's gripper.",
    parameters=types.Schema(
        type=types.Type.OBJECT,
        properties={
            "opened": types.Schema(type=types.Type.BOOLEAN, description="True opens the gripper, False closes the gripper."),
        },
        required=["opened"],
    ),
)

robot_tools = types.Tool(function_declarations=[move_declaration, set_gripper_state_declaration])

इस उदाहरण में, टूल की परिभाषाओं के साथ प्रॉम्प्ट और इमेज को मॉडल को भेजा जाता है. इसके बाद, एजेंटिक लूप चलता है: मॉडल के हर जवाब के बाद, अनुरोध किए गए फ़ंक्शन कॉल (move, setGripperState) को लागू किया जाता है. इसके बाद, नतीजों को वापस मॉडल को भेजा जाता है. यह प्रोसेस तब तक चलती है, जब तक मॉडल फ़ंक्शन कॉल करना बंद नहीं कर देता या स्टेप की सीमा पूरी नहीं हो जाती.

Python

with open("robot-api-example.png", "rb") as f:
    img_bytes = f.read()

prompt = (
    "You are a robotic arm with six degrees-of-freedom. "
    f"The origin point for calculating the moves is at normalized point y={robot_origin_y}, x={robot_origin_x}. "
    "Use this as the new (0,0) for calculating moves, allowing x and y to be negative.\n\n"
    "Find the blue block and the orange bowl. Calculate their coordinates relative to the origin.\n"
    "Perform a pick and place operation where you pick up the blue block and place it into the orange bowl. "
    "Call the appropriate sequence of functions to complete this operation."
)

contents = [
    types.Content(role="user", parts=[
        types.Part.from_bytes(data=img_bytes, mime_type="image/png"),
        types.Part(text=prompt),
    ])
]

print("\n--- Executing Orchestrated Plan ---")

max_steps = 15  # Safety limit to prevent infinite loops
step_count = 0

# The Agentic Loop
while step_count < max_steps:
    step_count += 1

    response = client.models.generate_content(
        model="gemini-robotics-er-2-preview",
        contents=contents,
        config=types.GenerateContentConfig(
            tools=[robot_tools],
            thinking_config=types.ThinkingConfig(thinking_level="low"),
        ),
    )

    # Add model response to conversation history
    contents.append(response.candidates[0].content)

    # Check for function calls
    function_calls = [part for part in response.candidates[0].content.parts if part.function_call]

    if not function_calls:
        # Model is done calling functions
        print("Sequence complete.")
        print(f"Model Summary: {response.text}")
        break

    # Execute function calls and collect results
    function_response_parts = []
    for part in function_calls:
        fc = part.function_call
        if fc.name == "move":
            move(**fc.args)
        elif fc.name == "setGripperState":
            setGripperState(**fc.args)

        function_response_parts.append(
            types.Part.from_function_response(
                name=fc.name,
                response={"status": "success"},
            )
        )

    # Send function results back to model
    contents.append(types.Content(role="user", parts=function_response_parts))

यहां, प्रॉम्प्ट और मॉक रोबोट एपीआई के आधार पर, मॉडल का संभावित आउटपुट दिखाया गया है. आउटपुट में, रोबोट के फ़ंक्शन कॉल का आउटपुट शामिल होता है. मॉडल ने इन फ़ंक्शन कॉल को एक साथ क्रम से लगाया है.

--- Executing Orchestrated Plan ---
Mock Robot: Opening gripper
Mock Robot: Moving to coordinates: 160, 440, high above table
Mock Robot: Moving to coordinates: 160, 440, down at table level
Mock Robot: Closing gripper
Mock Robot: Moving to coordinates: 160, 440, high above table
Mock Robot: Moving to coordinates: -250, 60, high above table
Mock Robot: Moving to coordinates: -250, 60, down at table level
Mock Robot: Opening gripper
Mock Robot: Moving to coordinates: -250, 60, high above table
Sequence complete.
Model Summary: I have completed the task of picking up the blue block and placing it into the orange bowl.

आगे क्या करना है