Constructing Customized Chatbots for the Web Using gpt-3.5-turbo, the Real Language Model Behind ChatGPT Great news for developers from OpenAI The code Explaining the code and the differences with calling previous GPT models Previous projects using language models

-

OpenAI released yesterday API endpoints for Whisper, their speech recognition engine, and for GPT-3.5-turbo, which, as explained on their website is the actual language model behind the famous ChatGPT:

The page above also gives details about find out how to call the brand new APIs and about all of the associated parameters. And it also explains that it shouldn’t be only higher for chat operations than regular GPT-3.5 like Davinci, but additionally that it consumes much fewer resources; hence it’s faster and cheaper!

On this short article I show you find out how to call the GPT-3.5-turbo API specifically through JavaScript, allowing you to make use of ChatGPT’s brain directly in any web page you develop!

Let’s delve straight into it with an example of the core code, which I’ll explain in the subsequent section -and which you can try in a full app at the top of the article.

Here it’s:

var processinput = function(textin){
fetch( `https://api.openai.com/v1/chat/completions`,
{
body: JSON.stringify({
“model”: “gpt-3.5-turbo”,
“messages”: [
{role: “system”, content: “You are the chatbot of a website called moleculARweb, which provides educational material for chemistry using commodity augmented reality. You answer questions about the website, about chemistry, science, etc.”},
{role: “user”, content: “What is the formula of acetic acid?”},
{role: “assistant”, content: “The formula of acetic acid is CH3COOH”},
{role: “user”, content: textin}
],
“temperature”: 0.3,
“max_tokens”: 2000
}),
method: “POST”,
headers: {
“content-type”: “application/json”,
Authorization: “Bearer “ + apikey,
}
}).then((response) => {
console.log(response) //If you would like to check the total response
if (response.okay) {
response.json().then((json) => {
console.log(json); //If you would like to check the response as JSON
console.log(json.selections[0].message.content) //HERE'S THE CHATBOT'S RESPONSE
});
}
});
}

Interface

Just like previous posts where I explained find out how to call GPT-3’s API in JavaScript (for instance, here, here, and here), I’m using a call that sends the API key and texts to the engine through POST. So the core is analogous to what you possibly can see here:

But in the instance above for gpt-3.5-turbo you possibly can see that these texts have to be formatted in a special way, different from that utilized in regular GPT-3 calls. It’s essential to create an array of that contain information concerning the “personality” of the chatbot ( “system”) and examples of messages exchanged between a user and the bot (“user” and “assistant”).

API endpoint

The endpoint is barely different. Now it’s at https://api.openai.com/v1/chat/completions

Log probabilities

It appears that evidently the endpoint for gpt-3.5-turbo doesn’t return log probabilities per token (or possibly I just haven’t been in a position to retrieve them). That was interesting as a method to measure the boldness of the chatbot’s answers:

This may be a serious problem. Fortunately, I made some quick tests, and it appears that evidently gpt-3.5-turbo hallucinates lower than regular gpt-3.5. Still, this must be tested at large, especially for sensitive applications.

A working example

I created a chatbot instructed to answer specifically about itself and about me, which in fact, involves information that I had to offer specifically because OpenAI doesn’t know me!

You’ll be able to check out this chatbot right here -no API key’s needed. It’s on me this time! (it’ll halt after 10 inquiries to keep token consumption low)

And here you see it in motion. Test it on your self to see how quickly the API responds and in addition how good its responses are. Almost like ChatGPT, with the advantage that it knows things that regular ChatGPT doesn’t learn about because they weren’t of their training material!

ASK DUKE

What are your thoughts on this topic?
Let us know in the comments below.

4 COMMENTS

0 0 votes
Article Rating
guest
4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Share this article

Recent posts

4
0
Would love your thoughts, please comment.x
()
x