cohere-ai / cohere-python

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

I get this error when trying Cohere Example API #464

Closed kurianbenoy closed 5 months ago

kurianbenoy commented 5 months ago

Documentation for Intent classification: https://docs.cohere.com/reference/intent-recognition

Input Import:

import cohere
from cohere.responses.classify import Example

Error:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[12], line 2
      1 import cohere
----> 2 from cohere.responses.classify import Example

ModuleNotFoundError: No module named 'cohere.responses'

Cohere API Responses is not coming correctly. I am using the cohere verison: 5.2.2

billytrend-cohere commented 5 months ago

Hey @kurianbenoy sorry that doc is out of date. I will get it updated. Please see the api docs for up to date snippets! classify should look like:

import cohere
from cohere import ClassifyExample
co = cohere.Client('<<apiKey>>')
examples=[
  ClassifyExample(text="Dermatologists don't like her!", label="Spam"),
  ClassifyExample(text="'Hello, open to this?'", label="Spam"),
  ClassifyExample(text="I need help please wire me $1000 right now", label="Spam"),
  ClassifyExample(text="Nice to know you ;)", label="Spam"),
  ClassifyExample(text="Please help me?", label="Spam"),
  ClassifyExample(text="Your parcel will be delivered today", label="Not spam"),
  ClassifyExample(text="Review changes to our Terms and Conditions", label="Not spam"),
  ClassifyExample(text="Weekly sync notes", label="Not spam"),
  ClassifyExample(text="'Re: Follow up from today's meeting'", label="Not spam"),
  ClassifyExample(text="Pre-read for tomorrow", label="Not spam"),
]
inputs=[
  "Confirm your email address",
  "hey i need u to send some $",
]
response = co.classify(
  inputs=inputs,
  examples=examples,
)
print(response)
lakshyaag commented 4 months ago

Thanks, this helped!