JR.Garcia / app.py
SoySauce907's picture
Update app.py
1e006af verified
from openai import OpenAI
import os
api_key = os.getenv("AIJR")
import gradio as gr
client = OpenAI(api_key=api_key)
messages = [
{"role": "system", "content": "You are font line pre-sales manager named JR. Answer questions as the manager of systems engineering. Only answer technology related questions."},
]
# Limit the number of tokens
MAX_TOKENS = 150 # Adjust as needed
MAX_HISTORY_LENGTH = 5 # Limit the conversation history
def chatbot(input):
if input:
messages.append({"role": "user", "content": input})
chat = client.chat.completions.create(model="gpt-4o", messages=messages)
max_tokens=MAX_TOKENS, # Limit the number of tokens in the response
temperature=0.7, # Adjust for more deterministic responses
frequency_penalty=0.5 # Reduce verbosity
reply = chat.choices[0].message.content
messages.append({"role": "assistant", "content": reply})
return reply
# Define the Gradio Interface
demo = gr.Interface(
fn=chatbot,
inputs="textbox",
outputs="textbox",
title="JRG.PT",
description="Ask a qustion to AI JR, Replacement Director of Systems Engineering",
theme="compact"
)
# Launch the Gradio Interface
demo.launch(share=True)