sashabaranov / go-openai

OpenAI ChatGPT, GPT-3, GPT-4, DALL·E, Whisper API wrapper for Go
Apache License 2.0
9.25k stars 1.42k forks source link

i get Error 400 Invalid shema function 'createProject': False is not of type array when i pass the tool that call a function to create a project in chatCompletions #893

Open CelebMunyiri opened 1 week ago

CelebMunyiri commented 1 week ago

Your issue may already be reported! Please search on the issue tracker before creating one.

Describe the bug A clear and concise description of what the bug is. If it's an API-related bug, please provide relevant endpoint(s).

To Reproduce Steps to reproduce the behavior, including any relevant code snippets.

Expected behavior A clear and concise description of what you expected to happen.

Screenshots/Logs If applicable, add screenshots to help explain your problem. For non-graphical issues, please provide any relevant logs or stack traces.

Environment (please complete the following information):

Additional context Add any other context about the problem here.

function createProjectCreationTool() { return { type: "function", function: { name: "createProject", description: "Creates a new project with specified details.", function: createProject, parameters: { type: "object", properties: { projectName: { type: "string", description: "Name of the project" }, department: { type: "string", enum: ["marketing"], description: "Department responsible for the project" }, webOrMobile: { type: "array", items: { type: "string" }, description: "Project platforms (e.g., ['web', 'mobile'])" }, modules: { type: "array", items: { type: "string" }, description: "List of project modules" }, customerName: { type: "string", description: "Name of the customer" }, //leadId: { type: "string", description: "ID of the associated lead", required: false }, expected_start_date: { type: "string", description: "Expected start date in format YYYY-MM-DD", required: false }, expected_completion_date: { type: "string", description: "Expected completion date in format YYYY-MM-DD", required: false }, project_status: { type: "string", description: "Initial status of the project", required: false }, total_value: { type: "string", description: "Total value of the project", required: false }, amount_paid: { type: "string", description: "Amount paid so far", required: false }, amount_due: { type: "string", description: "Amount due for the project", required: false } }, required: [] } } }; }

async function createProject(args) { const { projectName, department = "marketing", // webOrMobile = [],
// modules = [],
customerName, // leadId, expected_start_date, expected_completion_date, project_status = "Pending", total_value, amount_paid, amount_due } = JSON.parse(args);

console.log("ARGS:",args)

// Validate that webOrMobile and modules are arrays
// if (!Array.isArray(webOrMobile)) {
//     throw new Error("Invalid format for 'webOrMobile': Expected an array.");
// }
// if (!Array.isArray(modules)) {
//     throw new Error("Invalid format for 'modules': Expected an array.");
// }

// Step 1: Find the customer by name
const customer = await Customer.findOne({ client_name: customerName });
if (!customer) {
    throw new Error(`Customer with the name "${customerName}" not found.`);
}
console.log("Customer:", customer)

// Step 2: Optionally find the lead by ID if provided
let lead = null;
// if (leadId) {
//     lead = await Lead.findById(leadId);
//     if (!lead) {
//         throw new Error(`Lead with ID "${leadId}" not found.`);
//     }
// }

// Step 3: Create the project object
const newProject = new Project({
    projectName,
    department,
   // webOrMobile,
   // modules,
    customer: customer._id,
    //lead_id: lead?._id,
    expected_start_date,
    expected_completion_date,
    project_status,
    total_value,
    amount_paid,
    amount_due
});

// Step 4: Save the project to the database

await newProject.save();

return {
    message: "Project created successfully.",
    projectId: newProject.projectId,
    projectName: newProject.projectName,
    customer: customerName,
   // leadId: leadId || "Not linked"
};

}