Sabbah13's picture
Create openai_requests.py
fa7c624 verified
raw
history blame
No virus
982 Bytes
import os
def get_completion_from_openai(prompt, max_tokens):
url = os.getenv('OPENAI_COMPLETION_URL')
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer " + st.secrets["OPNEAI_TOKEN"],
}
response = requests.post(baseUrl,
json={
"model": os.getenv('OPENAI_MODEL'),
"max_tokens": max_tokens,
"messages": [
{
"role": "user",
"content": prompt
}
]
},
headers=headers,
stream=False,
)
return run_response.json()['choices'][0]['message']['content']