Merge pull request #2575 from lungothrin/feature/chatter-with-role
support on fly test of tools
This commit is contained in:
commit
7c87532476
|
@ -106,6 +106,7 @@ class WebChatModel(ChatModel):
|
||||||
def predict(
|
def predict(
|
||||||
self,
|
self,
|
||||||
chatbot: List[Tuple[str, str]],
|
chatbot: List[Tuple[str, str]],
|
||||||
|
role: str,
|
||||||
query: str,
|
query: str,
|
||||||
messages: Sequence[Tuple[str, str]],
|
messages: Sequence[Tuple[str, str]],
|
||||||
system: str,
|
system: str,
|
||||||
|
@ -115,7 +116,7 @@ class WebChatModel(ChatModel):
|
||||||
temperature: float,
|
temperature: float,
|
||||||
) -> Generator[Tuple[Sequence[Tuple[str, str]], Sequence[Tuple[str, str]]], None, None]:
|
) -> Generator[Tuple[Sequence[Tuple[str, str]], Sequence[Tuple[str, str]]], None, None]:
|
||||||
chatbot.append([query, ""])
|
chatbot.append([query, ""])
|
||||||
query_messages = messages + [{"role": Role.USER.value, "content": query}]
|
query_messages = messages + [{"role": role, "content": query}]
|
||||||
response = ""
|
response = ""
|
||||||
for new_text in self.stream_chat(
|
for new_text in self.stream_chat(
|
||||||
query_messages, system, tools, max_new_tokens=max_new_tokens, top_p=top_p, temperature=temperature
|
query_messages, system, tools, max_new_tokens=max_new_tokens, top_p=top_p, temperature=temperature
|
||||||
|
|
|
@ -2,6 +2,7 @@ from typing import TYPE_CHECKING, Dict, Optional, Tuple
|
||||||
|
|
||||||
import gradio as gr
|
import gradio as gr
|
||||||
|
|
||||||
|
from ...data import Role
|
||||||
from ..utils import check_json_schema
|
from ..utils import check_json_schema
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,6 +23,7 @@ def create_chat_box(
|
||||||
with gr.Column(scale=4):
|
with gr.Column(scale=4):
|
||||||
system = gr.Textbox(show_label=False)
|
system = gr.Textbox(show_label=False)
|
||||||
tools = gr.Textbox(show_label=False, lines=2)
|
tools = gr.Textbox(show_label=False, lines=2)
|
||||||
|
role = gr.Dropdown(choices=[Role.USER.value, Role.OBSERVATION.value], value=Role.USER.value)
|
||||||
query = gr.Textbox(show_label=False, lines=8)
|
query = gr.Textbox(show_label=False, lines=8)
|
||||||
submit_btn = gr.Button(variant="primary")
|
submit_btn = gr.Button(variant="primary")
|
||||||
|
|
||||||
|
@ -36,7 +38,7 @@ def create_chat_box(
|
||||||
|
|
||||||
submit_btn.click(
|
submit_btn.click(
|
||||||
engine.chatter.predict,
|
engine.chatter.predict,
|
||||||
[chatbot, query, messages, system, tools, max_new_tokens, top_p, temperature],
|
[chatbot, role, query, messages, system, tools, max_new_tokens, top_p, temperature],
|
||||||
[chatbot, messages],
|
[chatbot, messages],
|
||||||
show_progress=True,
|
show_progress=True,
|
||||||
).then(lambda: gr.update(value=""), outputs=[query])
|
).then(lambda: gr.update(value=""), outputs=[query])
|
||||||
|
@ -50,6 +52,7 @@ def create_chat_box(
|
||||||
dict(
|
dict(
|
||||||
system=system,
|
system=system,
|
||||||
tools=tools,
|
tools=tools,
|
||||||
|
role=role,
|
||||||
query=query,
|
query=query,
|
||||||
submit_btn=submit_btn,
|
submit_btn=submit_btn,
|
||||||
clear_btn=clear_btn,
|
clear_btn=clear_btn,
|
||||||
|
|
|
@ -861,6 +861,17 @@ LOCALES = {
|
||||||
"placeholder": "工具列表(非必填)",
|
"placeholder": "工具列表(非必填)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"role": {
|
||||||
|
"en": {
|
||||||
|
"label": "Role",
|
||||||
|
},
|
||||||
|
"ru": {
|
||||||
|
"label": "Роль",
|
||||||
|
},
|
||||||
|
"zh": {
|
||||||
|
"label": "角色",
|
||||||
|
},
|
||||||
|
},
|
||||||
"query": {
|
"query": {
|
||||||
"en": {
|
"en": {
|
||||||
"placeholder": "Input...",
|
"placeholder": "Input...",
|
||||||
|
|
Loading…
Reference in New Issue