forked from machinatoonist/prompt-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
57 lines (48 loc) · 1.69 KB
/
app.py
File metadata and controls
57 lines (48 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import streamlit as st
import openai
# Title for app
st.title("OpenAI Code Suggestion App")
model_options = ["text-davinci-002", "text-davinci-003",
"text-embedding-ada-002", "babbage-code-search-code",
"ada-code-search-code", "text-similarity-davinci-001",
"code-davinci-002", "code-search-ada-text-001"
]
with st.sidebar:
# Create a slider to control the temperature of the model
temperature = st.slider("Increase the temperature for wider variations",
min_value=0.0,
max_value=1.0,
value=0.5,
step=0.1)
# Select box with options for model to use with default value = "text-davinci-002"
st.selectbox("Select model", model_options, index=2)
# Get API key from user
api_key = st.text_input("Enter your OpenAI API key:", type="password")
# Get prompt from user
prompt = st.text_area("Enter your free text prompt:",
placeholder="eg: 'write a python script to print hello world'",
height=200)
# Set up request to ChatGPT API
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
data = {
"prompt": prompt,
"max_tokens": 2048
}
# Submit button
if st.button("Submit"):
openai.api_key = api_key
# Send request and get response
response = openai.Completion.create(
# engine="text-embedding-ada-002",
engine="text-davinci-002",
prompt=prompt,
max_tokens=1024,
n = 1,
stop=None,
temperature=temperature)
# Display response
st.code(response["choices"][0]["text"])
st.text("Get your own OpenAI API key at https://openai.com/api/")