gradio-app / gradio

Build and share delightful machine learning apps, all in Python. ๐ŸŒŸ Star to support our work!
http://www.gradio.app
Apache License 2.0
32.26k stars 2.41k forks source link

ChatInterface type='messages', API still uses tuples format #9375

Open taoari opened 3 days ago

taoari commented 3 days ago

Describe the bug

When set type="messages" for ChatInterface. In the GUI, history is in messages format, but from API call, history is in tuples format.

Have you searched existing issues? ๐Ÿ”Ž

Reproduction

import gradio as gr

def echo(message, history):
    print(message, history)
    return message

demo = gr.ChatInterface(fn=echo, type='messages', title="Echo Bot")
demo.launch()
from gradio_client import Client

client = Client("http://localhost:7860/")
result = client.predict(
        message="Hello!!",
        api_name="/chat"
)
print(result)

result = client.predict(
        message="Hello again!!",
        api_name="/chat"
)
print(result)

The following is from Gradio Web:

hello []
hello2 [{'role': 'user', 'metadata': {'title': None}, 'content': 'hello'}, {'role': 'assistant', 'metadata': {'title': None}, 'content': 'hello'}]

The following is from gradio_client:

Hello!! []
Hello again!! [['Hello!!', 'Hello!!']]

where history format is inconsistent.

Screenshot

No response

Logs

No response

System Info

Gradio Environment Information:
------------------------------
Operating System: Darwin
gradio version: 4.44.0
gradio_client version: 1.3.0

------------------------------------------------
gradio dependencies in your environment:

aiofiles: 23.2.1
anyio: 4.4.0
fastapi: 0.112.2
ffmpy: 0.4.0
gradio-client==1.3.0 is not installed.
httpx: 0.27.0
huggingface-hub: 0.24.6
importlib-resources: 6.4.0
jinja2: 3.1.4
markupsafe: 2.1.5
matplotlib: 3.9.2
numpy: 1.26.4
orjson: 3.10.7
packaging: 24.1
pandas: 2.2.2
pillow: 10.4.0
pydantic: 2.8.2
pydub: 0.25.1
python-multipart: 0.0.9
pyyaml: 6.0.2
ruff: 0.6.2
semantic-version: 2.10.0
tomlkit==0.12.0 is not installed.
typer: 0.12.5
typing-extensions: 4.11.0
urllib3: 2.2.2
uvicorn: 0.30.6
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.

gradio_client dependencies in your environment:

fsspec: 2024.5.0
httpx: 0.27.0
huggingface-hub: 0.24.6
packaging: 24.1
typing-extensions: 4.11.0
websockets: 12.0

Severity

Blocking usage of gradio

abidlabs commented 3 days ago

Thanks @taoari for flagging this!