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.
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
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 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
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.