# Can anyone help me update this davinci code? :(

**URL:** <https://community.openai.com/t/can-anyone-help-me-update-this-davinci-code/389710>\
**Category:** API\
**Tags:** gpt-4, gpt-35-turbo, chatgpt, api, text-davinci-002\
**Created:** [September 22, 2023, 7:14pm UTC](https://community.openai.com/t/can-anyone-help-me-update-this-davinci-code/389710 "2023-09-22T19:14:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gordygordy147](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/gordygordy147/32/204932_2.png) [@gordygordy147](https://community.openai.com/u/gordygordy147)\
**Post date:** [September 22, 2023, 7:14pm UTC](https://community.openai.com/t/can-anyone-help-me-update-this-davinci-code/389710/1 "2023-09-22T19:14:54Z")

</div>

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!

```auto
	<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
        const conversationDiv = document.getElementById("conversation");
        const inputForm = document.getElementById("input-form");
        const userInput = document.getElementById("user-input");

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

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

        async function sendMessageToGPT(message) {
                    const apiKey = "APIKEY";
                    const apiUrl = "https://api.openai.com/v1/completions";

                    try {
                        const response = await axios.post(apiUrl, {
                            "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}`
                            }
                        });
                        debugger;
                        const data = response.data.choices[0].text.trim();
                        console.log(data);
                        addMessageToConversation("gpt", data);
                    } catch (error) {
                        console.error(error);
                        addMessageToConversation("gpt", "Error: Unable to fetch response, please come back later.");
                    }
            }

    </script>

```

P.s APIkey removed for this post.

Many thanks!  
G

---

<div class="post-metadata">

**Author:** ![\_j](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/_j/32/766292_2.png) [@\_j](https://community.openai.com/u/_j)\
**Post date:** [September 22, 2023, 7:26pm UTC](https://community.openai.com/t/can-anyone-help-me-update-this-davinci-code/389710/2 "2023-09-22T19:26:27Z")

</div>

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

1. `https://api.openai.com/v1/completions`  
this URL needs to be updated  
`https://api.openai.com/v1/chat/completions`

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.

---

<div class="post-metadata">

**Author:** ![PaulBellow](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/paulbellow/32/597962_2.png) [@PaulBellow](https://community.openai.com/u/PaulBellow)\
**Post date:** [September 22, 2023, 7:32pm UTC](https://community.openai.com/t/can-anyone-help-me-update-this-davinci-code/389710/3 "2023-09-22T19:32:46Z")

</div>

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

More on [endpoint compatability for LLM models](https://platform.openai.com/docs/models/model-endpoint-compatibility)…
