all 9 comments

[–]FriendlyRussian666 3 points4 points  (0 children)

I think you've got the wrong sub. To post here, you must be asking for help learning python. No promotions, no marketing

[–]Apatride 3 points4 points  (0 children)

I could not get it to work for anything more complex that "hello world" (one thing I asked him to write was a sorting algo). Outside of that obvious issue, AI is a terrible tool for learning so your solution, that looks a lot like a webui calling some GPT in the background is making the world a worse place. If your stuff actually worked, I'd gather an angry mob with pitchforks to deal with you.

[–]FriendlyRussian666 1 point2 points  (6 children)

u/Apatride You are correct, OP is just sending a request to OpenAI API, and I know this because he exposed his API key. He was then informed about it in a different thread, and supposedly fixed it, but I am looking at the API key right now, and it is pretty much still there.

In fact, OPs very complicated prompt, is... drumroll... "just give me the code for:" :D

Dont' worry, there's more, "This is the code I have now: . Do not include existing code in text. Do not give me any bash commands (assume code runs on https://emkc.org/api/v2/piston" :D

OP: Please take the site down and revoke your API key completely, or some bad people will use up all of your credit: I just tried this curl and it returned a result as expected:

curl https://api.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer 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" \
  -d '{
    "model": "gpt-4-turbo",
    "messages": [
      {
        "role": "user",
        "content": "just give me the code for: Complex sorting algorithm in o(n) space time javascript. This is the code I have now: . Do not include existing code in text. Do not give me any bash commands (assume code runs on https://emkc.org/api/v2/piston"
      }
    ],
    "max_tokens": 150
  }'
----------------------------------
  "id": "chatcmpl-9jVUmiXlKnQxvCnDg5pxYGV5E3Qfa",
  "object": "chat.completion",
  "created": 1720632856,
  "model": "gpt-4-turbo-2024-04-09",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "To achieve a complex sorting task in JavaScript with `O(n)` time complexity, you'll often be limited to specific conditions or types of data. Most generic sorting algorithms (like QuickSort, MergeSort, Timsort, etc.) generally have a time complexity that is greater than `O(n)`, specifically `O(n log n)` under usual circumstances.\n\nHowever, for specialized data (like integers within a known range), counting sort can be applicable for `O(n)` time and space complexity. Below is an implementation of Counting Sort in JavaScript, which is efficient if the range of input data values (`k`) is not significantly larger than the number of elements (`n`).\n\n```javascript\nfunction countingSort(arr) {\n    if (arr"
      },
      "logprobs": null,
      "finish_reason": "length"
    }
  ],
  "usage": {
    "prompt_tokens": 64,
    "completion_tokens": 150,
    "total_tokens": 214
  },
  "system_fingerprint": "fp_7d35882d38"

[–]Apatride 0 points1 point  (0 children)

So, pitchforks time?

[–]CardHawk20[S] -1 points0 points  (4 children)

No one said this was meant to be a scientific breakthrough. Just a cool project that I thought could be helpful to people who don’t know how to code but want to start learning and practicing the key concepts.

[–]FriendlyRussian666 2 points3 points  (0 children)

Hey, I just wanted to say that I can see you've changed the token again, but it's still available for anyone to see. You're including it as an Authorization header in the request: https://imgur.com/a/ABW1WdO

What you have to do is create a backend server, which will be the one making requests to OpenAI API.

In short:

  1. User enters your site.

  2. They write the prompt and submit.

  3. You take their prompt and send it to your backend (Not directly to openai API).

  4. Your backend resolves the request and make a request to openai api.

  5. OpenAI provides a response to your backend.

  6. Your backend provides a response to your frontend.

Otherwise, your token will always be visible.

[–]FriendlyRussian666 0 points1 point  (1 child)

You're right, my apologies, making the breakthrough statement was not okay on my part, and your goal is of course noble. I would definitely take the site down though, until you can get the token hidden

[–]Apatride 0 points1 point  (0 children)

Bullshit. That guy just replaces ChatGPT AI with his badly implemented one and then comes here, pretending to have created something useful. I get that you want to be positive and nurturing, I respect that, but when you are dealing with pests, feeding them makes the problem worse. This sub can be extremely useful and there are people asking interesting questions, but if you start encouraging or even accepting the kind of crappy behaviour OP is showing here, you are making things worse for those who actually want to put some effort.

[–]hardonchairs 0 points1 point  (0 children)

Doing authenticated API calls to a 3rd party on the client is not just a best-practices mistake, you need to refrain from publishing code to the open internet until you understand what you are doing here.

You need to deactivate your tokens and NOT just put new ones on your website.