Can anyone help me update this davinci code? :(

Hi there!

Any help would be eternally appreciated!

I’m just working locally so no security issues to be concerned about just yet - but if I update this code to use 3.5 turbo or paste the code provided by 3.5’s playground it won’t work. I’m no expert and I’ve definitely thrown myself in at the deep end. I have picked it apart many times but can’t seem to get anywhere. Thanks for reading!

	<script src=""></script>
        const conversationDiv = document.getElementById("conversation");
        const inputForm = document.getElementById("input-form");
        const userInput = document.getElementById("user-input");

        inputForm.addEventListener("submit", (e) => {
            const message = userInput.value.trim();
            if (message) {
                addMessageToConversation("user", message);
                userInput.value = "";

        function addMessageToConversation(sender, message) {
            const messageDiv = document.createElement("div");
            messageDiv.className = "message";
            messageDiv.innerHTML = `<span class="${sender}">${sender === "user" ? "You" : "ChatGPT"}:</span> ${message}`;
            conversationDiv.scrollTop = conversationDiv.scrollHeight;

        async function sendMessageToGPT(message) {
                    const apiKey = "APIKEY";
                    const apiUrl = "";

                    try {
                        const response = await, {
                            "model": "text-davinci-002",
                            "prompt": message,
                            "temperature": 0.9,
                            "max_tokens": 150,
                            "top_p": 1,
                            "frequency_penalty": 0,
                            "presence_penalty": 0.6,
                            "stop": [" Human:", " AI:"],
                            }, {
                            headers: {
                                'Content-Type': 'application/json',
                                'Authorization': `Bearer ${apiKey}`
                        const data =[0].text.trim();
                        addMessageToConversation("gpt", data);
                    } catch (error) {
                        addMessageToConversation("gpt", "Error: Unable to fetch response, please come back later.");


P.s APIkey removed for this post.

Many thanks!

Don’t tell anybody, but if you click “API reference” at the top or edge of the forum, you can learn all the secrets!

    this URL needs to be updated

  2. prompt": message
    will need to be changed to
    "messages": a list of message arrays (dictionaries/json))

  3. then you might need to make more significant changes to how you create that list of messages, including a system role message that contains bot programming separate from a user message that contains instructions or data.

1 Like

You can also use the new gpt-3.5-turbo-instruct model with your current set-up…

More on endpoint compatability for LLM models