如何使用生成式人工智能構(gòu)建實(shí)時(shí)Slackbot
譯文譯者 | 李睿
審校 | 重樓
本文將展示如何使用由Apache NiFi支持的Cloudera DataFlow與IBM WatsonX交互。人工智能實(shí)時(shí)建立大型語言模型,并且可以使用任何基礎(chǔ)模型,例如谷歌FLAN T5 XXL或IBM Granite模型。
本文將展示構(gòu)建實(shí)時(shí)數(shù)據(jù)管道是多么容易,它可以直接向開發(fā)人員的Slack和移動(dòng)應(yīng)用程序提供問題,以確保WatsonX的安全。在IBM云平臺(tái)中運(yùn)行的人工智能模型。開發(fā)人員可以使用Cloudera DataFlow處理所有的安全性、管理、沿襲和治理。作為決策的一部分,可以選擇不同的WatsonX。人工智能根據(jù)提示的類型進(jìn)行動(dòng)態(tài)建模。例如,如果想編寫內(nèi)容,而不是回答一個(gè)問題,可以選擇不同的模型?;卮鸸雀鐵LAN T5 XXL的問題效果很好。如果想繼續(xù)編寫內(nèi)容,可以使用一個(gè)IBM Granite模型。
人們會(huì)注意到WatsonX的速度有多快。人工智能模型返回開發(fā)人員需要的結(jié)果。這里進(jìn)行了一些快速的轉(zhuǎn)換和豐富內(nèi)容,然后將它們發(fā)送到Cloudera Apache Kafka,用于持續(xù)分析和分發(fā)到許多其他應(yīng)用程序、系統(tǒng)、平臺(tái)和下游消費(fèi)者。此外,還將向原始請求者輸出答案,這可能是Slack頻道中的某一個(gè)或應(yīng)用程序中的某一個(gè)。所有這些都是實(shí)時(shí)發(fā)生的,沒有代碼,沒有完整的治理、沿襲、數(shù)據(jù)管理和任何規(guī)模、任何平臺(tái)上的安全性。
IBM和Cloudera在私有云、公共云和混合云環(huán)境中對實(shí)時(shí)數(shù)據(jù)和人工智能的共同作用才剛剛開始。
逐步實(shí)時(shí)流程
首先,在Slack中輸入一個(gè)問題:“整合生成式AI和Apache NiFi的一個(gè)好方法是什么?”
NiFi Flow Top
一旦輸入這個(gè)問題,Slack服務(wù)器將這些事件發(fā)送到注冊的服務(wù)。它可以在任何面向公眾的地方托管。
- (點(diǎn)擊https://api.slack.com/查看Slack API鏈接)
Slack API
一旦啟用,服務(wù)器將開始接收每個(gè)Slack帖子的JSON事件。這在NiFi中很容易接收和解析。Cloudera DataFlow允許在公共云托管版本中輕松接收安全的HTTPS REST調(diào)用,即使在Designer模式下也是如此。
NiFi Top Flow 2
在NiFi Top Flow的第一部分中,接收到REST JSON Post,如下所示:
Slackbot 1.0 (+https://api.slack.com/robots)
application/json
POST
HTTP/1.1
{
"token" : "qHvJe59yetAp1bao6wmQzH0C",
"team_id" : "T1SD6MZMF",
"context_team_id" : "T1SD6MZMF",
"context_enterprise_id" : null,
"api_app_id" : "A04U64MN9HS",
"event" : {
"type" : "message",
"subtype" : "bot_message",
"text" : "==== NiFi to IBM <http://WatsonX.AI|WatsonX.AI> LLM Answers\n\nOn Date: Wed, 15 Nov 20
這是一個(gè)非常豐富詳細(xì)的JSON文件,可以立即將其作為JSON文檔推送到Apache Iceberg Open Cloud Lakehouse、Kafka主題或?qū)ο蟠鎯?chǔ)(增強(qiáng)選項(xiàng))。它只是解析開發(fā)人員所需要的。
EvaluateJSONPath
解析出通道ID和帖子的文本。如果只想要一般的消息(“C1SD6N197”),然后將文本復(fù)制到一個(gè)輸入字段,這是Hugging Face.所需的。
然后,檢查輸入:如果是股票或天氣(更多信息),避免調(diào)用LLM。
SELECT * FROM FLOWFILE
WHERE upper(inputs) like '%WEATHER%'
AND not upper(inputs) like '%LLM SKIPPED%'
SELECT * FROM FLOWFILE
WHERE upper(inputs) like '%STOCK%'
AND not upper(inputs) like '%LLM SKIPPED%'
SELECT * FROM FLOWFILE
WHERE (upper(inputs) like 'QUESTION:%'
OR upper(inputs) like 'Q:%') and not upper(inputs) like '%WEATHER%'
and not upper(inputs) like '%STOCK%'
對于庫存處理:
為了解析需要的庫存,使用Open NLP處理器來獲取它。
因此,需要下載處理器和實(shí)體提取模型。
- Github - tspannhw/nifi-nlp-processor: Apache NiFi NLP Processor
- Open NLP Example Apache NiFi Processor
然后,將公司名稱從AlphaVantage傳遞給HTTP REST端點(diǎn),該端點(diǎn)將公司名稱轉(zhuǎn)換為股票代碼。在免費(fèi)賬戶中,每天只接到幾個(gè)電話,所以如果失敗了,就會(huì)跳過這一步,嘗試使用輸入的任何內(nèi)容。
使用RouteOnContent,可以過濾掉錯(cuò)誤消息。
然后,使用QueryRecord處理器將CSV轉(zhuǎn)換為JSON并進(jìn)行過濾。
SELECT name as companyName, symbol FROM FLOWFILE
ORDER BY matchScore DESC
LIMIT 1
使用SplitRecord來確保只有一條記錄。然后運(yùn)行EvaluateJsonPath以獲取字段作為屬性。
在UpdateAttribute中,修剪符號(hào)以備不時(shí)之需。
${stockSymbol:trim()}
然后,通過InvokeHTTP將該股票代碼傳遞給Twelve Data以獲取股票數(shù)據(jù)。
然后,得到很多股票數(shù)據(jù)。
{
"meta" : {
"symbol" : "IBM",
"interval" : "1min",
"currency" : "USD",
"exchange_timezone" : "America/New_York",
"exchange" : "NYSE",
"mic_code" : "XNYS",
"type" : "Common Stock"
},
"values" : [ {
"datetime" : "2023-11-15 10:37:00",
"open" : "152.07001",
"high" : "152.08000",
"low" : "151.99500",
"close" : "152.00999",
"volume" : "8525"
}, {
"datetime" : "2023-11-15 10:36:00",
"open" : "152.08501",
"high" : "152.12250",
"low" : "152.08000",
"close" : "152.08501",
"volume" : "15204"
} ...
然后,運(yùn)行EvaluateJSONPath來獲取交換信息。
因?yàn)橹皇菫榱朔祷氐絊lack,分叉記錄只得到一條記錄。使用UpdateRecord調(diào)用其他值來豐富股票數(shù)據(jù)。然后運(yùn)行QueryRecord來限制只能發(fā)送一條記錄到Slack。
SELECT * FROM FLOWFILE
ORDER BY 'datetime' DESC
LIMIT 1
運(yùn)行EvaluateJsonPath來獲取要顯示的最多的值字段。
然后,用自己的消息運(yùn)行PutSlack。
LLM Skipped. Stock Value for ${companyName} [${nlp_org_1}/${stockSymbol}] on ${date} is ${closeStockValue}. stock date ${stockdateT
使用QueryRecord將RSS/XML記錄轉(zhuǎn)換為JSON。
然后,運(yùn)行一個(gè)SplitJSON來分解新聞項(xiàng)目。
https://feeds.finance.yahoo.com/rss/2.0/headline?s=${stockSymbol:trim()}?inotallow=US&lang=en-US
使用QueryRecord將RSS/XML記錄轉(zhuǎn)換為JSON。
然后,運(yùn)行一個(gè)SplitJSON來分解新聞項(xiàng)目。
運(yùn)行SplitRecord以限制為1條記錄。使用EvaluateJSONPath來獲取Slack消息所需的字段。
然后,運(yùn)行UpdateRecord來完成JSON。
然后,將這個(gè)消息發(fā)送到Slack。
LLM Skipped. Stock News Information for ${companyName} [${nlp_org_1}/${stockSymbol}] on ${date}
${title} : ${description}.
${guid} article date ${pubdate}
對于那些選擇天氣的人,對股票采取類似的做法(應(yīng)該使用Redis@Aiven添加緩存)。使用OpenNLP處理器來提取可能想要了解天氣的位置。
下一步是獲取處理器的輸出并構(gòu)建要發(fā)送到Geoencoder的值。
weatherlocation = ${nlp_location_1:notNull():ifElse(${nlp_location_1}, "New York City")}
如果找不到有效的地點(diǎn),就說"紐約市"可以用其他的查找方法。正在做一些關(guān)于加載所有位置的工作,并且可以在上面做一些高級(jí)PostgreSQL搜索-或者可能是OpenSearch或矢量化數(shù)據(jù)存儲(chǔ)。
將該位置傳遞給Open Meteo,通過InvokeHTTP找到地理位置。
然后,從結(jié)果中解析需要的值。
{
"results" : [ {
"id" : 5128581,
"name" : "New York",
"latitude" : 40.71427,
"longitude" : -74.00597,
"elevation" : 10.0,
"feature_code" : "PPL",
"country_code" : "US",
"admin1_id" : 5128638,
"timezone" : "America/New_York",
"population" : 8175133,
"postcodes" : [ "10001", "10002", "10003", "10004", "10005", "10006", "10007", "10008", "10009", "10010", "10011", "10012", "10013", "10014", "10016", "10017", "10018", "10019", "10020", "10021", "10022", "10023", "10024", "10025", "10026", "10027", "10028", "10029", "10030", "10031", "10032", "10033", "10034", "10035", "10036", "10037", "10038", "10039", "10040", "10041", "10043", "10044", "10045", "10055", "10060", "10065", "10069", "10080", "10081", "10087", "10090", "10101", "10102", "10103", "10104", "10105", "10106", "10107", "10108", "10109", "10110", "10111", "10112", "10113", "10114", "10115", "10116", "10117", "10118", "10119", "10120", "10121", "10122", "10123", "10124", "10125", "10126", "10128", "10129", "10130", "10131", "10132", "10133", "10138", "10150", "10151", "10152", "10153", "10154", "10155", "10156", "10157", "10158", "10159", "10160", "10161", "10162", "10163", "10164", "10165", "10166", "10167", "10168", "10169", "10170", "10171", "10172", "10173", "10174", "10175", "10176", "10177", "10178", "10179", "10185", "10199", "10203", "10211", "10212", "10213", "10242", "10249", "10256", "10258", "10259", "10260", "10261", "10265", "10268", "10269", "10270", "10271", "10272", "10273", "10274", "10275", "10276", "10277", "10278", "10279", "10280", "10281", "10282", "10285", "10286" ],
"country_id" : 6252001,
"country" : "United States",
"admin1" : "New York"
} ],
"generationtime_ms" : 0.92196465
}
然后,對結(jié)果進(jìn)行解析,這樣就可以調(diào)用另一個(gè)API,通過InvokeHTTP獲取該緯度和經(jīng)度的當(dāng)前天氣。
https://api.weather.gov/points/${latitude:trim()},${longitude:trim()}
其結(jié)果是geo-json。
{
"@context": [
"https://geojson.org/geojson-ld/geojson-context.jsonld",
{
"@version": "1.1",
"wx": "https://api.weather.gov/ontology#",
"s": "https://schema.org/",
"geo": "http://www.opengis.net/ont/geosparql#",
"unit": "http://codes.wmo.int/common/unit/",
"@vocab": "https://api.weather.gov/ontology#",
"geometry": {
"@id": "s:GeoCoordinates",
"@type": "geo:wktLiteral"
},
"city": "s:addressLocality",
"state": "s:addressRegion",
"distance": {
"@id": "s:Distance",
"@type": "s:QuantitativeValue"
},
"bearing": {
"@type": "s:QuantitativeValue"
},
"value": {
"@id": "s:value"
},
"unitCode": {
"@id": "s:unitCode",
"@type": "@id"
},
"forecastOffice": {
"@type": "@id"
},
"forecastGridData": {
"@type": "@id"
},
"publicZone": {
"@type": "@id"
},
"county": {
"@type": "@id"
}
}
],
"id": "https://api.weather.gov/points/40.7143,-74.006",
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-74.006,
40.714300000000001
]
},
"properties": {
"@id": "https://api.weather.gov/points/40.7143,-74.006",
"@type": "wx:Point",
"cwa": "OKX",
"forecastOffice": "https://api.weather.gov/offices/OKX",
"gridId": "OKX",
"gridX": 33,
"gridY": 35,
"forecast": "https://api.weather.gov/gridpoints/OKX/33,35/forecast",
"forecastHourly": "https://api.weather.gov/gridpoints/OKX/33,35/forecast/hourly",
"forecastGridData": "https://api.weather.gov/gridpoints/OKX/33,35",
"observationStations": "https://api.weather.gov/gridpoints/OKX/33,35/stations",
"relativeLocation": {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-74.0279259,
40.745251000000003
]
},
"properties": {
"city": "Hoboken",
"state": "NJ",
"distance": {
"unitCode": "wmoUnit:m",
"value": 3906.1522008034999
},
"bearing": {
"unitCode": "wmoUnit:degree_(angle)",
"value": 151
}
}
},
"forecastZone": "https://api.weather.gov/zones/forecast/NYZ072",
"county": "https://api.weather.gov/zones/county/NYC061",
"fireWeatherZone": "https://api.weather.gov/zones/fire/NYZ212",
"timeZone": "America/New_York",
"radarStation": "KDIX"
}
}
使用EvaluateJSONPath獲取預(yù)測URL。
然后,通過invokeHTTP調(diào)用預(yù)測URL。
這將生成一個(gè)更大的JSON輸出,將對其進(jìn)行解析,以便將結(jié)果返回給Slack。
{
"@context": [
"https://geojson.org/geojson-ld/geojson-context.jsonld",
{
"@version": "1.1",
"wx": "https://api.weather.gov/ontology#",
"geo": "http://www.opengis.net/ont/geosparql#",
"unit": "http://codes.wmo.int/common/unit/",
"@vocab": "https://api.weather.gov/ontology#"
}
],
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-74.025095199999996,
40.727052399999998
],
[
-74.0295579,
40.705361699999997
],
[
-74.000948300000005,
40.701977499999998
],
[
-73.996479800000003,
40.723667899999995
],
[
-74.025095199999996,
40.727052399999998
]
]
]
},
"properties": {
"updated": "2023-11-15T14:34:46+00:00",
"units": "us",
"forecastGenerator": "BaselineForecastGenerator",
"generatedAt": "2023-11-15T15:11:39+00:00",
"updateTime": "2023-11-15T14:34:46+00:00",
"validTimes": "2023-11-15T08:00:00+00:00/P7DT17H",
"elevation": {
"unitCode": "wmoUnit:m",
"value": 2.1335999999999999
},
"periods": [
{
"number": 1,
"name": "Today",
"startTime": "2023-11-15T10:00:00-05:00",
"endTime": "2023-11-15T18:00:00-05:00",
"isDaytime": true,
"temperature": 51,
"temperatureUnit": "F",
"temperatureTrend": null,
"probabilityOfPrecipitation": {
"unitCode": "wmoUnit:percent",
"value": null
},
"dewpoint": {
"unitCode": "wmoUnit:degC",
"value": 2.2222222222222223
},
"relativeHumidity": {
"unitCode": "wmoUnit:percent",
"value": 68
},
"windSpeed": "1 to 7 mph",
"windDirection": "SW",
"icon": "https://api.weather.gov/icons/land/day/bkn?size=medium",
"shortForecast": "Partly Sunny",
"detailedForecast": "Partly sunny, with a high near 51. Southwest wind 1 to 7 mph."
},
{
"number": 2,
"name": "Tonight",
"startTime": "2023-11-15T18:00:00-05:00",
"endTime": "2023-11-16T06:00:00-05:00",
"isDaytime": false,
"temperature": 44,
"temperatureUnit": "F",
"temperatureTrend": null,
"probabilityOfPrecipitation": {
"unitCode": "wmoUnit:percent",
"value": null
},
"dewpoint": {
"unitCode": "wmoUnit:degC",
"value": 3.8888888888888888
},
"relativeHumidity": {
"unitCode": "wmoUnit:percent",
"value": 82
},
"windSpeed": "8 mph",
"windDirection": "SW",
"icon": "https://api.weather.gov/icons/land/night/sct?size=medium",
"shortForecast": "Partly Cloudy",
"detailedForecast": "Partly cloudy, with a low around 44. Southwest wind around 8 mph."
},
{
"number": 3,
"name": "Thursday",
"startTime": "2023-11-16T06:00:00-05:00",
"endTime": "2023-11-16T18:00:00-05:00",
"isDaytime": true,
"temperature": 60,
"temperatureUnit": "F",
"temperatureTrend": "falling",
"probabilityOfPrecipitation": {
"unitCode": "wmoUnit:percent",
"value": null
},
"dewpoint": {
"unitCode": "wmoUnit:degC",
"value": 5.5555555555555554
},
"relativeHumidity": {
"unitCode": "wmoUnit:percent",
"value": 82
},
"windSpeed": "6 mph",
"windDirection": "SW",
"icon": "https://api.weather.gov/icons/land/day/few?size=medium",
"shortForecast": "Sunny",
"detailedForecast": "Sunny. High near 60, with temperatures falling to around 58 in the afternoon. Southwest wind around 6 mph."
},
{
"number": 4,
"name": "Thursday Night",
"startTime": "2023-11-16T18:00:00-05:00",
"endTime": "2023-11-17T06:00:00-05:00",
"isDaytime": false,
"temperature": 47,
"temperatureUnit": "F",
"temperatureTrend": null,
"probabilityOfPrecipitation": {
"unitCode": "wmoUnit:percent",
"value": null
},
"dewpoint": {
"unitCode": "wmoUnit:degC",
"value": 6.1111111111111107
},
"relativeHumidity": {
"unitCode": "wmoUnit:percent",
"value": 80
},
"windSpeed": "3 mph",
"windDirection": "SW",
"icon": "https://api.weather.gov/icons/land/night/few?size=medium",
"shortForecast": "Mostly Clear",
"detailedForecast": "Mostly clear, with a low around 47. Southwest wind around 3 mph."
},
{
"number": 5,
"name": "Friday",
"startTime": "2023-11-17T06:00:00-05:00",
"endTime": "2023-11-17T18:00:00-05:00",
"isDaytime": true,
"temperature": 63,
"temperatureUnit": "F",
"temperatureTrend": "falling",
"probabilityOfPrecipitation": {
"unitCode": "wmoUnit:percent",
"value": 20
},
"dewpoint": {
"unitCode": "wmoUnit:degC",
"value": 12.222222222222221
},
"relativeHumidity": {
"unitCode": "wmoUnit:percent",
"value": 86
},
"windSpeed": "2 to 10 mph",
"windDirection": "S",
"icon": "https://api.weather.gov/icons/land/day/bkn/rain,20?size=medium",
"shortForecast": "Partly Sunny then Slight Chance Light Rain",
"detailedForecast": "A slight chance of rain after 1pm. Partly sunny. High near 63, with temperatures falling to around 61 in the afternoon. South wind 2 to 10 mph. Chance of precipitation is 20%."
},
{
"number": 6,
"name": "Friday Night",
"startTime": "2023-11-17T18:00:00-05:00",
"endTime": "2023-11-18T06:00:00-05:00",
"isDaytime": false,
"temperature": 51,
"temperatureUnit": "F",
"temperatureTrend": null,
"probabilityOfPrecipitation": {
"unitCode": "wmoUnit:percent",
"value": 70
},
"dewpoint": {
"unitCode": "wmoUnit:degC",
"value": 12.777777777777779
},
"relativeHumidity": {
"unitCode": "wmoUnit:percent",
"value": 100
},
"windSpeed": "6 to 10 mph",
"windDirection": "SW",
"icon": "https://api.weather.gov/icons/land/night/rain,60/rain,70?size=medium",
"shortForecast": "Light Rain Likely",
"detailedForecast": "Rain likely. Cloudy, with a low around 51. Chance of precipitation is 70%. New rainfall amounts between a quarter and half of an inch possible."
},
{
"number": 7,
"name": "Saturday",
"startTime": "2023-11-18T06:00:00-05:00",
"endTime": "2023-11-18T18:00:00-05:00",
"isDaytime": true,
"temperature": 55,
"temperatureUnit": "F",
"temperatureTrend": null,
"probabilityOfPrecipitation": {
"unitCode": "wmoUnit:percent",
"value": 70
},
"dewpoint": {
"unitCode": "wmoUnit:degC",
"value": 11.111111111111111
},
"relativeHumidity": {
"unitCode": "wmoUnit:percent",
"value": 100
},
"windSpeed": "8 to 18 mph",
"windDirection": "NW",
"icon": "https://api.weather.gov/icons/land/day/rain,70/rain,30?size=medium",
"shortForecast": "Light Rain Likely",
"detailedForecast": "Rain likely before 1pm. Partly sunny, with a high near 55. Chance of precipitation is 70%."
},
{
"number": 8,
"name": "Saturday Night",
"startTime": "2023-11-18T18:00:00-05:00",
"endTime": "2023-11-19T06:00:00-05:00",
"isDaytime": false,
"temperature": 40,
"temperatureUnit": "F",
"temperatureTrend": null,
"probabilityOfPrecipitation": {
"unitCode": "wmoUnit:percent",
"value": null
},
"dewpoint": {
"unitCode": "wmoUnit:degC",
"value": 1.1111111111111112
},
"relativeHumidity": {
"unitCode": "wmoUnit:percent",
"value": 65
},
"windSpeed": "12 to 17 mph",
"windDirection": "NW",
"icon": "https://api.weather.gov/icons/land/night/few?size=medium",
"shortForecast": "Mostly Clear",
"detailedForecast": "Mostly clear, with a low around 40."
},
{
"number": 9,
"name": "Sunday",
"startTime": "2023-11-19T06:00:00-05:00",
"endTime": "2023-11-19T18:00:00-05:00",
"isDaytime": true,
"temperature": 50,
"temperatureUnit": "F",
"temperatureTrend": null,
"probabilityOfPrecipitation": {
"unitCode": "wmoUnit:percent",
"value": null
},
"dewpoint": {
"unitCode": "wmoUnit:degC",
"value": -0.55555555555555558
},
"relativeHumidity": {
"unitCode": "wmoUnit:percent",
"value": 65
},
"windSpeed": "10 to 14 mph",
"windDirection": "W",
"icon": "https://api.weather.gov/icons/land/day/few?size=medium",
"shortForecast": "Sunny",
"detailedForecast": "Sunny, with a high near 50."
},
{
"number": 10,
"name": "Sunday Night",
"startTime": "2023-11-19T18:00:00-05:00",
"endTime": "2023-11-20T06:00:00-05:00",
"isDaytime": false,
"temperature": 38,
"temperatureUnit": "F",
"temperatureTrend": null,
"probabilityOfPrecipitation": {
"unitCode": "wmoUnit:percent",
"value": null
},
"dewpoint": {
"unitCode": "wmoUnit:degC",
"value": -0.55555555555555558
},
"relativeHumidity": {
"unitCode": "wmoUnit:percent",
"value": 67
},
"windSpeed": "13 mph",
"windDirection": "NW",
"icon": "https://api.weather.gov/icons/land/night/few?size=medium",
"shortForecast": "Mostly Clear",
"detailedForecast": "Mostly clear, with a low around 38."
},
{
"number": 11,
"name": "Monday",
"startTime": "2023-11-20T06:00:00-05:00",
"endTime": "2023-11-20T18:00:00-05:00",
"isDaytime": true,
"temperature": 46,
"temperatureUnit": "F",
"temperatureTrend": null,
"probabilityOfPrecipitation": {
"unitCode": "wmoUnit:percent",
"value": null
},
"dewpoint": {
"unitCode": "wmoUnit:degC",
"value": -1.6666666666666667
},
"relativeHumidity": {
"unitCode": "wmoUnit:percent",
"value": 70
},
"windSpeed": "13 mph",
"windDirection": "NW",
"icon": "https://api.weather.gov/icons/land/day/sct?size=medium",
"shortForecast": "Mostly Sunny",
"detailedForecast": "Mostly sunny, with a high near 46."
},
{
"number": 12,
"name": "Monday Night",
"startTime": "2023-11-20T18:00:00-05:00",
"endTime": "2023-11-21T06:00:00-05:00",
"isDaytime": false,
"temperature": 38,
"temperatureUnit": "F",
"temperatureTrend": null,
"probabilityOfPrecipitation": {
"unitCode": "wmoUnit:percent",
"value": null
},
"dewpoint": {
"unitCode": "wmoUnit:degC",
"value": -1.1111111111111112
},
"relativeHumidity": {
"unitCode": "wmoUnit:percent",
"value": 70
},
"windSpeed": "10 mph",
"windDirection": "N",
"icon": "https://api.weather.gov/icons/land/night/sct?size=medium",
"shortForecast": "Partly Cloudy",
"detailedForecast": "Partly cloudy, with a low around 38."
},
{
"number": 13,
"name": "Tuesday",
"startTime": "2023-11-21T06:00:00-05:00",
"endTime": "2023-11-21T18:00:00-05:00",
"isDaytime": true,
"temperature": 49,
"temperatureUnit": "F",
"temperatureTrend": null,
"probabilityOfPrecipitation": {
"unitCode": "wmoUnit:percent",
"value": 30
},
"dewpoint": {
"unitCode": "wmoUnit:degC",
"value": 2.7777777777777777
},
"relativeHumidity": {
"unitCode": "wmoUnit:percent",
"value": 73
},
"windSpeed": "9 to 13 mph",
"windDirection": "E",
"icon": "https://api.weather.gov/icons/land/day/bkn/rain,30?size=medium",
"shortForecast": "Partly Sunny then Chance Light Rain",
"detailedForecast": "A chance of rain after 1pm. Partly sunny, with a high near 49. Chance of precipitation is 30%."
},
{
"number": 14,
"name": "Tuesday Night",
"startTime": "2023-11-21T18:00:00-05:00",
"endTime": "2023-11-22T06:00:00-05:00",
"isDaytime": false,
"temperature": 46,
"temperatureUnit": "F",
"temperatureTrend": null,
"probabilityOfPrecipitation": {
"unitCode": "wmoUnit:percent",
"value": 50
},
"dewpoint": {
"unitCode": "wmoUnit:degC",
"value": 7.7777777777777777
},
"relativeHumidity": {
"unitCode": "wmoUnit:percent",
"value": 86
},
"windSpeed": "13 to 18 mph",
"windDirection": "S",
"icon": "https://api.weather.gov/icons/land/night/rain,50?size=medium",
"shortForecast": "Chance Light Rain",
"detailedForecast": "A chance of rain. Mostly cloudy, with a low around 46. Chance of precipitation is 50%."
}
]
}
}
使用EvaluateJSONPath解析數(shù)據(jù),以獲取天氣的主要字段。
然后,將這些字段格式化為PutSlack。
LLM Skipped. Read forecast on ${date} for ${weatherlocation} @ ${latitude},${longitude}
Used ${forecasturl} ${icon} Temp: ${temperature} ${temperatureunit} - ${temperaturetrend}
There is a wind ${winddirection} at ${windspeed}. ${detailedforecast}
Slack 輸出
如果有LLM的問題,需要確保只有一條記錄。
使用IBM WatsonX上提供的幾種不同的模型。IBM云上的人工智能可以通過REST提示快速訪問。
最初在IBM的Prompt Lab測試并構(gòu)建了這些提示,然后從那里復(fù)制了初始的curl語句。
點(diǎn)擊https://www.ibm.com/docs/en/watsonx-as-a-service?topic=models-查看IBM watson .ai支持的基礎(chǔ)模型。
ibm/mpt-7b-instruct2
meta-llama/llama-2–70b-chat
ibm/granite-13b-chat-v1
在這里必須將唯一的安全密鑰發(fā)送給IBM,他們將提供一個(gè)令牌,以便在下次通話時(shí)使用。在解析出問題之后,通過REST API將其發(fā)送給WatsonX。
構(gòu)建一個(gè)發(fā)送到IBM的提示符,如下所示:
{
"model_id": "meta-llama/llama-2-70b-chat",
"input": "${inputs:urlEncode()}",
"parameters": {
"decoding_method": "greedy",
"max_new_tokens": 200,
"min_new_tokens": 50,
"stop_sequences": [],
"repetition_penalty": 1
},
"project_id": "0ead8ec4-d137-4f9c-8956-50b0da4a7068" }
解析生成的文本,這是生成式人工智能結(jié)果加上一些有用的時(shí)間元數(shù)據(jù)。
發(fā)布在Slack上的結(jié)果如下:
“可以使用Apache NiFi以多種方式集成生成式人工智能模型:
1.數(shù)據(jù)預(yù)處理:在將數(shù)據(jù)輸入生成式人工智能模型之前,使用NiFi對數(shù)據(jù)進(jìn)行預(yù)處理。這可以包括數(shù)據(jù)清理、轉(zhuǎn)換和特征工程。
2.模型訓(xùn)練:使用NiFi自動(dòng)化生成式人工智能模型的訓(xùn)練過程。你可以使用NiFi的PutFile和PutFile_SFTP處理器將訓(xùn)練數(shù)據(jù)寫入文件,然后使用ExecuteScript之類的處理器運(yùn)行訓(xùn)練腳本。
3.模型部署:一旦生成式人工智能模型得到訓(xùn)練,就可以使用NiFi來部署它。你可以創(chuàng)建一個(gè)NiFi流,它接受輸入數(shù)據(jù),通過生成式人工智能模型運(yùn)行它,然后輸出生成的數(shù)據(jù)。
4.實(shí)時(shí)推理:可以使用NiFi的StreamingJobs。
在發(fā)布了測試結(jié)果后,Slackbot將測試指標(biāo)和調(diào)試信息發(fā)布到聊天頻道。
所有元數(shù)據(jù)都被發(fā)布到另一個(gè)Slack頻道,供管理員監(jiān)控。
==== NiFi to IBM WatsonX.AI LLM Answers
On Date: Wed, 15 Nov 2023 15:43:29 GMT Created: 2023-11-15T15:43:29.248Z
Prompt: Q: What is a good way to integrate Generative AI and Apache NiFi?
Response: )
You can use Apache NiFi to integrate Generative AI models in several ways:
1. Data Preprocessing: Use NiFi to preprocess data before feeding it into your Generative AI model. This can include data cleaning, transformation, and feature engineering.
2. Model Training: Use NiFi to automate the training process of your Generative AI model. You can use NiFi's PutFile and PutFile_SFTP processors to write the training data to a file, and then use a processor like ExecuteScript to run the training script.
3. Model Deployment: Once your Generative AI model is trained, you can use NiFi to deploy it. You can create a NiFi flow that takes in input data, runs it through the Generative AI model, and then outputs the generated data.
4. Real-time Inference: You can use NiFi's StreamingJobs
Token: 200
Req Duration: 8153
HTTP TX ID: 89d71099-da23-4e7e-89f9-4e8f5620c0fb
IBM Msg: This model is a Non-IBM Product governed by a third-party license that may impose use restrictions and other obligations. By using this model you agree to its terms as identified in the following URL. URL: https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-models.html?cnotallow=wx
IBM Msg ID: disclaimer_warning
Model ID: meta-llama/llama-2-70b-chat
Stop Reason: max_tokens
Token Count: 38
TX ID: NGp0djg-c05f740f84f84b7c80f93f9da05aa756
UUID: da0806cb-6133-4bf4-808e-1fbf419c09e3
Corr ID: NGp0djg-c05f740f84f84b7c80f93f9da05aa756
Global TX ID: 20c3a9cf276c38bcdaf26e3c27d0479b
Service Time: 478
Request ID: 03c2726a-dcb6-407f-96f1-f83f20fe9c9c
File Name: 1a3c4386-86d2-4969-805b-37649c16addb
Request Duration: 8153
Request URL: https://us-south.ml.cloud.ibm.com/ml/v1-beta/generation/text?versinotallow=2023-05-29
cf-ray: 82689bfd28e48ce2-EWR
制作自己的Slackbot
Slack輸出
Kafka分布
Apache Flink SQL表創(chuàng)建DDL
CREATE TABLE `ssb`.`Meetups`.`watsonairesults` (
`date` VARCHAR(2147483647),
`x_global_transaction_id` VARCHAR(2147483647),
`x_request_id` VARCHAR(2147483647),
`cf_ray` VARCHAR(2147483647),
`inputs` VARCHAR(2147483647),
`created_at` VARCHAR(2147483647),
`stop_reason` VARCHAR(2147483647),
`x_correlation_id` VARCHAR(2147483647),
`x_proxy_upstream_service_time` VARCHAR(2147483647),
`message_id` VARCHAR(2147483647),
`model_id` VARCHAR(2147483647),
`invokehttp_request_duration` VARCHAR(2147483647),
`message` VARCHAR(2147483647),
`uuid` VARCHAR(2147483647),
`generated_text` VARCHAR(2147483647),
`transaction_id` VARCHAR(2147483647),
`tokencount` VARCHAR(2147483647),
`generated_token` VARCHAR(2147483647),
`ts` VARCHAR(2147483647),
`advisoryId` VARCHAR(2147483647),
`eventTimeStamp` TIMESTAMP(3) WITH LOCAL TIME ZONE METADATA FROM 'timestamp',
WATERMARK FOR `eventTimeStamp` AS `eventTimeStamp` - INTERVAL '3' SECOND
) WITH (
'deserialization.failure.policy' = 'ignore_and_log',
'properties.request.timeout.ms' = '120000',
'format' = 'json',
'properties.bootstrap.servers' = 'kafka:9092',
'connector' = 'kafka',
'properties.transaction.timeout.ms' = '900000',
'topic' = 'watsonxaillmanswers',
'scan.startup.mode' = 'group-offsets',
'properties.auto.offset.reset' = 'earliest',
'properties.group.id' = 'watsonxaillmconsumer'
)
CREATE TABLE `ssb`.`Meetups`.`watsonxresults` (
`date` VARCHAR(2147483647),
`x_global_transaction_id` VARCHAR(2147483647),
`x_request_id` VARCHAR(2147483647),
`cf_ray` VARCHAR(2147483647),
`inputs` VARCHAR(2147483647),
`created_at` VARCHAR(2147483647),
`stop_reason` VARCHAR(2147483647),
`x_correlation_id` VARCHAR(2147483647),
`x_proxy_upstream_service_time` VARCHAR(2147483647),
`message_id` VARCHAR(2147483647),
`model_id` VARCHAR(2147483647),
`invokehttp_request_duration` VARCHAR(2147483647),
`message` VARCHAR(2147483647),
`uuid` VARCHAR(2147483647),
`generated_text` VARCHAR(2147483647),
`transaction_id` VARCHAR(2147483647),
`tokencount` VARCHAR(2147483647),
`generated_token` VARCHAR(2147483647),
`ts` VARCHAR(2147483647),
`eventTimeStamp` TIMESTAMP(3) WITH LOCAL TIME ZONE METADATA FROM 'timestamp',
WATERMARK FOR `eventTimeStamp` AS `eventTimeStamp` - INTERVAL '3' SECOND
) WITH (
'deserialization.failure.policy' = 'ignore_and_log',
'properties.request.timeout.ms' = '120000',
'format' = 'json',
'properties.bootstrap.servers' = 'kafka:9092',
'connector' = 'kafka',
'properties.transaction.timeout.ms' = '900000',
'topic' = 'watsonxaillm',
'scan.startup.mode' = 'group-offsets',
'properties.auto.offset.reset' = 'earliest',
'properties.group.id' = 'allwatsonx1'
)
提示例子
{"inputs":"Please answer to the following question. What is the capital of the United States?"}
IBM DB2 SQL
alter table "DB2INST1"."TRAVELADVISORY"
add column "summary" VARCHAR(2048);
-- DB2INST1.TRAVELADVISORY definition
CREATE TABLE "DB2INST1"."TRAVELADVISORY" (
"TITLE" VARCHAR(250 OCTETS) ,
"PUBDATE" VARCHAR(250 OCTETS) ,
"LINK" VARCHAR(250 OCTETS) ,
"GUID" VARCHAR(250 OCTETS) ,
"ADVISORYID" VARCHAR(250 OCTETS) ,
"DOMAIN" VARCHAR(250 OCTETS) ,
"CATEGORY" VARCHAR(4096 OCTETS) ,
"DESCRIPTION" VARCHAR(4096 OCTETS) ,
"UUID" VARCHAR(250 OCTETS) NOT NULL ,
"TS" BIGINT NOT NULL ,
"summary" VARCHAR(2048 OCTETS) )
IN "IBMDB2SAMPLEREL"
ORGANIZE BY ROW;
ALTER TABLE "DB2INST1"."TRAVELADVISORY"
ADD PRIMARY KEY
("UUID")
ENFORCED;
GRANT CONTROL ON TABLE "DB2INST1"."TRAVELADVISORY" TO USER "DB2INST1";
GRANT CONTROL ON INDEX "SYSIBM "."SQL230620142604860" TO USER "DB2INST1";
SELECT "summary", TITLE , ADVISORYID , TS, PUBDATE FROM DB2INST1.TRAVELADVISORY t
WHERE "summary" IS NOT NULL
ORDER BY ts DESC
輸出示例
GitHub README
源代碼
原文標(biāo)題:Building a Real-Time Slackbot With Generative AI,作者:Tim Spann