I am new in python

I am tiring to write a code on “how chatgpt answers a question Using specific Data” but it s not working Thanks for any help .

It looks like constants.py doesn’t contain valid Python code. Did you put just the characters isk-… in that file? If yes, why?

The image you posted shows your secret OpenAI API key. You should consider it compromised. Generate a new key and revoke this one.

3 Likes

constants.py contains the API key

Thanks for the notei didn’t realize that

Your code says constants.APIKEY, which suggests that constants.py should contain:

APIKEY = 'isk...'

but, judging by the traceback, it looks like constants.py contains only the plain text of the API key, the characters isk-....

That’s the point I’m trying to make.

yes your are right it only contains the key characters

APIKEY = "isk-s38YP4
thanks Matthew


still have some errors

Do you know what your code is supposed to do, or did you let an AI write it for you and then wonder why it isn’t working?

It’s expecting something (the query) to be passed as a command-line argument.

FWIW, the real moral of the story is that generally speaking, you shouldn’t be storing your API secret key in a Python code module, importing that and then storing it in an environment variable from within Python—all that needless complexity both led to the original problem you reported, and you compromising your OpenAI secret key for the entire world to see, plus likely a bunch of extra work on your end.

Instead, to avoid all of that, I’d strongly recommend doing as the developers intended and simply properly storing the secret key in the user environment variable yourself (Windows makes this easy via a straightforward GUI), and then everything should just work as intended without all the unessesary complexity around storing it as a constant, loading and setting it in your Python code.

1 Like

Thanks for the tips on API keyi think you’re right about that . . But still having problems’ in line 11 with the query.

I would strongly advise that you put this project aside for now, and make sure to learn the fundamentals of Python first. This includes things like having some familiarity with error messages: being able to read and understand them, have some ideas about common causes, etc. It also includes having the ability to check what happens as the code runs, step by step - either by using a debugger, or by outputting interesting values and comparing them to what you expected (which means you need to expect something specific at each step). It also involves some research skills. For example, if you don’t know what sys.argv[1] means, you can literally copy and paste that into a search engine.

4 Likes

Hi, I can see that you tried following along with the langchain docs to try building a little bot. Despite good documentation or sample code, this is not at all trivial if you also have only just started to learn Python. So, I agree with Karl’s advice: You either need to first learn more basic Python or restrict yourself to complete sample programs provided by langchain.

Basic Python can be learned in just a few days - a week, perhaps two or so. Doing so should make it possible to go back to the langchain samples and start tinkering with them without continuously running into the kind of problems that are tripping you up now.

1 Like