pip install traceAI-haystack haystack-ai trafilatura
import os os.environ["OPENAI_API_KEY"] = "your-openai-api-key" os.environ["FI_API_KEY"] = "your-futureagi-api-key" os.environ["FI_SECRET_KEY"] = "your-futureagi-secret-key"
from fi_instrumentation import register from fi_instrumentation.fi_types import ProjectType trace_provider = register( project_type=ProjectType.OBSERVE, project_name="haystack_project", )
from traceai_haystack import HaystackInstrumentor HaystackInstrumentor().instrument(tracer_provider=trace_provider)
from haystack import Pipeline from haystack.components.fetchers import LinkContentFetcher from haystack.components.converters import HTMLToDocument from haystack.components.builders import ChatPromptBuilder from haystack.components.generators.chat import OpenAIChatGenerator from haystack.dataclasses import ChatMessage fetcher = LinkContentFetcher() converter = HTMLToDocument() prompt_template = [ ChatMessage.from_user( """ According to the contents of this website: {% for document in documents %} {{document.content}} {% endfor %} Answer the given question: {{query}} Answer: """ ) ] prompt_builder = ChatPromptBuilder(template=prompt_template) llm = OpenAIChatGenerator() pipeline = Pipeline() pipeline.add_component("fetcher", fetcher) pipeline.add_component("converter", converter) pipeline.add_component("prompt", prompt_builder) pipeline.add_component("llm", llm) pipeline.connect("fetcher.streams", "converter.sources") pipeline.connect("converter.documents", "prompt.documents") pipeline.connect("prompt.prompt", "llm") result = pipeline.run({"fetcher": {"urls": ["https://haystack.deepset.ai/overview/quick-start"]}, "prompt": {"query": "Which components do I need for a RAG pipeline?"}}) print(result["llm"]["replies"][0].text)
Was this page helpful?