Search code examples
reactjsnext.jsopenai-api

Problem with openai API integration importing CreateChatCompletionRequestMessage


const [messages, setMessages] = useState<ChatCompletionRequestMessage[]>([]);

Error: Cannot find name 'ChatCompletionRequestMessage'.

I'm a beginner at Web Development and I'm trying to learn by building applications through YouTube tutorials. I've seen that openai has recently been upgraded from v3 to v4 but I couldn't really find a solution to this error.


Solution

  • this should work:

    import { CreateChatCompletionRequestMessage } from "openai/resources/chat";
    

    If there is a major update in packages, you should dive into the node_modules/openai and search for it