Skip to main content

Generating AI answers with OpenAI integration through Kuroco API

Overview

Kuroco has built-in integration with OpenAI, which makes it easy to use an AI-powered question-answering systems like ChatGPT. Additionally, Kuroco's API key can be used to start using the service simply by checking the "Enable" checkbox in the OpenAI integration screen, without requiring the user to obtain the API key for OpenAI.

In this tutorial, you will learn how to use Kuroco's API to obtain answers from OpenAI and how to configure the settings to improve the accuracy of the responses.

What You'll Learn

In this tutorial, you will learn how to use Kuroco's API to obtain answers from OpenAI using the following steps:

Integration with OpenAI

Enabling Integration with OpenAI

Click on [External system integration] -> [OpenAI].

Image from Gyazo

Check the "Enable" checkbox and click [Update]. For this tutorial, the API key field can be left blank as we will be using Kuroco's API key.

Image from Gyazo

Create the Endpoint

Click on [Add new endpoint] on the Endpoints page.

Image from Gyazo

Create the following endpoint:

FieldValue
Pathopenai/chat
CategoryAI
ModelOpenAI
Operationchat

Image from Gyazo

Once the settings are configured, click [Add] to create the endpoint.

Retrieve OpenAI's answers from Kuroco's API

When we send a request to OpenAI endpoint with the text parameter, we will receive a response with the answer to the question set in the text parameter.

Click [SwaggerUI] on the API page.
Image from Gyazo

Click [Try it out], enter "Tell me about Kuroco." in the text field as shown below, and click [Execute].

Image from Gyazo

The following answer was returned:

Kuroco is a Japanese manga series written and illustrated by Haruichi Furudate. It follows the story of a group of high school boys who form a volleyball team and compete in various tournaments. The main characters are Hinata Shoyo, Kageyama Tobio, and their teammates. The series focuses on the struggles and triumphs of the team as they strive to become the best volleyball team in Japan. The manga has been adapted into an anime series and a live-action movie.

Image from Gyazo

Improve the accuracy of the answers

With the above settings, you can easily get answers from OpenAI, but the AI's answers are often wrong. Especially for contents that the AI does not know, it predicts and answers, so you need to teach it the information to be used for the answer.

Registering Content for OpenAI to use in advance

Adding Content Definitions

Click [Add] on the Content Structure list screen.
Image from Gyazo

Configure the settings as follows.

ItemSetting
NameContent to be used by OpenAI
Use OpenAIEnabled
ID=1Field Name: Text
Field Settings: Multi-line text
Number of repetitions: 1

Image from Gyazo
Image from Gyazo

After configuring, click [Add] to add the content structure.

Adding Content

Next, we will register the information for OpenAI to use in the content.

Click [Add] on the Content list screen.
Image from Gyazo

Enter the following and click [Add].

ItemValue
TitleWhat is Kuroco?
TextKuroco is a headless CMS provided by Diverta Inc.

Image from Gyazo

After adding the content, open SwaggerUI again and send a request to the endpoint asking "Tell me about Kuroco" again.

You will receive the following response:

Kuroco is a headless CMS designed to help developers quickly build and manage content-driven websites and applications. It provides a simple, intuitive interface that allows developers to easily create and manage content, while also providing powerful tools for customizing and optimizing content delivery. Kuroco supports multiple content types, including text, images, audio, video, and more, and provides a wide range of features for managing content, including versioning, previewing, and scheduling. Additionally, Kuroco offers a variety of integrations with popular services, such as Amazon S3, Dropbox, and Google Drive, to help streamline content management.

Image from Gyazo

Provide instructions for OpenAI's Response

To adjust the wording and content of the response, we need to pass the desired instructions to the prompt parameter when requesting a response from the OpenAI endpoint.

From the endpoint list page, click [Update] on the endpoint created earlier.
Image from Gyazo

Add the following settings and click [Update]:

FieldValue
promptYou are a salesperson at Diverta Inc. Please provide an answer that can lead to a meeting if asked about Kuroco.

Image from Gyazo

Once the settings are completed, the configured instructions can be confirmed on the endpoint list page.
Image from Gyazo

Now, open SwaggerUI again and send a request to the endpoint with the question "Can you tell me about Kuroco?". This time, the following response was obtained:

Absolutely! Kuroco is a revolutionary new platform that helps businesses streamline their sales processes and optimize their customer relationships. It's a powerful tool that can help you save time and money, and I'd love to show you how it works. Would you be interested in scheduling a meeting to discuss it further?

Image from Gyazo

Adjusting temperature

OpenAI's endpoint uses a parameter called temperature to add randomness to the generated responses. A lower temperature generates more precise responses, while a higher temperature generates more diverse and random responses.

Selecting an appropriate temperature value is crucial for improving the accuracy of the response. Generally, it is desirable to choose an intermediate value as a high temperature can lead to unnatural responses, and a low temperature can cause the response to be repetitive. Additionally, the optimal temperature value may differ for specific tasks.

Adjusting top_p

OpenAI's endpoint uses a parameter called top_p during the generation process to add randomness to the generated responses. Specifically, reducing top_p makes the search for referenced content more strict, while increasing top_p generates more diverse and random responses.

To improve the accuracy of the responses, it is important to select an appropriate top-p value. Generally, if the top-p value is too high, the search for content becomes loose, which can lead to unnatural or incorrect responses. On the other hand, if the value is too low, the responses will be highly restricted, generating repetitive responses based on registered content.

Enabling the no_contents_no_answer parameter will cause an error message of not_found to be returned if there is no related content. Please set this parameter if you do not want to allow uncertain responses. Additionally, if you set min_score to a high value, the determination of related content will become more strict, so please set it accordingly.

{
"errors": [
{
"code": "not_found",
"message": "No appropriate content related to the question was found."
}
],
"x-rcms-request-id": "23f3ca66-aa8b-4a34-891c-9c1f958a0eab"
}

By using Kuroco's API, you can easily obtain responses from OpenAI as shown above.

To effectively utilize OpenAI, it is essential to register the information that AI requires accurately and set the prompt appropriately. Also, pay attention to the settings to improve the accuracy of the responses and try implementing the functions using Kuroco and OpenAI.


Support

If you have any other questions, please contact us or check out Our Slack Community.