mirror of
https://github.com/neuml/txtai.git
synced 2026-10-12 02:19:52 +00:00
78 KiB
78 KiB
In [1]:
%%capture
!pip install datasets git+https://github.com/neuml/txtai#egg=txtai[pipeline,workflow]In [6]:
import logging
import requests
# Uncomment and set. The following are dummy parameters. Your parameters should not be publicly shared!
# AUTH = "xoxb-not-a-real-token-this-will-not-work"
# CHANNEL = "C0XXXXXXXXX"
# URL = "https://slack.com/api/chat.postMessage"
# Logging configuration
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
class Slack:
def __init__(self):
self.alerts = set()
def __call__(self, elements):
for alert in elements:
uid, text, _ = self.extract(alert)
if uid not in self.alerts:
logger.info("Sending alert: %s", alert)
self.alerts.add(uid)
headers = {
"Content-type": "application/json",
"Authorization": f"Bearer {AUTH}"
}
response = requests.post(URL, headers=headers, json={
"channel": CHANNEL,
"text": f"{text} {uid}"
}).json()
if not response["ok"]:
logger.error(response)
return elements
def extract(self, alert):
if isinstance(alert, dict):
return (alert["id"], alert["text"], None)
return alert
In [5]:
from txtai.app import Application
workflow = """
writable: true
embeddings:
path: sentence-transformers/nli-mpnet-base-v2
content: true
tabular:
idcolumn: url
textcolumns:
- title
__main__.Slack:
workflow:
index:
schedule:
cron: "* * * * * 0/5"
elements:
- front_page
iterations: 1
tasks:
- batch: false
extract:
- hits
method: get
params:
tags: null
task: service
url: https://hn.algolia.com/api/v1/search?hitsPerPage=50
- action: tabular
- action: upsert
alert:
schedule:
cron: 0/1 * * * *
elements:
- select id, text, score from txtai where similar('software development library') and score >= 0.4 and id like 'http%'
iterations: 1
tasks:
- action: search
- action: __main__.Slack
"""
app = Application(workflow)
app.wait()2022-02-10 15:12:42,838 [INFO] schedule: 'index' scheduler started with schedule * * * * * 0/5
2022-02-10 15:12:42,839 [INFO] schedule: 'alert' scheduler started with schedule 0/1 * * * *
2022-02-10 15:12:42,843 [INFO] schedule: 'index' next run scheduled for 2022-02-10T15:12:45+00:00
2022-02-10 15:12:42,851 [INFO] schedule: 'alert' next run scheduled for 2022-02-10T15:13:00+00:00
2022-02-10 15:12:45,884 [INFO] schedule: 'index' max iterations (1) reached
2022-02-10 15:13:00,042 [INFO] __call__: Sending alert: {'id': 'https://datastation.multiprocess.io/blog/2022-02-08-the-world-of-postgresql-wire-compatibility.html', 'text': 'The world of PostgreSQL wire compatibility', 'score': 0.40123000741004944}
2022-02-10 15:13:00,254 [INFO] schedule: 'alert' max iterations (1) reached
In [6]:
from txtai.app import Application
workflow = """
writable: true
embeddings:
path: sentence-transformers/nli-mpnet-base-v2
content: true
tabular:
idcolumn: url
textcolumns:
- summary
content: true
__main__.Slack:
workflow:
index:
schedule:
cron: "* * * * * 0/5"
elements:
- 10
iterations: 1
tasks:
- batch: false
extract:
- rows
method: get
params:
size: null
task: service
url: https://neuspo.com/data/articles/list?category=Top&from=0
- action: tabular
- action: upsert
alert:
schedule:
cron: 0/1 * * * *
elements:
- select 'https://neuspo.com' || id id, text from txtai where weight >= 40
iterations: 1
tasks:
- action: search
- action: __main__.Slack
"""
app = Application(workflow)
app.wait()2022-02-10 15:16:49,702 [INFO] schedule: 'index' scheduler started with schedule * * * * * 0/5
2022-02-10 15:16:49,704 [INFO] schedule: 'index' next run scheduled for 2022-02-10T15:16:50+00:00
2022-02-10 15:16:49,704 [INFO] schedule: 'alert' scheduler started with schedule 0/1 * * * *
2022-02-10 15:16:49,714 [INFO] schedule: 'alert' next run scheduled for 2022-02-10T15:17:00+00:00
2022-02-10 15:16:50,474 [INFO] schedule: 'index' max iterations (1) reached
2022-02-10 15:17:00,010 [INFO] __call__: Sending alert: {'id': 'https://neuspo.com/stream/be15c852925b53639b63feb7169a2842', 'text': 'Islanders 6, Canucks 3: Five-goal first period keys Islanders win in first game post-'}
2022-02-10 15:17:00,215 [INFO] schedule: 'alert' max iterations (1) reached
In [7]:
from txtai.app import Application
workflow = """
writable: true
embeddings:
path: sentence-transformers/nli-mpnet-base-v2
content: true
summary:
path: sshleifer/distilbart-cnn-12-6
tabular:
idcolumn: url
textcolumns:
- title
textractor:
join: true
minlength: 100
paragraphs: true
__main__.Slack:
workflow:
index:
schedule:
cron: "* * * * * 0/5"
elements:
- front_page
iterations: 1
tasks:
- batch: false
extract:
- hits
method: get
params:
tags: null
task: service
url: https://hn.algolia.com/api/v1/search?hitsPerPage=50
- action: tabular
- action: upsert
alert:
schedule:
cron: 0/1 * * * *
elements:
- select id url, id title from txtai where similar('software development library') and score >= 0.4 and id like 'http%'
iterations: 1
tasks:
- action: search
- action: tabular
- action: textractor
- action: summary
- action: __main__.Slack
unpack: false
"""
app = Application(workflow)
app.wait()2022-02-10 17:19:48,847 [INFO] schedule: 'index' scheduler started with schedule * * * * * 0/5
2022-02-10 17:19:48,857 [INFO] schedule: 'index' next run scheduled for 2022-02-10T17:19:50+00:00
2022-02-10 17:19:48,848 [INFO] schedule: 'alert' scheduler started with schedule 0/1 * * * *
2022-02-10 17:19:48,864 [INFO] schedule: 'alert' next run scheduled for 2022-02-10T17:20:00+00:00
2022-02-10 17:19:50,368 [INFO] schedule: 'index' max iterations (1) reached
2022-02-10 17:20:02,233 [INFO] __call__: Sending alert: ('https://datastation.multiprocess.io/blog/2022-02-08-the-world-of-postgresql-wire-compatibility.html', 'Every server-client database has a wire protocol. A wire protocol is the format for interactions between a database server and its clients. It does NOT encompass the actual query language itself, let alone database semantics. Proprietary databases like Oracle and IBM Db2 find value in developing their own drivers.', None)
2022-02-10 17:20:02,496 [INFO] schedule: 'alert' max iterations (1) reached
In [9]:
from txtai.app import Application
workflow = """
writable: true
embeddings:
path: sentence-transformers/nli-mpnet-base-v2
content: true
summary:
path: sshleifer/distilbart-cnn-12-6
tabular:
idcolumn: url
textcolumns:
- title
textractor:
join: true
minlength: 100
paragraphs: true
translation:
__main__.Slack:
workflow:
index:
schedule:
cron: "* * * * * 0/5"
elements:
- front_page
iterations: 1
tasks:
- batch: false
extract:
- hits
method: get
params:
tags: null
task: service
url: https://hn.algolia.com/api/v1/search?hitsPerPage=50
- action: tabular
- action: upsert
alert:
schedule:
cron: 0/1 * * * *
elements:
- select id url, id title from txtai where similar('software development library') and score >= 0.4 and id like 'http%'
iterations: 1
tasks:
- action: search
- action: tabular
- action: textractor
- action: summary
- action: translation
args:
- fr
- action: __main__.Slack
unpack: false
"""
app = Application(workflow)
app.wait()2022-02-10 17:25:04,448 [INFO] schedule: 'index' scheduler started with schedule * * * * * 0/5
2022-02-10 17:25:04,449 [INFO] schedule: 'alert' scheduler started with schedule 0/1 * * * *
2022-02-10 17:25:04,451 [INFO] schedule: 'index' next run scheduled for 2022-02-10T17:25:05+00:00
2022-02-10 17:25:04,457 [INFO] schedule: 'alert' next run scheduled for 2022-02-10T17:26:00+00:00
2022-02-10 17:25:05,357 [INFO] schedule: 'index' max iterations (1) reached
2022-02-10 17:26:08,125 [INFO] __call__: Sending alert: ('https://datastation.multiprocess.io/blog/2022-02-08-the-world-of-postgresql-wire-compatibility.html', "Chaque base de données serveur-client a un protocole filaire. Un protocole filaire est le format pour les interactions entre un serveur de base de données et ses clients. Il n'inclut PAS le langage de requête réel lui-même, et encore moins la sémantique de la base de données.", None)
2022-02-10 17:26:08,310 [INFO] schedule: 'alert' max iterations (1) reached