Add Slack messaging
This commit is contained in:
15
indexing.py
15
indexing.py
@@ -12,13 +12,15 @@ import langchain_openai
|
||||
import langchain_weaviate
|
||||
import langgraph.graph
|
||||
|
||||
import slack
|
||||
import weaviate
|
||||
from hn import HackerNewsClient, Story
|
||||
from scrape import JinaScraper
|
||||
|
||||
NUM_STORIES = 20
|
||||
USER_PREFERENCES = []
|
||||
ENABLE_MLFLOW_TRACING = False # Set to True if you want to use MLflow for tracing
|
||||
USER_PREFERENCES = ["Machine Learning", "Linux", "Open-Source"]
|
||||
ENABLE_SLACK = False # Send updates to Slack, need to set SLACK_BOT_TOKEN env var
|
||||
ENABLE_MLFLOW_TRACING = False # Use MLflow (at http://localhost:5000) for tracing
|
||||
|
||||
|
||||
llm = langchain.chat_models.init_chat_model(
|
||||
@@ -100,13 +102,13 @@ def generate(state: State):
|
||||
return {"answer": response.content}
|
||||
|
||||
|
||||
def run_query(preferences: Iterable[str]):
|
||||
def run_query(preferences: Iterable[str]) -> str:
|
||||
graph_builder = langgraph.graph.StateGraph(State).add_sequence([retrieve, generate])
|
||||
graph_builder.add_edge(langgraph.graph.START, "retrieve")
|
||||
graph = graph_builder.compile()
|
||||
|
||||
response = graph.invoke(State(preferences=preferences, context=[], answer=""))
|
||||
print(response["answer"])
|
||||
return response["answer"]
|
||||
|
||||
|
||||
def get_existing_story_ids() -> set[str]:
|
||||
@@ -233,7 +235,10 @@ async def main():
|
||||
print("No new stories to process")
|
||||
|
||||
# 4. Query
|
||||
run_query(USER_PREFERENCES)
|
||||
answer = run_query(USER_PREFERENCES)
|
||||
print(answer)
|
||||
if ENABLE_SLACK:
|
||||
slack.send_message(channel="#ragpull-demo", text=answer)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user