Context by Cohere

testing code snippet

Share:

 
    const cohere = require('cohere-ai');
    cohere.init('{apiKey}');
    (async () => {
      const response = await cohere.classify('medium', {
        inputs: ["This item broke after 3 weeks"],
        examples: [{"text": "The order came 5 days early", "label": "positive"}, {"text": "The item exceeded my expectations", "label": "positive"}, {"text": "I ordered more for my friends", "label": "positive"}, {"text": "I would buy this again", "label": "positive"}, {"text": "I would recommend this to others", "label": "positive"}, {"text": "The package was damaged", "label": "negative"}, {"text": "The order is 5 days late", "label": "negative"}, {"text": "The order was incorrect", "label": "negative"}, {"text": "I want to return my item", "label": "negative"}, {"text": "The item\'s material feels low quality", "label": "negative"}]
      });
      console.log(`The confidence levels of the labels are ${response.body.classifications}`);
    })();


    import cohere
    from cohere.classify import Example
    co = cohere.Client('{apiKey}')
    classifications = co.classify(
      model='medium',
      inputs=["This item broke after 3 weeks"],
      examples=[Example("The order came 5 days early", "positive"), Example("The item exceeded my expectations", "positive"), Example("I ordered more for my friends", "positive"), Example("I would buy this again", "positive"), Example("I would recommend this to others", "positive"), Example("The package was damaged", "negative"), Example("The order is 5 days late", "negative"), Example("The order was incorrect", "negative"), Example("I want to return my item", "negative"), Example("The item\'s material feels low quality", "negative")])
    print('The confidence levels of the labels are: {}'.format(
       classifications.classifications))


    co model classify medium "This item broke after 3 weeks" --examples="The order came 5 days early"="positive","The item exceeded my expectations"="positive","I ordered more for my friends"="positive","I would buy this again"="positive","I would recommend this to others"="positive","The package was damaged"="negative","The order is 5 days late"="negative","The order was incorrect"="negative","I want to return my item"="negative","The item'\''s material feels low quality"="negative"

Keep reading