-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
459807c
commit 171d07b
Showing
5 changed files
with
50 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,5 +54,5 @@ | |
|
||
if st.session_state.result: | ||
voice = st.session_state.result | ||
st.write(voice['results'][0]) | ||
st.write(voice[0]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
safetensors==0.3.3.post1 | ||
farm-haystack==1.20.0 | ||
haystack-ai==2.0.0b4 | ||
streamlit==1.21.0 | ||
markdown | ||
st-annotated-text | ||
python-dotenv | ||
mastodon-fetcher-haystack==0.0.1 | ||
mastodon-fetcher-haystack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,61 @@ | ||
import streamlit as st | ||
from mastodon_fetcher_haystack.mastodon_fetcher import MastodonFetcher | ||
from haystack import Pipeline | ||
from haystack.nodes import PromptNode, PromptTemplate | ||
from haystack.components.generators import OpenAIGenerator | ||
from haystack.components.builders import PromptBuilder | ||
|
||
def start_haystack(openai_key): | ||
#Use this function to contruct a pipeline | ||
fetcher = MastodonFetcher() | ||
|
||
mastodon_template = PromptTemplate(prompt="""You will be given a post stream belonging to a specific Mastodon profile. Answer with a summary of what they've lately been posting about and in what languages. | ||
You may go into some detail about what topics they tend to like postint about. Please also mention their overall tone, for example: positive, | ||
negative, political, sarcastic or something else. | ||
Examples: | ||
Post stream: [@deepset_ai](https://mastodon.social/@deepset_ai): Come join our Haystack server for our first Discord event tomorrow, a deepset AMA session with @rusic_milos @malte_pietsch… | ||
[@deepset_ai](https://mastodon.social/@deepset_ai): Join us for a chat! On Thursday 25th we are hosting a 'deepset - Ask Me Anything' session on our brand new Discord. Come… | ||
[@deepset_ai](https://mastodon.social/@deepset_ai): Curious about how you can use @OpenAI GPT3 in a Haystack pipeline? This week we released Haystack 1.7 with which we introdu… | ||
[@deepset_ai](https://mastodon.social/@deepset_ai): So many updates from @deepset_ai today! | ||
Summary: This user has lately been reposting posts from @deepset_ai. The topics of the posts have been around the Haystack community, NLP and GPT. They've | ||
been posting in English, and have had a positive, informative tone. | ||
Post stream: I've directed my team to set sharper rules on how we deal with unidentified objects.\n\nWe will inventory, improve ca… | ||
the incursion by China’s high-altitude balloon, we enhanced radar to pick up slower objects.\n \nBy doing so, w… | ||
I gave an update on the United States’ response to recent aerial objects. | ||
Summary: This user has lately been posting about having sharper rules to deal with unidentified objects and an incursuin by China's high-altitude | ||
baloon. Their pots have mostly been neutral but determined in tone. They mostly post in English. | ||
Post stream: {join(documents)} | ||
Summary: | ||
""") | ||
prompt_node = PromptNode(model_name_or_path="gpt-4", default_prompt_template=mastodon_template, api_key=openai_key) | ||
mastodon_template = """You will be given a post stream belonging to a specific Mastodon profile. Answer with a summary of what they've lately been posting about and in what languages. | ||
You may go into some detail about what topics they tend to like postint about. Please also mention their overall tone, for example: positive, | ||
negative, political, sarcastic or something else. | ||
Examples: | ||
Post stream: [@deepset_ai](https://mastodon.social/@deepset_ai): Come join our Haystack server for our first Discord event tomorrow, a deepset AMA session with @rusic_milos @malte_pietsch… | ||
[@deepset_ai](https://mastodon.social/@deepset_ai): Join us for a chat! On Thursday 25th we are hosting a 'deepset - Ask Me Anything' session on our brand new Discord. Come… | ||
[@deepset_ai](https://mastodon.social/@deepset_ai): Curious about how you can use @OpenAI GPT3 in a Haystack pipeline? This week we released Haystack 1.7 with which we introdu… | ||
[@deepset_ai](https://mastodon.social/@deepset_ai): So many updates from @deepset_ai today! | ||
Summary: This user has lately been reposting posts from @deepset_ai. The topics of the posts have been around the Haystack community, NLP and GPT. They've | ||
been posting in English, and have had a positive, informative tone. | ||
Post stream: I've directed my team to set sharper rules on how we deal with unidentified objects.\n\nWe will inventory, improve ca… | ||
the incursion by China’s high-altitude balloon, we enhanced radar to pick up slower objects.\n \nBy doing so, w… | ||
I gave an update on the United States’ response to recent aerial objects. | ||
Summary: This user has lately been posting about having sharper rules to deal with unidentified objects and an incursuin by China's high-altitude | ||
baloon. Their pots have mostly been neutral but determined in tone. They mostly post in English. | ||
Post stream: {{ documents }} | ||
Summary: | ||
""" | ||
prompt_builder = PromptBuilder(template=mastodon_template) | ||
llm = OpenAIGenerator(model_name="gpt-4", api_key=openai_key) | ||
|
||
st.session_state["haystack_started"] = True | ||
|
||
mastodon_pipeline = Pipeline() | ||
mastodon_pipeline.add_node(component=fetcher, name="MastodonFetcher", inputs=["Query"]) | ||
mastodon_pipeline.add_node(component=prompt_node, name="PromptNode", inputs=["MastodonFetcher"]) | ||
mastodon_pipeline.add_component("fetcher", fetcher) | ||
mastodon_pipeline.add_component("prompt_builder", prompt_builder) | ||
mastodon_pipeline.add_component("llm", llm) | ||
|
||
|
||
mastodon_pipeline.connect("fetcher.documents", "prompt_builder.documents") | ||
mastodon_pipeline.connect("prompt_builder.prompt", "llm.prompt") | ||
|
||
return mastodon_pipeline | ||
|
||
|
||
@st.cache_data(show_spinner=True) | ||
def query(username, _pipeline): | ||
try: | ||
result = _pipeline.run(query=username, params={"MastodonFetcher": {"last_k_posts": 20}}) | ||
replies = _pipeline.run(data={"fetcher": {"username": username, | ||
"last_k_posts": 20}}) | ||
result = replies['llm']['replies'] | ||
except Exception as e: | ||
result = ["Please make sure you are providing a correct, public Mastodon account"] | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters