docs(tools): add Xquik examples#1456
Conversation
Signed-off-by: kriptoburak <kriptoburak@users.noreply.github.com>
There was a problem hiding this comment.
Code Review
This pull request introduces the Xquik API tool for searching X posts, providing implementations in both Python and TypeScript. The Python implementation uses urllib and asyncio.to_thread to handle requests, while the TypeScript version utilizes DynamicTool and the fetch API. Review feedback suggests improving the robustness of UTF-8 decoding in the Python code to handle malformed data and guarding the execution logic in the TypeScript file to prevent side effects when the module is imported by other components.
| ) | ||
| try: | ||
| with urlopen(request, timeout=30) as response: | ||
| body = response.read().decode("utf-8") |
There was a problem hiding this comment.
The response body is decoded using utf-8 without error handling. If the API returns malformed UTF-8 or a different encoding, this will raise a UnicodeDecodeError. For better robustness and consistency with the error handling on line 36, consider using errors="replace".
| body = response.read().decode("utf-8") | |
| body = response.read().decode("utf-8", errors="replace") |
| if (!process.env.XQUIK_API_KEY) { | ||
| console.log("Set XQUIK_API_KEY to run this example."); | ||
| } else { | ||
| const result = await xquikSearchTweetsTool.run({ | ||
| query: "from:xquikcom", | ||
| limit: 5, | ||
| }); | ||
| console.log(result.getTextContent()); | ||
| } |
There was a problem hiding this comment.
The example execution logic at the end of the file runs immediately upon module import. Since xquikSearchTweetsTool is exported, this can cause unexpected side effects (such as network requests) if the tool is imported by other modules or tests. Consider guarding this block to ensure it only runs when the file is executed directly, similar to the if __name__ == "__main__": pattern used in the Python example.
Signed-off-by: kriptoburak <kriptoburak@users.noreply.github.com>
|
Addressed the review feedback in
Focused validation reran successfully: Python 3.11 compile, Ruff check, Prettier check, esbuild parse/bundle, |
Which issue(s) does this pull-request address?
Closes: N/A
This is an examples-only addition for using a custom BeeAI tool with an authenticated external REST API.
Description
Adds Xquik search examples for both BeeAI Framework runtimes:
python/examples/tools/custom/xquik.pytypescript/examples/tools/custom/xquik.tsThe examples call
GET /x/tweets/searchwithXQUIK_API_KEY, optionalXQUIK_BASE_URL, and no new package dependencies.Validation
python3.11 -m py_compile python/examples/tools/custom/xquik.pyruff check --config python/pyproject.toml python/examples/tools/custom/xquik.py python/examples/README.mdprettier@3.6.2 --check typescript/examples/tools/custom/xquik.ts python/examples/README.md typescript/examples/README.mdesbuild@0.27.2 typescript/examples/tools/custom/xquik.ts --bundle --platform=node --format=esm '--external:beeai-framework/*' --external:zodgit diff --checkI could not run
mise check,mise test:unit, ormise test:e2elocally because this checkout does not have the project's mise or yarn toolchain installed. The added examples were kept dependency-free and validated with focused syntax, formatting, and parse checks.Checklist
General
Pythonfor Python changes,TypeScriptfor TypeScript changesCode quality checks
mise check(mise fixto auto-fix)Testing
mise test:unitmise test:e2eDocumentation
mise docs:fix