adopt ruff as the replacement for python black (#332)
This commit is contained in:
@@ -44,7 +44,7 @@ class LLMAPIHandlerFactory:
|
||||
),
|
||||
num_retries=llm_config.num_retries,
|
||||
retry_after=llm_config.retry_delay_seconds,
|
||||
set_verbose=False if SettingsManager.get_settings().is_cloud_environment() else llm_config.set_verbose,
|
||||
set_verbose=(False if SettingsManager.get_settings().is_cloud_environment() else llm_config.set_verbose),
|
||||
enable_pre_call_checks=True,
|
||||
)
|
||||
main_model_group = llm_config.main_model_group
|
||||
@@ -101,7 +101,11 @@ class LLMAPIHandlerFactory:
|
||||
except openai.OpenAIError as e:
|
||||
raise LLMProviderError(llm_key) from e
|
||||
except Exception as e:
|
||||
LOG.exception("LLM request failed unexpectedly", llm_key=llm_key, model=main_model_group)
|
||||
LOG.exception(
|
||||
"LLM request failed unexpectedly",
|
||||
llm_key=llm_key,
|
||||
model=main_model_group,
|
||||
)
|
||||
raise LLMProviderError(llm_key) from e
|
||||
|
||||
if step:
|
||||
|
||||
@@ -58,35 +58,58 @@ if not any(
|
||||
if SettingsManager.get_settings().ENABLE_OPENAI:
|
||||
LLMConfigRegistry.register_config(
|
||||
"OPENAI_GPT4_TURBO",
|
||||
LLMConfig("gpt-4-turbo", ["OPENAI_API_KEY"], supports_vision=False, add_assistant_prefix=False),
|
||||
LLMConfig(
|
||||
"gpt-4-turbo",
|
||||
["OPENAI_API_KEY"],
|
||||
supports_vision=False,
|
||||
add_assistant_prefix=False,
|
||||
),
|
||||
)
|
||||
LLMConfigRegistry.register_config(
|
||||
"OPENAI_GPT4V", LLMConfig("gpt-4-turbo", ["OPENAI_API_KEY"], supports_vision=True, add_assistant_prefix=False)
|
||||
"OPENAI_GPT4V",
|
||||
LLMConfig(
|
||||
"gpt-4-turbo",
|
||||
["OPENAI_API_KEY"],
|
||||
supports_vision=True,
|
||||
add_assistant_prefix=False,
|
||||
),
|
||||
)
|
||||
|
||||
if SettingsManager.get_settings().ENABLE_ANTHROPIC:
|
||||
LLMConfigRegistry.register_config(
|
||||
"ANTHROPIC_CLAUDE3",
|
||||
LLMConfig(
|
||||
"anthropic/claude-3-sonnet-20240229", ["ANTHROPIC_API_KEY"], supports_vision=True, add_assistant_prefix=True
|
||||
"anthropic/claude-3-sonnet-20240229",
|
||||
["ANTHROPIC_API_KEY"],
|
||||
supports_vision=True,
|
||||
add_assistant_prefix=True,
|
||||
),
|
||||
)
|
||||
LLMConfigRegistry.register_config(
|
||||
"ANTHROPIC_CLAUDE3_OPUS",
|
||||
LLMConfig(
|
||||
"anthropic/claude-3-opus-20240229", ["ANTHROPIC_API_KEY"], supports_vision=True, add_assistant_prefix=True
|
||||
"anthropic/claude-3-opus-20240229",
|
||||
["ANTHROPIC_API_KEY"],
|
||||
supports_vision=True,
|
||||
add_assistant_prefix=True,
|
||||
),
|
||||
)
|
||||
LLMConfigRegistry.register_config(
|
||||
"ANTHROPIC_CLAUDE3_SONNET",
|
||||
LLMConfig(
|
||||
"anthropic/claude-3-sonnet-20240229", ["ANTHROPIC_API_KEY"], supports_vision=True, add_assistant_prefix=True
|
||||
"anthropic/claude-3-sonnet-20240229",
|
||||
["ANTHROPIC_API_KEY"],
|
||||
supports_vision=True,
|
||||
add_assistant_prefix=True,
|
||||
),
|
||||
)
|
||||
LLMConfigRegistry.register_config(
|
||||
"ANTHROPIC_CLAUDE3_HAIKU",
|
||||
LLMConfig(
|
||||
"anthropic/claude-3-haiku-20240307", ["ANTHROPIC_API_KEY"], supports_vision=True, add_assistant_prefix=True
|
||||
"anthropic/claude-3-haiku-20240307",
|
||||
["ANTHROPIC_API_KEY"],
|
||||
supports_vision=True,
|
||||
add_assistant_prefix=True,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -125,7 +148,12 @@ if SettingsManager.get_settings().ENABLE_AZURE:
|
||||
"AZURE_OPENAI_GPT4V",
|
||||
LLMConfig(
|
||||
f"azure/{SettingsManager.get_settings().AZURE_DEPLOYMENT}",
|
||||
["AZURE_DEPLOYMENT", "AZURE_API_KEY", "AZURE_API_BASE", "AZURE_API_VERSION"],
|
||||
[
|
||||
"AZURE_DEPLOYMENT",
|
||||
"AZURE_API_KEY",
|
||||
"AZURE_API_BASE",
|
||||
"AZURE_API_VERSION",
|
||||
],
|
||||
supports_vision=True,
|
||||
add_assistant_prefix=False,
|
||||
),
|
||||
|
||||
@@ -33,7 +33,10 @@ async def llm_messages_builder(
|
||||
)
|
||||
# Anthropic models seems to struggle to always output a valid json object so we need to prefill the response to force it:
|
||||
if add_assistant_prefix:
|
||||
return [{"role": "user", "content": messages}, {"role": "assistant", "content": "{"}]
|
||||
return [
|
||||
{"role": "user", "content": messages},
|
||||
{"role": "assistant", "content": "{"},
|
||||
]
|
||||
return [{"role": "user", "content": messages}]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user