增加设置提示词的块
This commit is contained in:
parent
b562723d59
commit
f4fc0a316e
|
@ -99,6 +99,7 @@ def parse_text(text):
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def predict(history, max_length, top_p, temperature):
|
def predict(history, max_length, top_p, temperature):
|
||||||
stop = StopOnTokens()
|
stop = StopOnTokens()
|
||||||
messages = []
|
messages = []
|
||||||
|
@ -140,11 +141,14 @@ with gr.Blocks() as demo:
|
||||||
chatbot = gr.Chatbot()
|
chatbot = gr.Chatbot()
|
||||||
|
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
with gr.Column(scale=4):
|
with gr.Column(scale=3):
|
||||||
with gr.Column(scale=12):
|
with gr.Column(scale=12):
|
||||||
user_input = gr.Textbox(show_label=False, placeholder="Input...", lines=10, container=False)
|
user_input = gr.Textbox(show_label=False, placeholder="Input...", lines=10, container=False)
|
||||||
with gr.Column(min_width=32, scale=1):
|
with gr.Column(min_width=32, scale=1):
|
||||||
submitBtn = gr.Button("Submit")
|
submitBtn = gr.Button("Submit")
|
||||||
|
with gr.Column(scale=1):
|
||||||
|
prompt_input = gr.Textbox(show_label=False, placeholder="Prompt", lines=10, container=False)
|
||||||
|
pBtn = gr.Button("Set Prompt")
|
||||||
with gr.Column(scale=1):
|
with gr.Column(scale=1):
|
||||||
emptyBtn = gr.Button("Clear History")
|
emptyBtn = gr.Button("Clear History")
|
||||||
max_length = gr.Slider(0, 32768, value=8192, step=1.0, label="Maximum length", interactive=True)
|
max_length = gr.Slider(0, 32768, value=8192, step=1.0, label="Maximum length", interactive=True)
|
||||||
|
@ -156,10 +160,29 @@ with gr.Blocks() as demo:
|
||||||
return "", history + [[parse_text(query), ""]]
|
return "", history + [[parse_text(query), ""]]
|
||||||
|
|
||||||
|
|
||||||
|
def set_prompt(prompt_text, history):
|
||||||
|
"""
|
||||||
|
Sets the initial prompt for the chat session.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
- prompt_text (str): The text of the prompt from the prompt textbox.
|
||||||
|
- history (list): Current chat history.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
- list: Updated chat history with the new prompt at the beginning.
|
||||||
|
"""
|
||||||
|
# Clear any existing history and add the prompt as the first message
|
||||||
|
return [[parse_text(prompt_text), ""]]
|
||||||
|
|
||||||
|
|
||||||
|
# Connect the 'Set Prompt' button click event to the 'set_prompt' function
|
||||||
|
pBtn.click(set_prompt, inputs=[prompt_input, chatbot], outputs=chatbot)
|
||||||
|
|
||||||
|
pBtn.click()
|
||||||
submitBtn.click(user, [user_input, chatbot], [user_input, chatbot], queue=False).then(
|
submitBtn.click(user, [user_input, chatbot], [user_input, chatbot], queue=False).then(
|
||||||
predict, [chatbot, max_length, top_p, temperature], chatbot
|
predict, [chatbot, max_length, top_p, temperature], chatbot
|
||||||
)
|
)
|
||||||
emptyBtn.click(lambda: None, None, chatbot, queue=False)
|
emptyBtn.click(lambda: None, None, chatbot, queue=False)
|
||||||
|
|
||||||
demo.queue()
|
demo.queue()
|
||||||
demo.launch(server_name="127.0.0.1", server_port=8000, inbrowser=True, share=True)
|
demo.launch(server_name="127.0.0.1", server_port=8002, inbrowser=True, share=True)
|
||||||
|
|
Loading…
Reference in New Issue