#Cannot find module 'openai'

11 messages · Page 1 of 1 (latest)

gleaming spruce
#

I was dealing with a web chatbot project on node.js; then couldn't figure out the files, let me show you all; I need urgent support and in case of contribution I can promote you in the project also individual among 4-5k people.

package-lock-json:

{
  "name": "clade-ai",
  "version": "1.0.0",
  "lockfileVersion": 2,
  "requires": true,
  "dependencies": {
    "form-data": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
      "integrity": "sha512-ZlRtvIW2BxYF9X+CNLl3zPp3qjKYNda1dGOvHsu+gK5rHYxhWnXpA5jXFjDCKPTfJcNTWKNBn2Y1YdvcjyhKA==",
      "requires": {
        "asynckit": "^0.4.0",
        "combined-stream": "^1.0.8",
        "mime-types": "^2.1.12"
      }
    },
    "mime-types": {
      "version": "2.1.32",
      "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.32.tgz",
      "integrity": "sha512-hJGaVS4G4c9TSMYh2n6SQAGrC4RnfU+daP8G7cSCmaqNjiOoUY0VHCMS42pxnQmVF1GWwFhbHWn3RIxCqTmblrA=="
    },
    "openai": {
      "version": "3.2.1",
      "resolved": "https://registry.npmjs.org/openai/-/openai-3.2.1.tgz",
      "integrity": "sha512-7zE2nRFAwH09tgRtrrT7rZYnCJID+V7qf3qFZV7xl/Mfg0YR+KNJrOzUSkVrTgTduOJDb7tnXt+e37tJZdO+fQ==",
      "requires": {
        "axios": "^0.26.0",
        "ws": "^8.5.0"
      }
    },
    "asynckit": {
      "version": "0.4.0",
      "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
      "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
    },
"combined-stream": {
  "version": "1.0.8",
  "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
  "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOQ1TBdJJ/eMqz1bob21XHXQ==",
  "requires": {
    "delayed-stream": "~1.0.0"
  }
},
"delayed-stream": {
  "version": "1.0.0",
  "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
  "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
},
"axios": {
  "version": "0.26.0",
  "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.0.tgz",
  "integrity": "sha512-QPfJR+18nYn1C5NROGHjVfSr8v1NSvHgKpDtbS/eq8JfK9YvzM83HFEFpn+MbKU6gM/FjK1ZHJSJQ+6r1bKjQ==",
  "requires": {
    "follow-redirects": "^1.14.0"
  }
},
"follow-redirects": {
  "version": "1.16.1",
  "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.16.1.tgz",
  "integrity": "sha512-bjKfnoG+1pa53WLuUi3L7c+b5oSxX9I5EouZE5v+JwSAE6AKfD8VUmU6qZoK0PaTfJXgW+oL6HGVBy+tBitb0Q=="
},
    "ws": {
      "version": "8.5.2",
      "resolved": "https://registry.npmjs.org/ws/-/ws-8.5.2.tgz",
      "integrity": "sha512-BT3TIPf4Z4g4F+T8Ys+H4/sltfiqX9EOVJ5DA5+38c5PQkTECHfVJhvMv+1H8YjCJvv1Ugw3dUo3zSCFVncWw==",
      "requires": {
        "async-limiter": "~1.0.0",
        "abbr": "~1.1.0",
        "ws-extensions": "~0.1.0"
      }
    },
    "async-limiter": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz",
      "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxpEqOAIv2ejuvJwemOvNussQ=="
    },
    "ws-extensions": {
      "version": "0.1.5",
      "resolved": "https://registry.npmjs.org/ws-extensions/-/ws-extensions-0.1.5.tgz",
      "integrity": "sha1-/uvMjKfgLRdG1DNK9cT9XjTcObE="
    }
  }
}

Except than this you can find all the files that i might have not seen as a debugging matter at https://replit.com/join/edhmctrigz-plawlostofficia, thank you for all.

#

OTHER FILES:

index.js:

const { OpenAIApi } = require("openai");

// API endpoint
const API_ENDPOINT = "https://api.openai.com/v1/chat/completions";
let apiKey = "";

