Skip to content

Commit

Permalink
more type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
abidlabs committed Dec 23, 2024
1 parent e07bb01 commit 5fa4b1b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion demo/agent_chatbot/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def interact_with_agent(prompt, history):
messages = []
yield messages
for msg in stream_to_gradio(agent, prompt):
messages.append(asdict(msg))
messages.append(asdict(msg)) # type: ignore
yield messages
yield messages

Expand Down
7 changes: 4 additions & 3 deletions gradio/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ def load_chat(
[{"role": "system", "content": system_message}] if system_message else []
)

def open_api(message: str, history: list | None) -> str:
def open_api(message: str, history: list | None) -> str | None:
history = history or start_message
if len(history) > 0 and isinstance(history[0], (list, tuple)):
history = ChatInterface._tuples_to_messages(history)
Expand All @@ -641,7 +641,8 @@ def open_api_stream(
)
response = ""
for chunk in stream:
response += chunk.choices[0].delta.content
yield response
if chunk.choices[0].delta.content is not None:
response += chunk.choices[0].delta.content
yield response

return ChatInterface(open_api_stream if streaming else open_api, type="messages")
4 changes: 3 additions & 1 deletion gradio/themes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ def to_dict(self):
schema = {"theme": {}}
for prop in dir(self):
if (
not prop.startswith("_") or prop.startswith("_font") or prop in ("_stylesheets", "name")
not prop.startswith("_")
or prop.startswith("_font")
or prop in ("_stylesheets", "name")
) and isinstance(getattr(self, prop), (list, str)):
schema["theme"][prop] = getattr(self, prop)
return schema
Expand Down
2 changes: 1 addition & 1 deletion test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class GenericObject:
for x in test_objs:
hints = get_type_hints(x)
assert len(hints) == 1
assert hints["s"] == str
assert hints["s"] is str

assert len(get_type_hints(GenericObject())) == 0

Expand Down

0 comments on commit 5fa4b1b

Please sign in to comment.