Skip to content

Commit

Permalink
Handle None values in format_timestamp, session state, empty completi…
Browse files Browse the repository at this point in the history
…on and SERP items
  • Loading branch information
devxpy committed Jul 29, 2024
1 parent b0c80da commit 999d3ca
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
10 changes: 9 additions & 1 deletion daras_ai_v2/asr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,15 @@ def iterate_subtitles(
yield segment_start, segment_end, segment_text


def format_timestamp(seconds: float, always_include_hours: bool, decimal_marker: str):
INFINITY_SECONDS = 99 * 3600 + 59 * 60 + 59 # 99:59:59 in seconds


def format_timestamp(
seconds: float | None, always_include_hours: bool, decimal_marker: str
):
if seconds is None:
# treat None as end of time
seconds = INFINITY_SECONDS
assert seconds >= 0, "non-negative timestamp expected"
milliseconds = round(seconds * 1000.0)

Expand Down
2 changes: 1 addition & 1 deletion daras_ai_v2/enum_selector_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def enum_multiselect(
except AttributeError:
deprecated = set()
enums = []
value = gui.session_state.get(key, [])
value = gui.session_state.get(key) or []
for e in enum_cls:
if e in deprecated and e.name not in value:
continue
Expand Down
2 changes: 2 additions & 0 deletions daras_ai_v2/language_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,8 @@ def _run_openai_chat(
)
if stream:
return _stream_openai_chunked(completion, used_model, messages)
if not completion or not completion.choices:
return [format_chat_entry(role=CHATML_ROLE_ASSISTANT, content="")]
else:
ret = [choice.message.dict() for choice in completion.choices]
record_openai_llm_usage(used_model, completion, messages, ret)
Expand Down
2 changes: 1 addition & 1 deletion daras_ai_v2/serp_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_links_from_serp_api(
snippet=item.get("snippet") or "",
)
for item in items
if (url := item.get("link") or item.get("website"))
if item and (url := item.get("link") or item.get("website"))
]
return data, links

Expand Down

0 comments on commit 999d3ca

Please sign in to comment.