Traceback (most recent call last):
File "/home/user/app/app.py", line 46, in
chatbot = gr.Chatbot(label="Chat", type="messages")
File "/usr/local/lib/python3.10/site-packages/gradio/component_meta.py", line 163, in wrapper
return fn(self, **kwargs)
TypeError: Chatbot.init() got an unexpected keyword argument 'type'
IMPORTANT: You are using gradio version 4.36.1, however version 5.0.1 is available, please upgrade.
--------, убери апи
Assistant
User
Logs
Build
Container
Lock scroll
Clear
===== Application Startup at 2024-10-16 19:06:16 =====
To create a public link, set share=True in launch().
IMPORTANT: You are using gradio version 4.36.1, however version 5.0.1 is available, please upgrade.
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/gradio/queueing.py", line 532, in process_events
response = await route_utils.call_process_api(
File "/usr/local/lib/python3.10/site-packages/gradio/route_utils.py", line 276, in call_process_api
output = await app.get_blocks().process_api(
File "/usr/local/lib/python3.10/site-packages/gradio/blocks.py", line 1938, in process_api
data = await self.postprocess_data(block_fn, result["prediction"], state)
File "/usr/local/lib/python3.10/site-packages/gradio/blocks.py", line 1761, in postprocess_data
prediction_value = block.postprocess(prediction_value)
File "/usr/local/lib/python3.10/site-packages/gradio/components/chatbot.py", line 220, in postprocess
raise TypeError(
TypeError: Expected a list of lists or list of tuples. Received: {'role': 'user', 'content': 'hello'}, так же убери thinking budget и сделай окно с промптом дефолтным поменьше
Assistant
To address the issues you're encountering, we'll make the following modifications:
Adjust the Data Structure: Ensure that the chat history is a list of lists or tuples as required by the Gradio component.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
сделай так чтобы у меня было окошко с чатом и я еще мог поставить дефолтный промпт для него чтобы он отвечал всегда так. ПРимер:import gradio as gr
import time
import re
import os
if response.startswith("Error:"):
return history + [({"role": "system", "content": response},)], ""
answer, reflection, steps = parse_response(response)
messages = []
messages.append({"role": "user", "content": message})
formatted_steps = [f"Step {i}: {step}" for i, step in enumerate(steps, 1)]
all_steps = "\n".join(formatted_steps) + f"\n\nReflection: {reflection}"
messages.append({"role": "assistant", "content": all_steps, "metadata": {"title": f"Thinking Time: {thinking_time:.2f} sec"}})
messages.append({"role": "assistant", "content": answer})
return history + messages, ""
Define the default system prompt
DEFAULT_SYSTEM_PROMPT = """
You are a helpful assistant in normal conversation.
When given a problem to solve, you are an expert problem-solving assistant.
Your task is to provide a detailed, step-by-step solution to a given question.
Follow these instructions carefully:
Read the given question carefully and reset counter between and to {budget}
Generate a detailed, logical step-by-step solution.
Enclose each step of your solution within and tags.
You are allowed to use at most {budget} steps (starting budget),
keep track of it by counting down within tags ,
STOP GENERATING MORE STEPS when hitting 0, you don't have to use all of them.
Do a self-reflection when you are unsure about how to proceed,
based on the self-reflection and reward, decides whether you need to return
to the previous steps.
After completing the solution steps, reorganize and synthesize the steps
into the final answer within and tags.
Provide a critical, honest and subjective self-evaluation of your reasoning
process within and tags.
Assign a quality score to your solution as a float between 0.0 (lowest
quality) and 1.0 (highest quality), enclosed in and tags.
Example format:
[starting budget]
[Content of step 1]
[remaining budget]
[Content of step 2]
[Evaluation of the steps so far]
[Float between 0.0 and 1.0]
[remaining budget]
[Content of step 3 or Content of some previous step]
[remaining budget]
...
[Content of final step]
[remaining budget]
[Final Answer] (must give final answer in this format)
[Evaluation of the solution]
[Float between 0.0 and 1.0]
"""
with gr.Row():
model = gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[0])
thinking_budget = gr.Slider(minimum=1, maximum=100, value=10, step=1, label="Thinking Budget", info="maximum times a model can think")
chatbot = gr.Chatbot(label="Chat", show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel", type="messages")
msg = gr.Textbox(label="Type your message here...", placeholder="Enter your message...")
gr.Button("Clear Chat").click(lambda: ([], ""), inputs=None, outputs=[chatbot, msg])
system_prompt = gr.Textbox(label="System Prompt", value=DEFAULT_SYSTEM_PROMPT, lines=15, interactive=True)
msg.submit(generate, inputs=[msg, chatbot, model, system_prompt, thinking_budget, api_key], outputs=[chatbot, msg])
demo.launch(share=True, show_api=False)
Sure, here's how you can set up a Gradio chat interface with a default system prompt and allow the user to interact with it:
python
import gradio as gr
import time
import re
MODELS = ["Mixtral-8x7B-Instruct-v0.1"]
def chat_with_ai(message, chat_history, system_prompt):
"""Formats the chat history for the API call."""
messages = [{"role": "system", "content": system_prompt}]
for item in chat_history:
messages.append({"role": "user", "content": item["user"]})
messages.append({"role": "assistant", "content": item.get("assistant", "")})
messages.append({"role": "user", "content": message})
return messages
def respond(message, chat_history, model, system_prompt, thinking_budget):
"""Simulate API call and get the response. Replace with actual API call."""
# Simulate a delay
time.sleep(1)
# Dummy response
response = f"Simulated response for: {message}"
return response, 1.0
def generate(message, history, model, system_prompt, thinking_budget):
"""Generates the chatbot response."""
response, thinking_time = respond(message, history, model, system_prompt, thinking_budget)
history.append({"user": message, "assistant": response})
return history, ""
# Define the default system prompt
DEFAULT_SYSTEM_PROMPT = """
You are a helpful assistant in normal conversation.
When given a problem to solve, you are an expert problem-solving assistant.
Your task is to provide a detailed, step-by-step solution to a given question.
...
"""
with gr.Blocks() as demo:
gr.Markdown("# Custom Chat Interface")
with gr.Row():
model = gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[0])
thinking_budget = gr.Slider(minimum=1, maximum=100, value=10, step=1, label="Thinking Budget")
system_prompt = gr.Textbox(value=DEFAULT_SYSTEM_PROMPT, lines=15, label="System Prompt")
chatbot = gr.Chatbot(label="Chat", type="messages")
msg = gr.Textbox(label="Type your message here...", placeholder="Enter your message...")
# Clear chat
def clear_chat():
return [], ""
gr.Button("Clear Chat").click(clear_chat, inputs=None, outputs=[chatbot, msg])
# Generate response on message submission
msg.submit(generate, inputs=[msg, chatbot, model, system_prompt, thinking_budget], outputs=[chatbot, msg])
demo.launch()
Explanation
Gradio Components:
gr.Markdown: Displays markdown text.
gr.Dropdown: Allows model selection.
gr.Slider: For adjusting the thinking budget.
gr.Chatbot: The chat interface to display conversation.
gr.Textbox: For user input and system prompt.
Functionality:
generate: Simulates a response from the AI using a placeholder function respond. Replace this with actual API calls when integrating with an API.
Default system prompt captures how the AI should behave.
You can clear the chat with the "Clear Chat" button.
Replace the respond function with the actual API interaction to get responses from your model, and ensure you manage any required authentication for API access.
It seems you're using an older version of Gradio (4.36.1), which might not support all the functionalities or argument names used in the code you've provided. Let's modify the code to remove any parameters that might not be supported, such as the type argument for the Chatbot component.
Here's the revised code without any unnecessary API placeholders or unsupported arguments, and it should be compatible with Gradio 4.36.1:
python
import gradio as gr
MODELS = ["Mixtral-8x7B-Instruct-v0.1"]
def chat_with_ai(message, chat_history, system_prompt):
"""Formats the chat history for processing."""
history = [{"role": "system", "content": system_prompt}]
history.extend(chat_history)
history.append({"role": "user", "content": message})
return history
def generate(message, chat_history, model, system_prompt, thinking_budget):
"""Simulates response generation."""
# Dummy logic for simulating a response
response = f"Simulated response for: {message}"
# Update chat history
chat_history.append({"role": "user", "content": message})
chat_history.append({"role": "assistant", "content": response})
return chat_history, ""
DEFAULT_SYSTEM_PROMPT = """
You are a helpful assistant in normal conversation.
When given a problem to solve, you are an expert problem-solving assistant.
Your task is to provide a detailed, step-by-step solution to a given question.
...
"""
with gr.Blocks() as demo:
gr.Markdown("# Custom Chat Interface")
with gr.Row():
model = gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[0])
thinking_budget = gr.Slider(minimum=1, maximum=100, value=10, step=1, label="Thinking Budget")
system_prompt = gr.Textbox(value=DEFAULT_SYSTEM_PROMPT, lines=15, label="System Prompt")
chatbot = gr.Chatbot(label="Chat")
msg = gr.Textbox(label="Type your message here...", placeholder="Enter your message...")
def clear_chat():
return [], ""
gr.Button("Clear Chat").click(clear_chat, inputs=None, outputs=[chatbot, msg])
msg.submit(generate, inputs=[msg, chatbot, model, system_prompt, thinking_budget], outputs=[chatbot, msg])
demo.launch()
Key Points:
Removed the type argument in gr.Chatbot since it caused issues with the version you're using.
The API interactions are mocked to simulate responses locally. Replace generate's response logic with actual API calls if needed in the future.
Simplified some component interactions to ensure compatibility with your current Gradio version.
Chatbot
Remove the Thinking Budget: Eliminate the slider component for the thinking budget as requested.
Modify the Default System Prompt Textbox: Make the system prompt textbox smaller for simplicity.
Here's the modified code:
python
import gradio as gr
MODELS = ["Mixtral-8x7B-Instruct-v0.1"]
def generate(message, chat_history, model, system_prompt):
"""Simulates response generation."""
response = f"Simulated response for: {message}"
# Update chat history as a list of tuples
chat_history.append((message, response))
return chat_history, ""
DEFAULT_SYSTEM_PROMPT = """
You are a helpful assistant in normal conversation.
When given a problem to solve, you are an expert problem-solving assistant.
Your task is to provide a detailed, step-by-step solution to a given question.
"""
with gr.Blocks() as demo:
gr.Markdown("# Custom Chat Interface")
with gr.Row():
model = gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[0])
system_prompt = gr.Textbox(value=DEFAULT_SYSTEM_PROMPT, lines=5, label="System Prompt")
chatbot = gr.Chatbot(label="Chat")
msg = gr.Textbox(label="Type your message here...", placeholder="Enter your message...")
def clear_chat():
return [], ""
gr.Button("Clear Chat").click(clear_chat, inputs=None, outputs=[chatbot, msg])
msg.submit(generate, inputs=[msg, chatbot, model, system_prompt], outputs=[chatbot, msg])
demo.launch()
Key Modifications:
Data Structure: The chat_history is updated as a list of tuples, which satisfies the expected input format for the Chatbot component.
Removed Thinking Budget: The slider for the thinking budget has been removed to simplify the interface.
System Prompt Textbox: Reduced the number of visible lines in the system prompt textbox to 5 for a more compact interface.
These changes should fix the errors you encountered and align the interface with your requirements. If you still face issues, it would be beneficial to update to the latest Gradio version to take advantage of newer features and bug fixes.