Arize-ai / openinference

OpenTelemetry Instrumentation for AI Observability
https://arize-ai.github.io/openinference/
Apache License 2.0
211 stars 32 forks source link

[feature request] capture tool_schema in anthropic requests #1068

Open mikeldking opened 1 week ago

mikeldking commented 1 week ago

see example:

from typing import Any, Dict
from your_client_library import Client  # Replace with actual import

tool_schema = {
    "name": "record_travel_request_attributes",
    "description": "Records the attributes of a travel request",
    "input_schema": {
        "type": "object",
        "properties": {
            "location": {
                "type": "string",
                "description": 'The desired destination location. Use city, state, and country format when possible. If no destination is provided, return "not_stated".',
            },
            "budget_level": {
                "type": "string",
                "enum": ["low", "medium", "high", "not_stated"],
                "description": 'The desired budget level. If no budget level is provided, return "not_stated".',
            },
            "purpose": {
                "type": "string",
                "enum": ["business", "pleasure", "other", "not_stated"],
                "description": 'The purpose of the trip. If no purpose is provided, return "not_stated".',
            },
        },
        "required": ["location", "budget_level", "purpose"],
    },
}

system_message = (
    "You are an assistant that parses and records the attributes of a user's travel request."
)

def extract_raw_travel_request_attributes_string(
    travel_request: str,
    client: Client,
    model: str = "claude-3-5-sonnet-20240620",
) -> str:
    response = client.messages.create(
        model=model,
        max_tokens=1024,
        messages=[
            {"role": "user", "content": travel_request},
        ],
        system=system_message,
        tools=[tool_schema],
        tool_choice={"type": "tool", "name": "record_travel_request_attributes"},
    )
    # Process the response to extract the relevant information
    # This is a placeholder - you'll need to implement the actual extraction logic
    extracted_attributes = process_response(response)
    return extracted_attributes

def process_response(response: Any) -> str:
    # Implement the logic to extract the attributes from the response
    # This is a placeholder function
    pass
mikeldking commented 1 week ago

Related to playground