Unify the 3 interface modes (#3554)
This commit is contained in:
parent
bf70c19603
commit
a1a9ec895d
29 changed files with 660 additions and 714 deletions
|
@ -53,14 +53,32 @@ def iterator():
|
|||
|
||||
|
||||
# Extension functions that map string -> string
|
||||
def _apply_string_extensions(function_name, text, state):
|
||||
def _apply_string_extensions(function_name, text, state, is_chat=False):
|
||||
for extension, _ in iterator():
|
||||
if hasattr(extension, function_name):
|
||||
func = getattr(extension, function_name)
|
||||
if len(signature(func).parameters) == 2:
|
||||
text = func(text, state)
|
||||
|
||||
# Handle old extensions without the 'state' arg or
|
||||
# the 'is_chat' kwarg
|
||||
count = 0
|
||||
has_chat = False
|
||||
for k in signature(func).parameters:
|
||||
if k == 'is_chat':
|
||||
has_chat = True
|
||||
else:
|
||||
count += 1
|
||||
|
||||
if count == 2:
|
||||
args = [text, state]
|
||||
else:
|
||||
text = func(text)
|
||||
args = [text]
|
||||
|
||||
if has_chat:
|
||||
kwargs = {'is_chat': is_chat}
|
||||
else:
|
||||
kwargs = {}
|
||||
|
||||
text = func(*args, **kwargs)
|
||||
|
||||
return text
|
||||
|
||||
|
@ -169,9 +187,7 @@ def create_extensions_block():
|
|||
if len(to_display) > 0:
|
||||
with gr.Column(elem_id="extensions"):
|
||||
for row in to_display:
|
||||
extension, name = row
|
||||
display_name = getattr(extension, 'params', {}).get('display_name', name)
|
||||
gr.Markdown(f"\n### {display_name}")
|
||||
extension, _ = row
|
||||
extension.ui()
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue