remixreal-jared / app.py
socasanta's picture
Upload folder using huggingface_hub
6058de2 verified
import os
import openai
import gradio as gr
### dotenv
from dotenv import load_dotenv
load_dotenv()
openai.api_key = os.getenv("AZURE_OPENAI_API_KEY")
openai.api_type = "azure"
openai.api_base = os.getenv("AZURE_OPENAI_ENDPOINT")
openai.api_version = os.getenv("AZURE_OPENAI_API_VERSION")
def predict(message, history, system_prompt):
history_openai_format = []
history_openai_format.append({"role": "system", "content": system_prompt})
for human, assistant in history:
history_openai_format.append({"role": "user", "content": human })
history_openai_format.append({"role": "assistant", "content":assistant})
history_openai_format.append({"role": "user", "content": message})
response = openai.ChatCompletion.create(
model='gpt-4-32k',
engine='gpt-4-32k',
messages= history_openai_format,
temperature=0.7,
top_p=0.95,
stream=True
)
partial_message = ""
for chunk in response:
print(chunk)
if len(chunk['choices'][0]['delta']) != 0:
if 'content' in chunk['choices'][0]['delta']:
partial_message = partial_message + chunk['choices'][0]['delta']['content']
yield partial_message
gr.ChatInterface(
predict,
title="J.A.R.E.D",
additional_inputs=[
gr.Textbox("You are an AI assistant that helps people find information. If asked your name, you will introduce yourself as 'JARED'. If asked what 'JARED' means, you will reply 'Jared Assists Richard Every Day.", label="System message")
]).queue().launch(auth=("richard", "Not4Sale1!"))