// Prompt for the AI
let aiPrompt = `You are chatting with Clade AI, an advanced language model created by PlawLabs. Ask me anything!`;

// Store the conversation history
let conversation = [
  {
    role: "system",
    content: aiPrompt,
  },
];

// Function to display a message in the chat log
function displayMessage(role, content) {
  const chatItem = document.createElement("li");
  chatItem.classList.add("chat-item", role);
  chatItem.innerHTML = `<div class="chat-bubble">
      <div class="chat-content">${content}</div>
    </div>
  `;
  chatLog.appendChild(chatItem);
  chatLog.scrollTo(0, chatLog.scrollHeight);
}

// Function to handle a user message submission
async function handleSubmit(event) {
  event.preventDefault();
  const message = input.value;
  if (!message) return;
  displayMessage("user", message);
  chatInput.value = "";
  conversation.push({ role: "user", content: message });
  const headers = {
    "Content-Type": "application/json",
    Authorization: `Bearer ${apiKey}`,
  };
  let body = {
    messages: conversation,
    model: "gpt-3.5-turbo",
    max_tokens: 1040,
    temperature: 0.7,
  };
  try {
    console.log(JSON.parse(JSON.stringify(body)));
    const response = await openai.completions.create({
      engine: "davinci",
      prompt: body.messages[1].content,
      maxTokens: 1040,
      temperature: 0.7,
    });
    if (!response.ok) {
      throw new Error("Failed to get response from API");
    }
    const aiMessage = response.choices[0].text;
    displayMessage("assistant", aiMessage);
    conversation.push({ role: "assistant", content: aiMessage });
  } catch (error) {
    console.error(error);
    displayMessage("system", "Sorry, something went wrong. Please try again later.");
  }
}

// Event listeners
chatForm.onsubmit = handleSubmit;

// Initial message from the AI
displayMessage("system", aiPrompt);

// Additional code for hover effect on the button
chatBtn.addEventListener("mouseenter", () => {
  chatBtn.style.backgroundColor = "white";
  chatBtn.style.color = "black";
});
chatBtn.addEventListener("mouseleave", () => {
  chatBtn.style.backgroundColor = "black";
  chatBtn.style.color = "white";
});
#

package.json:

{
  "name": "clade-ai",
  "version": "1.0.0",
  "description": "A chatbot powered by PlawLabs",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "author": "plawlost",
  "license": "ISC",
  "dependencies": {
    "openai": "^3.2.1"
  }
}
#

public[
index.html:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Clade AI</title>
  <link rel="stylesheet" href="style.css">
  <link rel="icon" href="favicon.png" type="image/png">
</head>

<body>
  <div class="wrapper">
    <header class="header">
      <h1 class="title">Clade AI</h1>
      <p class="subtitle">Your smarter chat partner</p>
    </header>
    <main class="main">
      <div class="chat-window">
        <div class="chat-log">
          <ul id="chatLog"></ul>
        </div>
        <form id="form" class="chat-input">
          <input type="text" id="input" placeholder="Type your message...">
          <button type="submit" id="sendButton">Send</button>
        </form>
      </div>
    </main>
    <footer class="footer">
      <p>&copy; 2023 PlawLabs. All right are reserved.</p>
    </footer>
  </div>

  <script src="https://cdn.jsdelivr.net/npm/@openai/api@0.4.5/dist/openai-api.min.js"></script>
  <script src="index.js"></script>

  <script>
    const sendButton = document.getElementById("sendButton");
    const input = document.getElementById("input");
    sendButton.addEventListener("mouseover", function () {
      console.log("Mouse over on send button!");
    });
  </script>

</body>

</html>

]

#

style.css

@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;700&display=swap');

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  font-family: 'Montserrat', sans-serif;
  height: 100%;
}

