📘 **TELUS Agriculture & Consumer Goods** 如何通过 **Haystack Agents** 转变促销交易

集成:Mastodon Fetcher

一个自定义组件,用于获取 mastodon 用户名的最新帖子

作者
Tuana Çelik

MastodonFetcher 是一个简单的自定义组件,用于获取给定 Mastodon 用户名的 last_k_posts。您可以在 Hugging Face 🤗 上的 🦄 Should I Follow? 空间中找到此自定义组件的演示。

目录

概述

此组件期望 username 是一个完整的 Mastodon 用户名。例如:“ tuana@sigmoid.social”。如果提供的用户名正确且公开,MastodonFetcher 将返回一个 Document 对象列表,其内容是用户最新的帖子。

安装

pip install mastodon-fetcher-haystack

使用

您可以单独使用此组件,也可以在管道中使用。

单独使用

from mastodon_fetcher_haystack.mastodon_fetcher import MastodonFetcher

mastodon_fetcher = MastodonFetcher()
mastodon_fetcher.run(username="tuana@sigmoid.social")

在管道中使用

from haystack import Pipeline
from haystack.utils import Secret
from mastodon_fetcher_haystack.mastodon_fetcher import MastodonFetcher
from haystack.components.generators import OpenAIGenerator
from haystack.components.builders import PromptBuilder

mastodon_fetcher = MastodonFetcher()
prompt_builder = PromptBuilder(template='YOUR_PROMPT_TEMPLATE')
llm = OpenAIGenerator(api_key=Secret.from_token("YOUR_OPENAI_API_KEY"))

pipe = Pipeline()
pipe.add_component("fetcher", mastodon_fetcher)
pipe.add_component("prompt_builder", prompt_builder)
pipe.add_component("llm", llm)

pipe.connect("fetcher.documents", "prompt_builder.documents")
pipe.connect("prompt_builder.prompt", "llm.prompt")
pipe.run(data={"fetcher": {"username": "tuana@sigmoid.social"}})

限制

  1. 此组件的设置方式非常特定于它期望用户名的格式。请确保您提供完整的用户名,例如:username@instance
  2. 默认情况下,Mastodon API 允许请求多达 40 篇帖子。