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

Fix the Pydantic Validation Error -> convert_component_output #39

Closed
wants to merge 1 commit into from

Conversation

ParseDark
Copy link

I am currently trying to resolve the Pydantic Response error. I believe the root cause lies in the convert_component_output function, which cannot properly handle the ApiMeta. It seems the intended functionality is to treat this field as a dictionary for the model_dump. Therefore, I have enhanced the convert_component_output function, and it works successfully on my end.

Yml

components:
  generator:
    init_parameters:
      api_base_url: null
      api_key:
        env_vars:
        - OPENAI_API_KEY
        strict: true
        type: env_var
      generation_kwargs: {}
      model: gpt-4o-mini
      streaming_callback: null
      system_prompt: null
    type: haystack.components.generators.openai.OpenAIGenerator
  prompt:
    init_parameters:
      required_variables: null
      template: "\nYou will be provided some context, followed by the URL that this\
        \ context comes from.\nAnswer the question based on the context, and reference\
        \ the URL from which your answer is generated.\nYour answer should be in {{\
        \ language }}.\nContext:\n{% for doc in documents %}\n   {{ doc.content }}\
        \ \n   URL: {{ doc.meta['url']}}\n{% endfor %}\nQuestion: {{ query }}\nAnswer:\n"
      variables: null
    type: haystack.components.builders.prompt_builder.PromptBuilder
  query_embedder:
    init_parameters:
      api_base_url: null
      api_key:
        env_vars:
        - COHERE_API_KEY
        - CO_API_KEY
        strict: true
        type: env_var
      input_type: search_query
      model: embed-english-v3.0
      timeout: 120
      truncate: END
      use_async_client: false
    type: haystack_integrations.components.embedders.cohere.text_embedder.CohereTextEmbedder
  retriever:
    init_parameters:
      document_store:
        init_parameters:
          bm25_algorithm: BM25L
          bm25_parameters: {}
          bm25_tokenization_regex: (?u)\b\w\w+\b
          embedding_similarity_function: dot_product
        type: haystack.document_stores.in_memory.document_store.InMemoryDocumentStore
      filter_policy: replace
      filters: null
      return_embedding: false
      scale_score: false
      top_k: 10
    type: haystack.components.retrievers.in_memory.embedding_retriever.InMemoryEmbeddingRetriever
connections:
- receiver: retriever.query_embedding
  sender: query_embedder.embedding
- receiver: prompt.documents
  sender: retriever.documents
- receiver: generator.prompt
  sender: prompt.prompt
max_loops_allowed: 100
metadata: {}

Response

image

Error Stack

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/Users/hawei/miniconda3/envs/hayhooks/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 406, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/Users/hawei/miniconda3/envs/hayhooks/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
    return await self.app(scope, receive, send)
  File "/Users/hawei/miniconda3/envs/hayhooks/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/Users/hawei/miniconda3/envs/hayhooks/lib/python3.10/site-packages/starlette/applications.py", line 113, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/hawei/miniconda3/envs/hayhooks/lib/python3.10/site-packages/starlette/middleware/errors.py", line 187, in __call__
    raise exc
  File "/Users/hawei/miniconda3/envs/hayhooks/lib/python3.10/site-packages/starlette/middleware/errors.py", line 165, in __call__
    await self.app(scope, receive, _send)
  File "/Users/hawei/miniconda3/envs/hayhooks/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/Users/hawei/miniconda3/envs/hayhooks/lib/python3.10/site-packages/starlette/_exception_handler.py", line 62, in wrapped_app
    raise exc
  File "/Users/hawei/miniconda3/envs/hayhooks/lib/python3.10/site-packages/starlette/_exception_handler.py", line 51, in wrapped_app
    await app(scope, receive, sender)
  File "/Users/hawei/miniconda3/envs/hayhooks/lib/python3.10/site-packages/starlette/routing.py", line 715, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/hawei/miniconda3/envs/hayhooks/lib/python3.10/site-packages/starlette/routing.py", line 735, in app
    await route.handle(scope, receive, send)
  File "/Users/hawei/miniconda3/envs/hayhooks/lib/python3.10/site-packages/starlette/routing.py", line 288, in handle
    await self.app(scope, receive, send)
  File "/Users/hawei/miniconda3/envs/hayhooks/lib/python3.10/site-packages/starlette/routing.py", line 76, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/Users/hawei/miniconda3/envs/hayhooks/lib/python3.10/site-packages/starlette/_exception_handler.py", line 62, in wrapped_app
    raise exc
  File "/Users/hawei/miniconda3/envs/hayhooks/lib/python3.10/site-packages/starlette/_exception_handler.py", line 51, in wrapped_app
    await app(scope, receive, sender)
  File "/Users/hawei/miniconda3/envs/hayhooks/lib/python3.10/site-packages/starlette/routing.py", line 73, in app
    response = await f(request)
  File "/Users/hawei/miniconda3/envs/hayhooks/lib/python3.10/site-packages/fastapi/routing.py", line 301, in app
    raw_response = await run_endpoint_function(
  File "/Users/hawei/miniconda3/envs/hayhooks/lib/python3.10/site-packages/fastapi/routing.py", line 212, in run_endpoint_function
    return await dependant.call(**values)
  File "/Volumes/workspace/SWorkspace/hayhooks/src/hayhooks/server/utils/deploy_utils.py", line 32, in pipeline_run
    return JSONResponse(PipelineRunResponse(**final_output).model_dump(), status_code=200)
  File "/Users/hawei/miniconda3/envs/hayhooks/lib/python3.10/site-packages/pydantic/main.py", line 209, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for StartRunResponse
query_embedder.meta
  Input should be a valid dictionary [type=dict_type, input_value=ApiMeta(api_version=ApiMe...okens=None, warnings=[]), input_type=ApiMeta]
    For further information visit https://errors.pydantic.dev/2.9/v/dict_type

@mpangrazzi
Copy link
Contributor

mpangrazzi commented Nov 20, 2024

@ParseDark this should be fixed now by #41 (merged). Can you double check so we can close this? Thanks!

@mpangrazzi
Copy link
Contributor

@ParseDark closing this, I've tested with the same pipeline and everything it's working using v0.0.18. Feel free to reopen if you still get errors!

@mpangrazzi mpangrazzi closed this Nov 21, 2024
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

Successfully merging this pull request may close these issues.

2 participants