-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample.py
More file actions
60 lines (44 loc) · 1.81 KB
/
example.py
File metadata and controls
60 lines (44 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
deepset Haystack integration example.
Prerequisites:
pip install metorial haystack-ai python-dotenv
"""
import asyncio
import os
from dotenv import load_dotenv
load_dotenv()
from haystack import Pipeline
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.components.tools import ToolInvoker
from haystack.dataclasses import ChatMessage
from metorial import Metorial
from metorial.integrations.haystack import create_haystack_tools
async def main():
metorial = Metorial(api_key=os.getenv("METORIAL_API_KEY"))
# Create a deployment for Metorial Search — built-in web search, no auth needed
deployment = metorial.provider_deployments.create(
name="Metorial Search",
provider_id="metorial-search",
)
async with metorial.provider_session(
provider="openai",
providers=[
{"provider_deployment_id": deployment.id},
# (Optional) Add an OAuth provider like Slack or GitHub:
# {"provider_deployment_id": "your-slack-deployment-id", "provider_auth_config_id": "auth-config-id"},
],
) as session:
tools = create_haystack_tools(session)
generator = OpenAIChatGenerator(model="gpt-4o", tools=tools)
tool_invoker = ToolInvoker(tools=tools)
pipeline = Pipeline()
pipeline.add_component("generator", generator)
pipeline.add_component("tool_invoker", tool_invoker)
pipeline.connect("generator.replies", "tool_invoker.messages")
messages = [ChatMessage.from_user(
"Search the web for the latest news about AI agents and summarize the top 3 stories."
)]
result = pipeline.run({"generator": {"messages": messages}})
print(result["tool_invoker"]["tool_messages"])
if __name__ == "__main__":
asyncio.run(main())