cohere-ai / cohere-python

Python Library for Accessing the Cohere API
https://docs.cohere.ai
MIT License
283 stars 62 forks source link

response_format problem #541

Closed Dexterity104 closed 3 weeks ago

Dexterity104 commented 1 month ago

I want to get a JSON object from Cohere LLM and that's why I'm gonna use response_format. But the error occurs. 3

How can I fix this?

billytrend-cohere commented 1 month ago

@Dexterity104 have you updated to the latest python SDK version? The following snippet works fine for me:

        chat = co.chat(
            message="give me taylor swift details at the time she sung the song '22'",
            response_format={
                "type": "json_object",
                "schema": {
                  "type": "object",
                  "properties": {
                    "name": { "type": "string" },
                    "age": { "type": "integer" }
                  },
                  "required": ["name", "age"]
                }
            }
        )

        print(chat)
        # {\n  "name": "Taylor Swift",\n  "age": 22\n}
abdullahkady commented 1 month ago

Hi @Dexterity104, did upgrading your version fix it as Billy mentioned?

mkozakov commented 3 weeks ago

@Dexterity104 we're going to close the Issue as we cannot reproduce on the latest version of the SDK. please let us know if you're still encountering issues on the latest version and we can reopen.