Skip to content

Commit

Permalink
fix: use any(<cond> for llm in llms) instead of any(map(...))
Browse files Browse the repository at this point in the history
  • Loading branch information
nikochiko committed Mar 7, 2025
1 parent 55d1be9 commit 427b414
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
3 changes: 2 additions & 1 deletion daras_ai_v2/language_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,8 @@ def run_language_model(
), "Pleave provide exactly one of { prompt, messages }"

model: LargeLanguageModels = LargeLanguageModels[str(model)]
max_tokens = min(max_tokens, model.max_output_tokens)
if model.max_output_tokens:
max_tokens = min(max_tokens, model.max_output_tokens)
if model.is_chat_model:
if prompt and not messages:
# convert text prompt to chat messages
Expand Down
27 changes: 12 additions & 15 deletions daras_ai_v2/language_model_settings_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,16 @@ def language_model_settings(selected_models: str | list[str] | None = None) -> N
with col1:
gui.checkbox("Avoid Repetition", key="avoid_repetition")

if any(map(lambda llm: llm.supports_json, llms)):
with col2:
gui.selectbox(
f"###### {field_title_desc(LanguageModelSettings, 'response_format_type')}",
options=[None, "json_object"],
key="response_format_type",
format_func={
None: BLANK_OPTION,
"json_object": "JSON Object",
}.__getitem__,
)
with col2:
gui.selectbox(
f"###### {field_title_desc(LanguageModelSettings, 'response_format_type')}",
options=[None, "json_object"],
key="response_format_type",
format_func={
None: BLANK_OPTION,
"json_object": "JSON Object",
}.__getitem__,
)

col1, col2 = gui.columns(2)
with col1:
Expand All @@ -81,7 +80,7 @@ def language_model_settings(selected_models: str | list[str] | None = None) -> N
step=2,
)

if any(map(lambda llm: llm.supports_temperature, llms)):
if any(llm.supports_temperature for llm in llms):
with col2:
gui.slider(
label="""
Expand All @@ -105,9 +104,7 @@ def language_model_settings(selected_models: str | list[str] | None = None) -> N
min_value=1,
max_value=4,
)
if llms and any(
map(lambda llm: not llm.is_chat_model and llm.llm_api == LLMApis.openai, llms)
):
if any(not llm.is_chat_model and llm.llm_api == LLMApis.openai for llm in llms):
with col2:
gui.slider(
label="""
Expand Down

0 comments on commit 427b414

Please sign in to comment.