-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix * lint * add changeset * add changeset * notebooks --------- Co-authored-by: gradio-pr-bot <[email protected]>
- Loading branch information
1 parent
2346ae8
commit 5923c67
Showing
10 changed files
with
174 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@gradio/chatbot": patch | ||
"gradio": patch | ||
--- | ||
|
||
feat:Fix Chatbot Examples Error |
27 changes: 27 additions & 0 deletions
27
demo/test_chatinterface_examples/multimodal_messages_examples_testcase.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import gradio as gr | ||
|
||
def generate( | ||
message: dict, | ||
chat_history: list[dict], | ||
): | ||
|
||
output = "" | ||
for character in message['text']: | ||
output += character | ||
yield output | ||
|
||
|
||
demo = gr.ChatInterface( | ||
fn=generate, | ||
examples=[ | ||
[{"text": "Hey"}], | ||
[{"text": "Can you explain briefly to me what is the Python programming language?"}], | ||
], | ||
cache_examples=False, | ||
type="messages", | ||
multimodal=True, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
demo.launch() |
27 changes: 27 additions & 0 deletions
27
demo/test_chatinterface_examples/multimodal_tuples_examples_testcase.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import gradio as gr | ||
|
||
def generate( | ||
message: dict, | ||
chat_history: list[dict], | ||
): | ||
|
||
output = "" | ||
for character in message['text']: | ||
output += character | ||
yield output | ||
|
||
|
||
demo = gr.ChatInterface( | ||
fn=generate, | ||
examples=[ | ||
[{"text": "Hey"}], | ||
[{"text": "Can you explain briefly to me what is the Python programming language?"}], | ||
], | ||
cache_examples=False, | ||
type="tuples", | ||
multimodal=True, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
demo.launch() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: test_chatinterface_examples"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["# Downloading files from the demo repo\n", "import os\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/test_chatinterface_examples/multimodal_messages_examples_testcase.py\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/test_chatinterface_examples/multimodal_tuples_examples_testcase.py\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/test_chatinterface_examples/tuples_examples_testcase.py"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "def generate(\n", " message: str,\n", " chat_history: list[dict],\n", "):\n", "\n", " output = \"\"\n", " for character in message:\n", " output += character\n", " yield output\n", "\n", "\n", "demo = gr.ChatInterface(\n", " fn=generate,\n", " examples=[\n", " [\"Hey\"],\n", " [\"Can you explain briefly to me what is the Python programming language?\"],\n", " ],\n", " cache_examples=False,\n", " type=\"messages\",\n", ")\n", "\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import gradio as gr | ||
|
||
def generate( | ||
message: str, | ||
chat_history: list[dict], | ||
): | ||
|
||
output = "" | ||
for character in message: | ||
output += character | ||
yield output | ||
|
||
|
||
demo = gr.ChatInterface( | ||
fn=generate, | ||
examples=[ | ||
["Hey"], | ||
["Can you explain briefly to me what is the Python programming language?"], | ||
], | ||
cache_examples=False, | ||
type="messages", | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
demo.launch() |
27 changes: 27 additions & 0 deletions
27
demo/test_chatinterface_examples/tuples_examples_testcase.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import gradio as gr | ||
|
||
def generate( | ||
message: str, | ||
chat_history: list[dict], | ||
): | ||
|
||
output = "" | ||
for character in message: | ||
output += character | ||
yield output | ||
|
||
|
||
demo = gr.ChatInterface( | ||
fn=generate, | ||
examples=[ | ||
["Hey"], | ||
["Can you explain briefly to me what is the Python programming language?"], | ||
], | ||
cache_examples=False, | ||
type="tuples", | ||
) | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
demo.launch() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { test, expect, go_to_testcase } from "@self/tootils"; | ||
|
||
const cases = [ | ||
"messages", | ||
"tuples_examples", | ||
"multimodal_tuples_examples", | ||
"multimodal_messages_examples" | ||
]; | ||
|
||
for (const test_case of cases) { | ||
test(`test case ${test_case} clicking example properly adds it to the history and passes the correct values to the prediction function`, async ({ | ||
page | ||
}) => { | ||
if (cases.slice(1).includes(test_case)) { | ||
await go_to_testcase(page, test_case); | ||
} | ||
|
||
// Click on an example and the input/response are correct | ||
await page.getByRole("button", { name: "Hey" }).click(); | ||
await expect(page.locator(".user p")).toContainText("Hey"); | ||
await expect(page.locator(".bot p")).toContainText("Hey"); | ||
|
||
// Clear the chat and click on a different example, the input/response are correct | ||
await page.getByLabel("Clear").click(); | ||
await page | ||
.getByRole("button", { name: "Can you explain briefly to me" }) | ||
.click(); | ||
await expect(page.locator(".user p")).toContainText( | ||
"Can you explain briefly to me what is the Python programming language?" | ||
); | ||
await expect(page.locator(".bot p")).toContainText( | ||
"Can you explain briefly to me what is the Python programming language?" | ||
); | ||
|
||
// Retry button works | ||
await page.getByLabel("Retry").click(); | ||
await expect(page.locator(".user p")).toContainText( | ||
"Can you explain briefly to me what is the Python programming language?" | ||
); | ||
await expect(page.locator(".bot p")).toContainText( | ||
"Can you explain briefly to me what is the Python programming language?" | ||
); | ||
|
||
// Undo message resets to the examples view | ||
await page.getByLabel("Undo", { exact: true }).click(); | ||
await expect(page.getByRole("button", { name: "Hey" })).toBeVisible(); | ||
}); | ||
} |