body {
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(to bottom, #000000, #003157);
}

.wrapper {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
}

.header {
  text-align: center;
  margin-bottom: 2rem;
}

.header h1 {
  font-size: 3rem;
  font-weight: 700;
  color: #ffffff;
  text-shadow: 2px 2px #1f1f1f;
}

.header p {
  font-size: 1.2rem;
  font-weight: 500;
  color: #aaa;
}

.chat-window {
  background-color: rgba(171, 171, 171, 0.5);
  border-radius: 1rem;
  padding: 1rem;
  max-width: 40rem;
  width: 100%;
  margin-top: 2rem;
  backdrop-filter: blur(10px);
}

.chat-log {
  height: 25rem;
  overflow-y: auto;
}

.chat-log ul {
  list-style: none;
}

.chat-log li {
  display: flex;
  margin-bottom: 1rem;
}

.chat-log li.user .chat-bubble {
  margin-left: auto;
  background-color: #1f9eff;
  color: #fff;
  border-radius: 1rem;
  padding: 0.5rem;
}

.chat-log li.assistant .chat-bubble {
  background-color: #8e4859;
  color: #fff;
  border-radius: 1rem;
  padding: 0.5rem;
}

.chat-input {
  display: flex;
  margin-top: 1rem;
}

.chat-input form {
  display: flex;
  flex: 1;
}

.chat-input input[type="text"] {
  flex: 1;
  padding: 0.5rem;
  border-radius: 0.5rem;
  border: none;
  background-color: #282828;
  color: #fff;
}

.chat-input button[type="submit"] {
  margin-left: 1rem;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  border: none;
  background-color: #1f9eff;
  color: #fff;
}

.footer {
  text-align: center;
  margin-top: 2rem;
  font-size: 1rem;
  color: #aaa;
  position: relative;
  z-index: 1;
}

.footer a {
  color: #fff;
}

/* Gradient animation */
body:before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  background: linear-gradient(to bottom, #000000, #45008a);
  animation: gradient 10s ease infinite;
}

@keyframes gradient {
  0% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0% 50%;
  }
}
#

What I get:

Error: Cannot find module 'openai'
Require stack:
- /home/runner/Clade-1/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/runner/Clade-1/index.js:1:38)
    at Module._compile (internal/modules/cjs/loader.js:999:30)```
#
Error: Cannot find module 'openai'
Require stack:
- /home/runner/Clade-1/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/runner/Clade-1/index.js:1:38)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/home/runner/Clade-1/index.js' ]
}
~/Clade-1$ npm i openai
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!
npm ERR! code EINTEGRITY
npm ERR! sha512-hJGaVS4G4c9TSMYh2n6SQAGrC4RnfU+daP8G7cSCmaqNjiOoUY0VHCMS42pxnQmVF1GWwFhbHWn3RIxCqTmblrA== integrity checksum failed when using sha512: wanted sha512-hJGaVS4G4c9TSMYh2n6SQAGrC4RnfU+daP8G7cSCmaqNjiOoUY0VHCMS42pxnQmVF1GWwFhbHWn3RIxCqTmblrA== but got sha512-hJGaVS4G4c9TSMYh2n6SQAGrC4RnfU+daP8G7cSCmaqNjiOoUY0VHCMS42pxnQmVF1GWwFhbHWn3RIxCqTmZ9A==. (5542 bytes)
npm ERR! code EINTEGRITY
npm ERR! sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOQ1TBdJJ/eMqz1bob21XHXQ== integrity checksum failed when using sha512: wanted sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOQ1TBdJJ/eMqz1bob21XHXQ== but got sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==. (4068 bytes)
npm ERR! code EINTEGRITY
npm ERR! sha512-ZlRtvIW2BxYF9X+CNLl3zPp3qjKYNda1dGOvHsu+gK5rHYxhWnXpA5jXFjDCKPTfJcNTWKNBn2Y1YdvcjyhKA== integrity checksum failed when using sha512: wanted sha512-ZlRtvIW2BxYF9X+CNLl3zPp3qjKYNda1dGOvHsu+gK5rHYxhWnXpA5jXFjDCKPTfJcNTWKNBn2Y1YdvcjyhKA== but got sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==. (10490 bytes)

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2023-03-14T03_26_59_331Z-debug.log
candid dust
#

May I see a screenshot of the catalog of the files

#

I’m sorry but do you have the node_modules folder in this file catalog

#

I don’t html very well but can you try out all your files in the same folder as the node_modules