EasyYI / app.py
PayPeer's picture
Non-optional
e5c16c0
raw
history blame
2.64 kB
import gradio as gr
import gradio_client
from gradio_client import Client
def chat_api_interface(messages, model, frequency_penalty=0, logit_bias=None, max_tokens=None, n=1, presence_penalty=0, response_format="text", seed=None, stop=None, stream=False, temperature=1, top_p=1, tools=None, tool_choice="none", user=None):
# Your API interaction logic goes here
return "API response here"
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
messages = gr.Textbox(label="Messages (JSON format)", placeholder="Enter messages as a JSON array", value="[{\"role\": \"user\", \"content\": \"Hello, how can I help you today?\"}, {\"role\": \"assistant\", \"content\": \"I'm looking for information on renewable energy sources.\"}]")
model = gr.Textbox(label="Model ID", placeholder="Enter the model ID", value="text-davinci-003")
frequency_penalty = gr.Number(label="Frequency Penalty", value=0.5)
logit_bias = gr.Textbox(label="Logit Bias (JSON format)", placeholder="Enter logit bias as JSON", value="{\"50256\": -100, \"50257\": 100}")
max_tokens = gr.Number(label="Max Tokens", value=150)
n = gr.Number(label="N", value=3)
presence_penalty = gr.Number(label="Presence Penalty", value=0.6)
response_format = gr.Radio(label="Response Format", choices=["text", "json_object"], value="text")
seed = gr.Number(label="Seed", optional=True, value=42)
stop = gr.Textbox(label="Stop Sequence(s)", placeholder="Enter stop sequences", value="[\"\\n\", \" end\"]")
stream = gr.Checkbox(label="Stream", value=False)
temperature = gr.Slider(label="Temperature", minimum=0, maximum=2, value=0.7)
top_p = gr.Slider(label="Top P", minimum=0, maximum=1, value=0.9)
tools = gr.Textbox(label="Tools (JSON format)", optional=True, placeholder="Enter tools as JSON", value="{\"spellcheck\": true, \"grammar_check\": false}")
tool_choice = gr.Textbox(label="Tool Choice", value="spellcheck", placeholder="Enter tool choice")
user = gr.Textbox(label="User", optional=True, placeholder="Enter user identifier", value="user123")
with gr.Column():
submit_btn = gr.Button("Submit")
output = gr.Textbox(label="API Response", readonly=True)
submit_btn.click(
chat_api_interface,
inputs=[messages, model, frequency_penalty, logit_bias, max_tokens, n, presence_penalty, response_format, seed, stop, stream, temperature, top_p, tools, tool_choice, user],
outputs=output
)
demo.launch()