cohere-ai / cohere-typescript

The Cohere TypeScript SDK
https://docs.cohere.ai
MIT License
117 stars 16 forks source link

`chat` does not work with `documents` parameter #102

Closed d-e-h-i-o closed 8 months ago

d-e-h-i-o commented 8 months ago

I'm using the library with Deno (1.36.4) and calling the chat function with documents produces the following error:

error: Uncaught (in promise) Error: Status code: 400
Body: {
  "message": "invalid request: document at index 0 cannot be empty"
}

This is a reproducible example:

import "https://deno.land/x/xhr@0.1.0/mod.ts"; // this is a XMLHttpRequest polyfill for Deno
import { CohereClient } from "https://esm.sh/cohere-ai@7.2.0";

export const cohere = new CohereClient({
  token: "<token>",
});

const res = await cohere.chat({
  message: "Where do the tallest penguins live?",
  model: "command",
  promptTruncation: "AUTO",
  documents: [
    {
      "title": "Tall penguins",
      "snippet": "Emperor penguins are the tallest."
    },
    {
      "title": "Penguin habitats",
      "snippet": "Emperor penguins only live in Antarctica."
    },
    {
      "title": "What are animals?",
      "snippet": "Animals are different from plants."
    }
  ],
});

Just replace <token> and run with deno run <filename>

billytrend-cohere commented 8 months ago

Thanks @d-e-h-i-o, we're looking into this!

d-e-h-i-o commented 8 months ago

Thanks @d-e-h-i-o, we're looking into this!

Thank you! I also noticed that the types for the documents are wrong (they only contain the field id).

AStox commented 8 months ago

Also running into this in node v21. Any workarounds?

d-e-h-i-o commented 8 months ago

Also running into this in node v21. Any workarounds?

You can make a http request with axios or so, it just a litte more code.

exentrich commented 8 months ago

The documents parameter should accept any key-value pairs, as described in the documentation at https://docs.cohere.com/docs/retrieval-augmented-generation-rag

billytrend-cohere commented 8 months ago

Hey all, thanks for reporting! This issue should be fixed with 7.4.0. Let us know if you have any further problems