from openai import OpenAI
from agentsjson.core.models.auth import BearerAuthConfig, AuthType
from agentsjson.core.models.schema import AgentsJson
from agentsjson import ToolFormat, execute, get_tools
# Convert the API response into tool definitions
agents_json = AgentsJson(**result.json())
tools = get_tools(agents_json, ToolFormat.OPENAI)
# Set up your OpenAI client
client = OpenAI(api_key="<YOUR-OPENAI-API-KEY>")
completion = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "system",
"content": "You are a helpful assistant that completes tasks."
},
{
"role": "user",
"content": query
}
],
tools=tools
)
# Execute the chosen action with authentication
auth = BearerAuthConfig(type=AuthType.BEARER, token="<YOUR-STRIPE-API-KEY>")
execute(agents_json, completion, ToolFormat.OPENAI, auth)