Skip to content

Instantly share code, notes, and snippets.

@ScottCampit
Last active January 9, 2023 05:16
Show Gist options
  • Save ScottCampit/d403c7ef86fdc2fd6b07507b463f1e85 to your computer and use it in GitHub Desktop.
Save ScottCampit/d403c7ef86fdc2fd6b07507b463f1e85 to your computer and use it in GitHub Desktop.
import os
import openai
import streamlit as st
openai.api_key = os.environ["OPENAI_API_KEY"]
def generate_response(prompt:str, temperature:float=0.5, max_tokens:int=1500, engine='davinci'):
response = openai.Completion.create(
engine=engine,
prompt=prompt,
temperature=temperature,
max_tokens=max_tokens,
top_p=1,
frequency_penalty=0.3,
presence_penalty=0.3
)
generated_text = response["choices"][0]["text"]
return generated_text
st.title("Chatbot Assistant")
prompt = st.text_input(label="Enter your message: ")
if prompt:
response = generate_response(prompt)
st.write("Chatbot:", response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment