Docs
Sentiment

Sentiment

This feature is in beta. Please email us at sounho@weavel.ai to gain access.

Use to determine the sentiment (positive, negative, or neutral) of a conversation.

Start by enabling the Sentiment API in the Weavel dashboard (for instructions, visit overview). A unique endpoint ID will be generated for you to use in the API request.

POST https://api.weavel.ai/extract/:endpoint_id

Send a request

To send the request, add:

context (required): A list of up to 3 context messages. Each should be a JSON with a role (user or assistant) and content.

[
  { "role": "assistant", "content": "hello there" },
  { "role": "user", "content": "hi" },
  { "role": "assistant", "content": "how are you doing?" }
]

target_message (required): Sentiment analysis is performed on this message. Should be JSON with a role (user or assistant) and content.

{ "role": "user", "content": "i'm doing good" }

Example Usage

import requests
 
url = 'https://api.weavel.ai/extract/your_endpoint_id'
headers = {
  'accept': 'application/json',
  'Authorization': 'Bearer YOUR_WEAVEL_API_KEY',
  'Content-Type': 'application/json
}
data = {
  # Up to 3 context messages are allowed
  "context": [
    {"role": "assistant", "content": "example context"},
    {"role": "user", "content": "example context"},
    {"role": "assistant", "content": "example context"}
  ]
  # Sentiment analysis is performed on the target message
  "target_message": {"role": "user", "content": "example message"}
}
 
response = requests.post(url, headers=headers, json=data)
 
print(response.json())

Returns

returns a JSON object with the sentiment label (positive, negative, or neutral) and score.

{
  "label": "negative",
  "score": 0.9518851637840271
}

View the API logs

Weavel's APIs are automatically connected to your analytics dashboard for tracking usage and logs.

Check your usage and logs in the Weavel dashboard. For instructions, visit the API Overview (Logs and Usage).