Skip to content

Commit

Permalink
fix: anthropic tool nested objects (#568)
Browse files Browse the repository at this point in the history
  • Loading branch information
hughcrt authored Sep 20, 2024
1 parent 2ee2eb0 commit c035de5
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions packages/frontend/components/prompts/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ import Link from "next/link";
import { IconInfoCircle, IconTools } from "@tabler/icons-react";

function convertOpenAIToolsToAnthropic(openAITools) {
function convertProperties(openAIProperties) {
const anthropicProperties = {};

for (const [key, value] of Object.entries(openAIProperties)) {
const anthropicProperty = {
type: value.type,
description: value.description,
};

if (value.type === "object" && value.properties) {
anthropicProperty.properties = convertProperties(value.properties);
anthropicProperty.required = value.required || [];
}

anthropicProperties[key] = anthropicProperty;
}

return anthropicProperties;
}

return openAITools.map((openAITool) => {
const openAIFunction = openAITool.function;

Expand All @@ -40,14 +60,9 @@ function convertOpenAIToolsToAnthropic(openAITools) {
},
};

for (const [key, value] of Object.entries(
anthropicTool.input_schema.properties = convertProperties(
openAIFunction.parameters.properties,
)) {
anthropicTool.input_schema.properties[key] = {
type: value.type,
description: value.description,
};
}
);

return anthropicTool;
});
Expand Down

0 comments on commit c035de5

Please sign in to comment.