0
import openai from "./zggpt";

const query = async (prompt:string,  chatId:string, model:string) => {
    const res= await openai
    .createChatCompletion({
        model,
        prompt,
        temperature: 0.9,
        
        top_p:1,
       
        max_tokens:1000,
        frequency_penalty:0,
        presence_penalty:0,
    })
    .then((res) => res.data.choices[0].text)
    .catch((err)=>
    `ZG was unable to find an answer for that!
     (Error: ${err.message})`
     );
     return res;
};

export default query;

Property 'text' does not exist on type 'CreateChatCompletionResponseChoicesInner'.ts(2339)

Argument of type '{ model: string; prompt: string; temperature: number; top_p: number; max_tokens: number; frequency_penalty: number; presence_penalty: number; }' is not assignable to parameter of type 'CreateChatCompletionRequest'. Object literal may only specify known properties, and 'prompt' does not exist in type 'CreateChatCompletionRequest'.ts(2345)

even though I do everything as in the video, I get these errors.

i'm a beginner in coding, so I'm trying to make applications based on videos to learn.

Thanks

the application responds without returning an error. enter image description here

https://www.youtube.com/watch?v=V6Hq_EX2LLM&t=6293s

Rok Benko
  • 14,265
  • 2
  • 24
  • 49

2 Answers2

1

Problem

You watched a tutorial which used the GPT-3 Completions endpoint (you need to provide the prompt and parameters to get a completion). In this case, this is the function which generates a completion:

openai.createCompletion()

Whereas, you used the code from the tutorial, but used the ChatGPT Completions endpoint (you need to provide the chat message to get a completion). In this case, this is the function which generates a completion:

openai.createChatCompletion()

Solution

So, change this...

openai.createChatCompletion()

...to this.

openai.createCompletion()

Both errors will disappear.

My advice

However, you want to achieve a chat-like bot using a GPT-3 model. At the time the tutorial was recorded, this was the only way to do it. Since 1 March 2023, the gpt-3.5-turbo model is available. I strongly suggest you to use it. See the official OpenAI documentation.

Rok Benko
  • 14,265
  • 2
  • 24
  • 49
0

The answer from Rok is correct, but also in the past 2 days OpenAI has released the ChatGPT model and endpoint.

Ref: https://platform.openai.com/docs/api-reference/chat/create?lang=python

In the Chat endpoint your code would look like this:

import openai;
import os;
openai.api_key = os.getenv("OPENAI_API_KEY");

const query = async (prompt:string,  chatId:string, model:string) => {
    const res= await openai
    .createChatCompletion({
        model:"gpt-3.5-turbo",
        messages:[{"role": "user", "content": prompt}]
    })
    .then((res) => res.choices[0].message)
    .catch((err)=>
    `ZG was unable to find an answer for that!
     (Error: ${err.message})`
     );
     return res;
};

export default query;
Nima Bastani
  • 185
  • 11
Kane Hooper
  • 1,531
  • 1
  • 9
  • 21