deepset-ai / hayhooks

Deploy Haystack pipelines behind a REST Api.
https://haystack.deepset.ai
Apache License 2.0
39 stars 11 forks source link

"422 Client Error: Unprocessable Entity" when making POST request to pipeline #34

Closed paulleo13 closed 3 months ago

paulleo13 commented 3 months ago

Whenever i post a request to the following pipeline deployed on hayhooks, i get a 422 Client Error. My pipeline schema YAML file and illustration are as follows:

components:
  answer_builder:
    init_parameters:
      pattern: null
      reference_pattern: null
    type: haystack.components.builders.answer_builder.AnswerBuilder
  llm:
    init_parameters:
      generation_kwargs: {}
      model_kwargs:
        model_path: ./llama_model/llama-3-8b-instruct/ggml-model-Q4_K_M.gguf
        n_batch: 128
        n_ctx: 8192
        n_threads: 9
        use_mlock: false
        verbose: false
      model_path: ./llama_model/llama-3-8b-instruct/ggml-model-Q4_K_M.gguf
      n_batch: 128
      n_ctx: 8192
    type: haystack_integrations.components.generators.llama_cpp.generator.LlamaCppGenerator
  prompt_builder:
    init_parameters:
      template: "You are an assistant for answering questions about technical documentation.\n\
        \    You are given a question and extracted context from the documentation.\
        \ Provide an instructional, precise answer.\n    If you don't know the answer,\
        \ say 'I don't know the answer based on the context'. Do not make up an answer.\n\
        \    Question: {{question}}\n    Context:\n    {% for doc in documents %}\n\
        \        {{ doc.content }}\n    {% endfor %}\n    <|end_of_turn|>\n    Answer:\n"
    type: haystack.components.builders.prompt_builder.PromptBuilder
  retriever:
    init_parameters:
      document_store:
        init_parameters:
          api_key: null
          content_field: content
          duplicate_documents: overwrite
          embedding_dim: 768
          embedding_field: embedding
          grpc_port: 6334
          hnsw_config: null
          host: null
          https: null
          index: Document
          init_from: null
          location: null
          metadata: {}
          name_field: name
          on_disk: true
          on_disk_payload: null
          optimizers_config: null
          path: ./db
          payload_fields_to_index: null
          port: 6333
          prefer_grpc: false
          prefix: null
          progress_bar: true
          quantization_config: null
          recreate_index: false
          replication_factor: null
          return_embedding: true
          scroll_size: 10000
          shard_number: null
          similarity: cosine
          timeout: null
          url: null
          use_sparse_embeddings: false
          wait_result_from_api: false
          wal_config: null
          write_batch_size: 100
          write_consistency_factor: null
        type: haystack_integrations.document_stores.qdrant.document_store.QdrantDocumentStore
      filters: null
      return_embedding: false
      scale_score: true
      top_k: 3
    type: haystack_integrations.components.retrievers.qdrant.retriever.QdrantEmbeddingRetriever
  text_embedder:
    init_parameters:
      batch_size: 32
      device:
        device: cpu
        type: single
      model: ./embedding_models/text_embedder
      normalize_embeddings: false
      prefix: ''
      progress_bar: false
      suffix: ''
      token:
        env_vars:
        - HF_API_TOKEN
        strict: false
        type: env_var
    type: haystack.components.embedders.sentence_transformers_text_embedder.SentenceTransformersTextEmbedder
connections:
- receiver: retriever.query_embedding
  sender: text_embedder.embedding
- receiver: prompt_builder.documents
  sender: retriever.documents
- receiver: answer_builder.documents
  sender: retriever.documents
- receiver: llm.prompt
  sender: prompt_builder.prompt
- receiver: answer_builder.replies
  sender: llm.replies
max_loops_allowed: 100
metadata: {}

pipeline_schema After debugging, the correct format for a POST request should be as follows:

url = 'http://localhost:1416/pipeline_schema'  
headers = {  
    'accept': 'application/json',
    'Content-Type': 'application/json'  
}  
data = {  
    "text_embedder": {  
        "text": "What are the steps to configure the ET200SP?"  
    },  
    "answer_builder": {  
        "query": "What are the steps to configure the ET200SP?"  
    }  
}  
response = requests.post(url, headers=headers, json=data)

However, this fails every time. Same thing happens when using curl from cmd.

Unfortunately, I cannot get the API specification through http://localhost:1416/docs because an internal server error (pydantic.errors.PydanticInvalidForJsonSchema: Cannot generate a JsonSchema for core_schema.IsInstanceSchema (<class 'haystack.dataclasses.sparse_embedding.SparseEmbedding'>)) related to pydantic occurs every time I call the url from the browser.

paulleo13 commented 3 months ago

Ok have found the solution to the pydantic error in this pull request in haystack https://github.com/deepset-ai/haystack/pull/7678

paulleo13 commented 3 months ago

Fixed after I had found the correct format under http://localhost:1416/docs