Or AI hackathons apart, maybe you have a chat bot on your website and you want to summarize the conversation between the user and the bot? This tutorial will show you how to do that with Cohere and Python.
And if you want to get started with Cohere, feel free to to go through our cohere guides.
This data often is valuable for the business and can be used for further analysis. A conversation would typically look like this:
With the help of our small program, wecan just summarize the entire conversation in one simple sentence like:
Python 3.6 or higher
Cohere API key
The first step is to install the Cohere Python library. You can do this by running the following command:
The next step is to create a Cohere client. You can do this by running the following code: (You can find your API on the Cohere dashboard)
Next, let's create a response object and call Generate on the Cohere client.
We will choose the model xlarge for this example, and you can find more information about different model sizes on the Cohere website. Next, let's call the prompt and passin two examples of a summarized dialog. So right here you can see the summary of this dialogue at the top. Next, let's pass in our new chat that hasn't been summarized yet. You can see the TLDR is empty. Then let's pass in a few more parameters. You can choose these to your needs. And then let's pass in a stop sequence. This stop sequence tells the AI to stop generating when exactly this sequence is reached. So for example, you can see that the example sequence is always at the end of the summary. At the end, let's print out our prediction.
Now we can check if our program works by executing the Python file. You can use the summarizer to summarize conversations, for example on Slack, Discord, Telegram or Emails.