Closed PrashantSaikia closed 5 months ago
Hi @PrashantSaikia could you mock out the ollama calls so that we can have a standalone minimal repro? https://stackoverflow.com/help/minimal-reproducible-example
I can't reproduce the issue if I remove ollama and replace its responses with random responses form a list:
import gradio as gr
import random
def format_history(msg: str, history: list[list[str, str]], system_prompt: str):
chat_history = [{"role": "system", "content":system_prompt}]
for query, response in history:
chat_history.append({"role": "user", "content": query})
chat_history.append({"role": "assistant", "content": response})
chat_history.append({"role": "user", "content": msg})
return chat_history
def generate_response(msg: str, history: list[list[str, str]], system_prompt: str, top_k: int, top_p: float, temperature: float):
chat_history = format_history(msg, history, system_prompt)
response = random.choice(["Hi", "Hey", "Hello", "Nice to meet you", "Wassup?"])
return response
chatbot = gr.ChatInterface(
generate_response,
chatbot=gr.Chatbot(
value=[(None, "Hello, I am Charlie. Ask me anything you want.")],
avatar_images=["user.jpg", "chatbot.png"],
height="64vh"
),
additional_inputs=[
gr.Textbox("You are a helpful assistant and always try to answer user queries to the best of your ability.", label="System Prompt"),
gr.Slider(0.0,100.0, label="top_k", value=40, info="Reduces the probability of generating nonsense. A higher value (e.g. 100) will give more diverse answers, while a lower value (e.g. 10) will be more conservative. (Default: 40)"),
gr.Slider(0.0,1.0, label="top_p", value=0.9, info=" Works together with top-k. A higher value (e.g., 0.95) will lead to more diverse text, while a lower value (e.g., 0.5) will generate more focused and conservative text. (Default: 0.9)"),
gr.Slider(0.0,2.0, label="temperature", value=0.4, info="The temperature of the model. Increasing the temperature will make the model answer more creatively. (Default: 0.8)"),
],
title="Charlie",
theme="finlaymacklon/smooth_slate",
submit_btn="⬅ Send",
retry_btn="🔄 Regenerate Response",
undo_btn="↩ Delete Previous",
clear_btn="🗑️ Clear Chat",
css="footer {visibility: hidden}"
)
chatbot.queue().launch(server_name="0.0.0.0", server_port=8080)
This works perfectly without any error. With Ollama calls, the issue seems to go away if I replace None
with any text, like so:
value=[("Hi", "Hello, I am Charlie. Ask me anything you want.")],
But of course, that also leads to appearing of a user message before the bot greeting. Is there any way around this issue?
We can try to take a look -- but in the meantime, you could also consider using a placeholder
for the gr.Chatbot
-- which can be an arbitrary html / markdown that is present before a user starts interacting with your chatbot.
If I replace value=[(None, greeting)]
with placeholder=greeting
, it displays the greeting, but not as a chatbot message. And also, it does not persist - it goes away the moment the user enters a message.
Yes that's the intention of placeholder
-- just offering it as a workaround until we have time to investigate this
Alright, thanks! Also, unrelated, but could you please quickly point out how I can write a custom footer? Like, instead of "built with gradio" and displaying the API link, I want it to display some text, like "Charlie does not collect any user data or track user queries". I can't find anything in the documentation on how or where to edit the footer.
There isn't a specific api for this, but I would suggest wrapping the ChatInterface within a Blocks and then using gr.Markdown()
to write whichever text you'd like, e.g.
with gr.Blocks() as demo:
gr.ChatInterface(...)
gr.Markdown(..)
demo.launch()
But can't I just edit the html file in the backend to hardcode the footer? I can't find where its located, perhaps its a hidden file?
Hi @PrashantSaikia its internationalized so you'd have to edit this file: gradio/js/app/src/lang/en.json
, specifically:
37,18: "built_with": "built with", 38,25: "built_with_gradio": "Built with Gradio",
I'm going to close this issue since we don't have a standalone repro for the original issue. We can reopen if we do.
Describe the bug
Here is my app:
If I remove this greeting line:
value=[[None, "Hello, I am Charlie. Ask me anything you want."]],
It works fine.
But if I have it in, I get the following error:
ollama._types.RequestError: messages must contain content
Basically, it interferes with the inputs being sent to the LLM. But I just want it to be a welcome message.
How do I have the greeting message without interfering with the rest of the app?
I have also tried putting it this way (slightly different syntax according to two different sources):
value=[(None, "Hello, I am Charlie. Ask me anything you want.")]
But the result is the same.
Have you searched existing issues? 🔎
Reproduction
Screenshot
No response
Logs
System Info
Severity
I can work around it