Register to Cohere if you haven't done it already https://dashboard.cohere.ai/register
Before I was creating the nextjs project I was trying out my concept on the Cohere playground. It is a great tool to test out your ideas and get a feeling for the API. You can find it here: https://os.cohere.ai/playground
I was using our repository that is public on GitHub. You can find it here: https://github.com/lablab-ai/nextjs-cohere-boilerplate
You can clone the repository and install all the dependencies with npm or yarn.
Create a new API key for you project on the Cohere dashboard. You can find it here: https://dashboard.cohere.ai/api-keys The created API you need to place into the env file of the project. (Never share your API key with anyone, don't commit it to a public repository!)
Now we will update the index.js file to be able to handle more input than one. I also renamed the states to make it more clear.
Update the fetch request, as we will change the endpoint name and we will send more information.
We will also need to update the frontend as we will have two inputs:
Let's rename the api file to answer.js and update the code.
we will need the question and the companyDate fields from the request body.
We will still use the generate model., but we will change the prompt of course.
First of all, we will show an example of a good prompt and a bad prompt. I am using a short company data text from wikipedia.
First time we are asking about the company and we place the correct answer in the answer field. Second time I am creating a bad question, )not regarding the company). I used the question "How are you?" and placed the answer "This question is not related to the company". This way the model will know how to react on a question that is irrelevant and not covered in the company data text. My prompt is the following:
At the end I am slicing the last part of the response to get the correct answer.
Let's start our application with yarn or npm run dev script.
For a test porpose, I placed a short description about Robert Bosch GmbH from wikipedia:
I asked question regarding the company that the text contain. "What are the main sectors?" Answer: mobility, consumer goods, industrial technology and energy and building technology.
This is correct! The model was able to understand the question and answer it correctly. Of course the prompt can be always finetuned to get better results. Because the model will try to answer everything.
Cohere is a great tool for creating a chatbot. It is easy to use and it is free for a limited number of requests.