deepset-ai / hayhooks

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

using chat_with_website pipeline #15

Closed ssword62 closed 1 month ago

ssword62 commented 1 month ago

After deploying to the hayhooks server the pipeline chat_with_website, I'm trying to use it. Starting from your example for test_pipeline_01.yml I'm trying curl -X 'POST' \ 'http://localhost:1416/chat_with_website' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "converter": { "value": "what is haystack?" } }' since converter is the name of the first element of the pipeline and th input is an HTML document (a simple string in my case)

this leads to the error 422 Unprocessable Entity {"detail":[{"type":"missing","loc":["body","fetcher"],"msg":"Field required","input":{"converter":{"value":"what is haystack?"}}},{"type":"missing","loc":["body","llm"],"msg":"Field required","input":{"converter":{"value":"what is haystack?"}}},{"type":"missing","loc":["body","prompt"],"msg":"Field required","input":{"converter":{"value":"what is haystack?"}}}]}

What am I doing wrong? Thanks.

masci commented 1 month ago

With this pipeline (taken from Haystack's predefined templates and stripped from the {%raw%} blocks):

components:
  converter:
    init_parameters:
      extractor_type: DefaultExtractor
    type: haystack.components.converters.html.HTMLToDocument

  fetcher:
    init_parameters:
      raise_on_failure: true
      retry_attempts: 2
      timeout: 3
      user_agents:
      - haystack/LinkContentFetcher/2.0.0b8
    type: haystack.components.fetchers.link_content.LinkContentFetcher

  llm:
    init_parameters:
      api_base_url: null
      api_key:
        env_vars:
        - OPENAI_API_KEY
        strict: true
        type: env_var
      generation_kwargs: {}
      model: gpt-3.5-turbo
      streaming_callback: null
      system_prompt: null
    type: haystack.components.generators.openai.OpenAIGenerator

  prompt:
    init_parameters:
      template: |
        "According to the contents of this website:
        {% for document in documents %}
          {{document.content}}
        {% endfor %}
        Answer the given question: {{query}}
        Answer:
        "
    type: haystack.components.builders.prompt_builder.PromptBuilder

connections:
- receiver: converter.sources
  sender: fetcher.streams
- receiver: prompt.documents
  sender: converter.documents
- receiver: llm.prompt
  sender: prompt.prompt

metadata: {}

This is the curl command I used:

curl -X 'POST' \
  'http://localhost:1416/chat_with_website' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "converter": {
    "meta": {}
  },
  "fetcher": {
    "urls": [
      "https://haystack.deepset.ai"
    ]
  },
  "llm": {
    "generation_kwargs": {}
  },
  "prompt": {
    "query": "What is Haystack?"
  }
}'
ssword62 commented 1 month ago

@masci thanks for the explanation.