TheFireCo / genkit-plugins

Community Plugins for Genkit (OpenAI, Groq, Anthropic, Cohere, etc)
https://thefireco.github.io/genkit-plugins/
Apache License 2.0
73 stars 5 forks source link

[Cohere] Will throw an obscure error when parsing Tool definitions for complex input schemas #75

Closed MichaelDoyle closed 2 weeks ago

MichaelDoyle commented 1 month ago

Affected plugin(s)

Cohere

Describe the bug The input schema parsing for Cohere currently errors out. It's expecting Zod types, but we have a Record<string, any> instead.

I also suspect there will be problems supporting more complex object types properly with the current implementation. This is somewhat against what Cohere recommends (which is a flat structure), although there is some support for Dict, List and python data objects. If we're not able to support deeply nested objects, there should be an error that properly reflects that.

Error: Unsupported Zod type: String
    at zodTypeToPythonType (/Users/michaeldoyle/repos/thirdparty/genkit-experiments/apps/model-garden/node_modules/.pnpm/genkitx-cohere@0.9.0_@aws-sdk+client-sso-oidc@3.588.0_@genkit-ai+ai@0.5.2_@genkit-ai+core@0.5.2/node_modules/genkitx-cohere/lib/command.js:203:11)
    at toCohereTool (/Users/michaeldoyle/repos/thirdparty/genkit-experiments/apps/model-garden/node_modules/.pnpm/genkitx-cohere@0.9.0_@aws-sdk+client-sso-oidc@3.588.0_@genkit-ai+ai@0.5.2_@genkit-ai+core@0.5.2/node_modules/genkitx-cohere/lib/command.js:210:13)
    at Array.map (<anonymous>)
    at toCohereRequestBody (/Users/michaeldoyle/repos/thirdparty/genkit-experiments/apps/model-garden/node_modules/.pnpm/genkitx-cohere@0.9.0_@aws-sdk+client-sso-oidc@3.588.0_@genkit-ai+ai@0.5.2_@genkit-ai+core@0.5.2/node_modules/genkitx-cohere/lib/command.js:425:55)
    at /Users/michaeldoyle/repos/thirdparty/genkit-experiments/apps/model-garden/node_modules/.pnpm/genkitx-cohere@0.9.0_@aws-sdk+client-sso-oidc@3.588.0_@genkit-ai+ai@0.5.2_@genkit-ai+core@0.5.2/node_modules/genkitx-cohere/lib/command.js:447:20

To Reproduce

Example Tools Schema

defineTool(
  {
    name: 'getStockPrice',
    description: 'Get the price for the given stock ticker.',
    inputSchema: z.object({ symbol: z.string() }),
    outputSchema: z.any(),
  },
  async (input) => {
    // ...
  }
);

Expected behavior Properly parse the schema. :)

Plugin(s) version: 0.9.0

Genkit version: 0.5.2

Dabolus commented 4 weeks ago

I can take a look at it. I'll also add some tests on that part since it's currently uncovered