from opperai import Opper
import time
opper = Opper(http_bearer="YOUR_API_KEY")
# First, create a function to call
unique_name = f"geography_expert_{int(time.time())}"
created_function = opper.functions.create(
name=unique_name,
description="Expert in world geography and capital cities",
instructions="You are a geography expert. Answer questions about countries, capitals, and geography clearly and accurately.",
model="openai/gpt-4o-mini",
)
print(f"Created function with ID: {created_function.id}")
# Call the function with input data
response = opper.functions.call(
function_id=created_function.id,
input={
"question": "What is the capital of France?",
"context": "We are discussing European geography.",
},
tags={"user": "demo_user", "session": "session_123"},
)
print(f"Span ID: {response.span_id}")
if response.message:
print(f"Message: {response.message}")
if response.json_payload:
print(f"JSON Response: {response.json_payload}")
print(f"Cached: {response.cached}")
Copy
Ask AI
{
"span_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"message": "The sum of 1 and 3 is 4",
"json_payload": "<any>",
"cached": true,
"images": [
"image_url"
],
"usage": {
"input_tokens": 25,
"output_tokens": 972,
"output_tokens_details": {
"reasoning_tokens": 704
},
"total_tokens": 997
},
"cost": {
"generation": 0.0001,
"platform": 0.00001,
"total": 0.00011
}
}
from opperai import Opper
import time
opper = Opper(http_bearer="YOUR_API_KEY")
# First, create a function to call
unique_name = f"geography_expert_{int(time.time())}"
created_function = opper.functions.create(
name=unique_name,
description="Expert in world geography and capital cities",
instructions="You are a geography expert. Answer questions about countries, capitals, and geography clearly and accurately.",
model="openai/gpt-4o-mini",
)
print(f"Created function with ID: {created_function.id}")
# Call the function with input data
response = opper.functions.call(
function_id=created_function.id,
input={
"question": "What is the capital of France?",
"context": "We are discussing European geography.",
},
tags={"user": "demo_user", "session": "session_123"},
)
print(f"Span ID: {response.span_id}")
if response.message:
print(f"Message: {response.message}")
if response.json_payload:
print(f"JSON Response: {response.json_payload}")
print(f"Cached: {response.cached}")
Copy
Ask AI
{
"span_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"message": "The sum of 1 and 3 is 4",
"json_payload": "<any>",
"cached": true,
"images": [
"image_url"
],
"usage": {
"input_tokens": 25,
"output_tokens": 972,
"output_tokens_details": {
"reasoning_tokens": 704
},
"total_tokens": 997
},
"cost": {
"generation": 0.0001,
"platform": 0.00001,
"total": 0.00011
}
}
Assistant
Responses are generated using AI and may contain mistakes.