2 minutes to read - Mar 30, 2023

Cohere tutorial: Q&A chatbot with heart from Cohere

VISIT
Cohere tutorial: Q&A chatbot with heart from Cohere
Cohere provides natural language processing models that help companies improve human-machine interactions. It offers a clear way of understanding the world around us by providing dynamic and contextual information.
Table of Contents
1Cohere
2Prompt
3Streamlit
4Conclusion

In this tutorial, we create the chatbot with cohere as a heart.

Before we have started with coding, you need to create an account on Cohere to get the API key.

Cohere

To use cohere we need to install it

Then we can use cohere in our code. In this tutorial, we use generate method. Entire docs for it you can found here. First, we have to initialize the client, I will also create a class CoHere.

In arguments of Client should be API key, which you have generated before, and version 2021-11-08.

Now, we should create a method to generate a text. We have to select a few arguments of cohere method.

model size of the model

prompt "instructions" for model, we use stevenQa function for it.

max_tokens is the max length of output

temperature is the degree of randomness

More avaiable arguments are here

Prompt

After that, we have to write a prompt for our model. The prompt is instructions and some examples. In brackets {question} will be new question.

Streamlit

Streamlit is a great tool to build a simple web app.

Installation

In this tutorial, we will build an app with two text inputs and a button to display the cohere result.

From docs of streamlit I will take four methods of streamlit

st.header() to make a header on our app

st.test_input() to send a text request

st.button() to create button

st.write() to display the results of cohere model.

To run the streamlit app use command

The created app looks like this

Conclusion

The Cohere models are so powerful, that this tutorial shows only one usage of cohere model. Cohere is also able to embed and classify text. In my mind, there are a lot of ideas on how to use NLP models from cohere.

Article source
loading...