forked from TBXark/ChatGPT-Telegram-Workers
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: optimize tool processing. allowing different types of processin…
…g methods, template parsing supports complete plugin syntax chore: optimize audio processing chore: split built-in app in-app purchase queries
- Loading branch information
Showing
14 changed files
with
239 additions
and
124 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
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 |
---|---|---|
@@ -1,42 +1,46 @@ | ||
{ | ||
"schema": { | ||
"name": "app_iap", | ||
"description": "Search for an app in App Store and retrieve its IAP information.", | ||
"description": "Retrive detailed in-app purchase information based on country code, app id.", | ||
"parameters": { | ||
"type": "object", | ||
"properties": { | ||
"app_name": { | ||
"type": "string", | ||
"description": "The name of the app to search for in App Store", | ||
"examples": ["WeChat", "YouTube"] | ||
}, | ||
"country": { | ||
"type": "string", | ||
"description": "The country code for App Store search", | ||
"default": "us", | ||
"examples": ["us", "cn", "jp"] | ||
"examples": [ | ||
"us", | ||
"cn", | ||
"tr", | ||
"ng" | ||
] | ||
}, | ||
"trackId": { | ||
"type": "string", | ||
"description": "The trackId to be queried", | ||
"examples": ["363590051"] | ||
} | ||
}, | ||
"required": ["app_name", "country"], | ||
"required": [ | ||
"country", | ||
"trackId" | ||
], | ||
"additionalProperties": false | ||
} | ||
}, | ||
"payload": { | ||
"url": "https://itunes.apple.com/search?entity=software&limit=1&term={{app_name}}&country={{country}}&fields=trackId,trackCensoredName", | ||
"method": "GET", | ||
"headers": { | ||
"Accept": "application/json" | ||
} | ||
"url": "https://apps.apple.com/{{country}}/app/id{{trackId}}" | ||
}, | ||
"webcrawler": { | ||
"template": "{{results[0].trackViewUrl}}", | ||
"handler": { | ||
"type": "webclean", | ||
"patterns": [ | ||
{ | ||
"pattern": "<li class=\\\"list-with-numbers__item\\\">([\\s\\S]+?)<\\/li>", | ||
"group": 1, | ||
"cleanPattern": "<[^>]*>?" | ||
"clean": ["<[^>]*>?", ""] | ||
} | ||
] | ||
} | ||
|
||
}, | ||
"prompt": "Please provide the detailed in-app purchase information for the app in the specified country. The default regions that users want to follow include Turkey and Nigeria, two low-cost areas, unless the user explicitly does not need to query these two regions." | ||
} |
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"schema": { | ||
"name": "app_lookup", | ||
"description": "Retrive five sets of related app id and app name through region code and keywords. The app id is consistent across different countries. Only one piece of data is valid.", | ||
"parameters": { | ||
"type": "object", | ||
"properties": { | ||
"app_name": { | ||
"type": "string", | ||
"description": "The name of the app to search for in App Store", | ||
"examples": [ | ||
"WeChat", | ||
"YouTube" | ||
] | ||
}, | ||
"country": { | ||
"type": "string", | ||
"description": "The country code for App Store search", | ||
"default": "us", | ||
"examples": [ | ||
"us", | ||
"cn", | ||
"jp" | ||
] | ||
}, | ||
"entity": { | ||
"type": "string", | ||
"description": "Types of search software", | ||
"default": "software", | ||
"enum": [ | ||
"software", | ||
"iPadSoftware", | ||
"macSoftware" | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"app_name", | ||
"country", | ||
"entity" | ||
], | ||
"additionalProperties": false | ||
} | ||
}, | ||
"payload": { | ||
"url": "https://itunes.apple.com/search?entity={{entity}}&limit=3&term={{app_name}}&country={{country}}&fields=trackId,trackCensoredName", | ||
"method": "GET", | ||
"headers": { | ||
"Accept": "application/json" | ||
} | ||
}, | ||
"handler": { | ||
"type": "template", | ||
"data": "{{#each i in results}}{\"trackId\":{{i.trackId}},\"trackName\":\"{{i.trackName}}\",\"primaryGenreName\":{{i.primaryGenreName}}}{{/each}}" | ||
}, | ||
"prompt": "This tool should only be called once, and the app ID is the same in different regions. You should select the most relevant one." | ||
} |
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,6 +1,7 @@ | ||
import app_iap from './app_iap.json'; | ||
import app_lookup from './app_lookup.json'; | ||
import jina_reader from './jina.json'; | ||
import qw_lookup from './lookup.json'; | ||
import qw_weather from './qweather.json'; | ||
|
||
export default { app_iap, jina_reader, qw_lookup, qw_weather }; | ||
export default { app_iap, app_lookup, jina_reader, qw_lookup, qw_weather }; |
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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { PatternInfo } from '../types'; | ||
import { log } from '../../log/logger'; | ||
import { interpolate } from '../../plugins/interpolate'; | ||
|
||
export function processHtmlText(patterns: PatternInfo[], text: string): string { | ||
let results: string[] = [text]; | ||
for (const { pattern, group = 0, clean } of patterns) { | ||
results = results.flatMap((text) => { | ||
const regex = new RegExp(pattern, 'g'); | ||
const matches = Array.from(text.matchAll(regex)); | ||
return matches.map((match) => { | ||
let extractedText = match[group]; | ||
if (clean) { | ||
const cleanRegex = new RegExp(clean[0], 'g'); | ||
extractedText = extractedText.replace(cleanRegex, clean[1] ?? ''); | ||
} | ||
return extractedText.replace(/\s+/g, ' ').trim(); | ||
}); | ||
}); | ||
} | ||
return results.join('\n'); | ||
} | ||
|
||
export interface WebCrawlerInfo { | ||
url: string; | ||
patterns?: PatternInfo[]; | ||
} | ||
|
||
export async function webCrawler(webcrawler: WebCrawlerInfo, data: Record<string, any>) { | ||
let result: string | Record<string, any> = ''; | ||
const url = interpolate(webcrawler.url, data); | ||
log.info(`webcrawler url: ${url}`); | ||
const resp = await fetch(url).then(r => r.text()); | ||
result = { | ||
result: processHtmlText(webcrawler.patterns || [], resp), | ||
source: url, | ||
}; | ||
return result; | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.