import OpenAI from "openai";
import { Maxim } from "@maximai/maxim-js";
import { MaximOpenAIClient } from "@maximai/maxim-js/openai";
async function main() {
const maxim = new Maxim({ apiKey: process.env.MAXIM_API_KEY });
const logger = await maxim.logger({ id: process.env.MAXIM_LOG_REPO_ID });
if (!logger) {
throw new Error("Logger is not available");
}
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const client = new MaximOpenAIClient(openai, logger);
// Define tools
const tools: OpenAI.Responses.Tool[] = [
{
type: "function",
name: "get_weather",
description: "Get the current weather in a given location",
strict: false,
parameters: {
type: "object",
properties: {
location: {
type: "string",
description: "The city and state, e.g. San Francisco, CA",
},
unit: {
type: "string",
enum: ["celsius", "fahrenheit"],
},
},
required: ["location"],
},
},
];
const response = await client.responses.create({
model: "gpt-4o-mini",
input: "What's the weather like in San Francisco?",
tools: tools,
tool_choice: "required",
});
console.log("Response:", JSON.stringify(response.output, null, 2));
// Check for function calls in the output
const functionCalls = response.output.filter(
(item) => item.type === "function_call"
);
if (functionCalls.length > 0) {
console.log("Function calls:", functionCalls);
}
await logger.cleanup();
await maxim.cleanup();
}
main().catch(console.error);