#Dumb Question (Sorry) Need help with Tutorial on adding my key as a Environment Variable
16 messages · Page 1 of 1 (latest)
Which specific GitHub repo are you trying to implement? Then I’ll be able to tell you
Hello, sio I wasn't even considering using GitHub
I just wanted to start with the simplest prompt like, "Tell me about potatoes."
Like this
import os
import openai
from flask import Flask
app = Flask(name)
os.environ['OPEN_API_KEY'] = 'Key'
openai.api_key = os.getenv('OPEN_API_KEY')
prompt = "Tell me about potatoes step by step."
response = openai.Completion.create(
engine="text-davinci-002",
prompt=prompt,
temperature=0,
)
and then have a print(response)
So for a start, the way you have imported your OPEN_API_KEY is wrong. So there are two ways to do it: the bad way and the good way:
- Bad way:
openapi.api_key="<YOUR_API_KEY>", and this would replace the two lines that you wrote - Good way:
create a file called.env, and in that file just haveOPEN_API_KEY=<YOUR_API_KEY>, without the<>obviously. Then in the main python file, belowimport os, add the following:
from dotenv import load_dotenv
load_dotenv()
You may have to install the package dotenv if you don't have it already. Then, replace the two lines you wrote with:
OPEN_API_KEY=os.environ["OPEN_API_KEY"]
openai.api_key=OPEN_API_KEY
That should solve your problem.
Then what you can do for the rest of your prompt is something like the following:
model_engine = "text-davinci-003"
while True:
prompt = input("Human: ")
completions = openai.Completion.create(
model=model_engine,
prompt=convos,
max_tokens=502,
stop=None,
temperature=0.1,
top_p=1,
frequency_penalty=0.0,
presence_penalty=0.0
)
response = completions["choices"][0]["text"]
print("AI: " + response)
For what you want to do you don't need to bother with using Flask if you just want to interact with it from the console or PyCharm
Thank you so much, Sio! I'm going to try this today. Right now I'm starting with something simple but I do want to move towards a system that reviews chatlogs
but baby steps first
Hey Sio! I've been reading in a .csv file and sending it to OpenAI's API with data.append like data.append(row[1] + ": " + row[2] + ". "). The problem is I'm trying to get it to spit it back to me verbatim. The prompt I'm using is "Display the content of this text to me in the exact same way you received it. \n{text}"
What happens is it only tells me the very last line and that is only of the last row[2]/ I tried bumping up max tokens as well
I think this is a problem with strings actually sorry! Let me fix that first
Ok. I got it to work and I've been trying to get it to count unique hashes in a body of text. Each hash is separated from the rest of the text with a "Hash: " which should make it easy. It doesn't get the right answer. There are 55 total hashes and 32 unique hashes. When I ask, "How many hashes are in the following text? Text: \n{text}. Explain your reasoning step by step." It lists out the hashes in a numbered list along with a sentence of text associated with the hash which is nice but it just stops half way. So for example, it goes all the way up to the 28th hash and then the response stops. It's almost like it quits half way through. Do you know what this might be related to? I set max_tokens to 2000 which should be enough because the .csv only has 448 words in total.