Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Issues with active_models validation causing 422 errors #651

Open
elliotsegler opened this issue Dec 18, 2024 · 1 comment
Open

[BUG] Issues with active_models validation causing 422 errors #651

elliotsegler opened this issue Dec 18, 2024 · 1 comment

Comments

@elliotsegler
Copy link

Describe the bug

It looks like #607 has introduced a validation error that doesn't quite work with sharing bots.

When you load a shared bot from a URL and an alias doesn't exist, the code tries to create it. It looks like the model validation for active_models used below doesn't like the format that's being passed in (despite looking pretty correct).

BotAliasModel(
id=bot.id,
title=bot.title,
description=bot.description,
original_bot_id=bot_id,
create_time=current_time,
last_used_time=current_time,
is_pinned=False,
sync_status=bot.sync_status,
has_knowledge=bot.has_knowledge(),
has_agent=bot.is_agent_enabled(),
conversation_quick_starters=[
ConversationQuickStarterModel(
title=starter.title,
example=starter.example,
)
for starter in bot.conversation_quick_starters
],
active_models=ActiveModelsOutput.model_validate(
dict(bot.active_models)
),

At a guess, I'd question this code is nessecary, given the model already is valid.

To Reproduce

Steps to reproduce the behavior:

  1. Create a bot and share the URL
  2. Log in as a different user and browse to the shared bot
  3. On loading the bot summary, you'll see 422 Unprocessable Content Errors, which block user input to interact with the bot.

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Logs and stacktrace (redacted)

START RequestId: 90abc01b-f351-4939-8014-e1747d3b0e7b Version: 1
INFO:app.main - Request path: /bot/summary/01JFC2VJ8D2DA7YW3B1T5PWD4F
INFO:app.main - Request method: GET
INFO:app.main - Request headers: Headers( READACTED )
INFO:app.main - Request body: ...
INFO:app.repositories.custom_bot - Finding bot with id: 01JFC2VJ8D2DA7YW3B1T5PWD4F
INFO:app.repositories.custom_bot - Finding alias bot with id: 01JFC2VJ8D2DA7YW3B1T5PWD4F
INFO:app.repositories.custom_bot - Finding public bot with id: 01JFC2VJ8D2DA7YW3B1T5PWD4F
INFO:app.repositories.custom_bot - Found public bot: id='01JFC2VJ8D2DA7YW3B1T5PWD4F' title='READACTED' description='READACTED' instruction='READACTED' create_time=1734498992095.0 last_used_time=1734499616847.0 public_bot_id='01JFC2VJ8D2DA7YW3B1T5PWD4F' owner_user_id='6468f4c8-b0e1-70d1-aeec-be475aee63ff' is_pinned=True generation_params=GenerationParamsModel(max_tokens=2000, top_k=128, top_p=0.999, temperature=0.6, stop_sequences=['Human: ', 'Assistant: ']) agent=AgentModel(tools=[]) knowledge=KnowledgeModel(source_urls=[], sitemap_urls=[], filenames=['DSPF-OFFICIAL.pdf'], s3_urls=[]) sync_status='SUCCEEDED' sync_status_reason='Knowledge base sync succeeded' sync_last_exec_id='' published_api_stack_name=None published_api_datetime=None published_api_codebuild_id=None display_retrieved_chunks=True conversation_quick_starters=[] bedrock_knowledge_base=BedrockKnowledgeBaseModel(embeddings_model='titan_v2', open_search=OpenSearchParamsModel(analyzer=None), chunking_configuration=DefaultParamsModel(chunking_strategy='default'), search_params=SearchParamsModel(max_results=20, search_type='hybrid'), knowledge_base_id='ZWPLOAB5JD', exist_knowledge_base_id=None, data_source_ids=['ZI15WEZC6S'], parsing_model='disabled', web_crawling_scope='DEFAULT', web_crawling_filters=WebCrawlingFiltersModel(exclude_patterns=[''], include_patterns=[''])) bedrock_guardrails=BedrockGuardrailsModel(is_guardrail_enabled=False, hate_threshold=0, insults_threshold=0, sexual_threshold=0, violence_threshold=0, misconduct_threshold=0, grounding_threshold=0.0, relevance_threshold=0.0, guardrail_arn='', guardrail_version='') active_models=ActiveModelsModel(claude_instant_v1=True, claude_v2=True, claude_v3_sonnet=True, claude_v3_5_sonnet=True, claude_v3_5_sonnet_v2=True, claude_v3_5_haiku=True, claude_v3_haiku=True, claude_v3_opus=True, mistral_7b_instruct=True, mixtral_8x7b_instruct=True, mistral_large=True, amazon_nova_pro=True, amazon_nova_lite=True, amazon_nova_micro=True)
ERROR:app.main - 1 validation error for BotAliasModel
active_models
Input should be a valid dictionary or instance of ActiveModelsModel [type=model_type, input_value=ActiveModelsOutput(claude... amazon_nova_micro=True), input_type=ActiveModelsOutput]
For further information visit https://errors.pydantic.dev/2.10/v/model_type
ERROR:app.main -   File "/var/task/starlette/_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "/var/task/starlette/routing.py", line 73, in app
response = await f(request)
^^^^^^^^^^^^^^^^
File "/var/task/fastapi/routing.py", line 301, in app
raw_response = await run_endpoint_function(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/task/fastapi/routing.py", line 214, in run_endpoint_function
return await run_in_threadpool(dependant.call, **values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/task/starlette/concurrency.py", line 39, in run_in_threadpool
return await anyio.to_thread.run_sync(func, *args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/task/anyio/to_thread.py", line 56, in run_sync
return await get_async_backend().run_sync_in_worker_thread(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/task/anyio/_backends/_asyncio.py", line 2441, in run_sync_in_worker_thread
return await future
^^^^^^^^^^^^
File "/var/task/anyio/_backends/_asyncio.py", line 943, in run
result = context.run(func, *args)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/task/app/routes/bot.py", line 167, in get_bot_summary
return fetch_bot_summary(current_user.id, bot_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/task/app/usecases/bot.py", line 704, in fetch_bot_summary
BotAliasModel(
File "/var/task/pydantic/main.py", line 214, in __init__
validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INFO:     REDACTED:0 - "GET /bot/summary/01JFC2VJ8D2DA7YW3B1T5PWD4F HTTP/1.1" 422 Unprocessable Entity
@elliotsegler
Copy link
Author

Just doing a little more digging here, the model definitions look incompatible.

Both the BotModel and BotAliasModel expect active_models to be type ActiveModelsModel. See below

active_models: ActiveModelsModel # type: ignore

active_models: ActiveModelsModel # type: ignore

I think this is just a mistaken use of the ActiveModelsOutput model (used for the APIs).

I'm looking at the tests, I can't see that app/usecases/bot.py:fetch_bot_summary is covered...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant