-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
split cli #586
Conversation
@@ -548,7 +548,7 @@ defTool("math_eval", "Evaluates a math expression", { | |||
required: ["expression"], | |||
}, async (args) => { | |||
const { expression } = args | |||
return "" + (parsers.math(expression) ?? "?") | |||
return "" + (await parsers.math(expression) ?? "?") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parsers.math
function is now awaited, but the containing function is not marked as async
.
generated by pr-docs-review-commit
async_missing
) | ||
} | ||
if (!this._azureToken) | ||
this._azureToken = await createAzureToken(signal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no error handling for the createAzureToken
function. If it fails, the error will not be caught and handled properly, which could lead to unexpected behavior. Consider adding a try-catch block around this function call. 😊
generated by pr-review-commit
missing_error_handling
@@ -94,7 +95,8 @@ export function createParsers(options: { | |||
await resolveFileContent(file, { trace }) | |||
return await treeSitterQuery(file, query, { trace }) | |||
}, | |||
math: (expression) => MathTryEvaluate(expression, { trace }), | |||
math: async (expression) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The math
function is declared as async but there is no await keyword used in its body. This could lead to unexpected behavior as the function might not wait for promises to resolve before continuing execution. Please ensure that the async keyword is used correctly. 😊
generated by pr-review-commit
async_without_await
try { | ||
return XLSXParse(data, options) | ||
return await XLSXParse(data, options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no error handling for the XLSXParse
function. If it fails, the error will not be caught and handled properly, which could lead to unexpected behavior. Consider adding a try-catch block around this function call. 😊
generated by pr-review-commit
missing_error_handling
@@ -210,7 +210,7 @@ const captures = await parsers.code(file, "(interface_declaration) @i") | |||
The `parsers.math` function uses [mathjs](https://mathjs.org/) to parse a math expression. | |||
|
|||
```js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parsers.math
function should be used with await
as it returns a Promise.
generated by pr-docs-review-commit
await_usage
@@ -548,7 +548,7 @@ defTool("math_eval", "Evaluates a math expression", { | |||
required: ["expression"], | |||
}, async (args) => { | |||
const { expression } = args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parsers.math
function should be used with await
as it returns a Promise.
generated by pr-docs-review-commit
await_usage
@@ -15,6 +13,7 @@ export async function DOCXTryParse( | |||
): Promise<string> { | |||
const { trace } = options || {} | |||
try { | |||
const { extractRawText } = await import("mammoth") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dynamic import of "mammoth" module is used. This could lead to performance issues as it might cause delays in execution. Consider importing the module at the top of the file if it does not have side effects. 😊
generated by pr-review-commit
dynamic_import
@@ -94,7 +95,8 @@ export function createParsers(options: { | |||
await resolveFileContent(file, { trace }) | |||
return await treeSitterQuery(file, query, { trace }) | |||
}, | |||
math: (expression) => MathTryEvaluate(expression, { trace }), | |||
math: async (expression) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The math
function is now asynchronous but the function signature in the interface Parsers
in packages/core/src/types/prompt_template.d.ts
has not been updated to reflect this change. This could lead to confusion and potential bugs. Please update the interface to match the implementation. 😊
generated by pr-review-commit
async_function
The changes in the pull request consist of the following modifications:
The changes look good overall with the following specific observations:
However, one potential concern that I have is with error handling. The updates added several For example: +export async function MathTryEvaluate(
expr: string,
options?: { defaultValue?: number } & TraceOptions
-): string | number | undefined {
+): Promise<string | number | undefined> {
const { trace, defaultValue } = options || {}
try {
if (!expr) return defaultValue
+ const { evaluate } = await import("mathjs")
const res = evaluate(expr)
return res
} catch (e) { In the above code snippet, if This could be handled by updating the code to: export async function MathTryEvaluate(
expr: string,
options?: { defaultValue?: number } & TraceOptions
): Promise<string | number | undefined> {
const { trace, defaultValue } = options || {}
try {
if (!expr) return defaultValue
+ let evaluate;
+ try {
+ const mathjs = await import("mathjs");
+ evaluate = mathjs.evaluate;
+ } catch (e) {
+ console.error(`Failed to import mathjs: ${e}`);
+ return defaultValue;
+ }
const res = evaluate(expr)
return res
} catch (e) { So, with the exception of the missing error handling for promises, the changes look fine. Apart from this, LGTM 🚀.
|
@@ -272,14 +272,6 @@ for the current model. This is useful for estimating the number of prompts that | |||
const count = parsers.tokens("...") | |||
``` | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The section on parsers.math
is duplicated and should be removed as it is already defined under the .env
section.
generated by pr-docs-review-commit
duplicate_section
@@ -210,7 +210,7 @@ const captures = await parsers.code(file, "(interface_declaration) @i") | |||
The `parsers.math` function uses [mathjs](https://mathjs.org/) to parse a math expression. | |||
|
|||
```js | |||
const res = parsers.math("1 + 1") | |||
const res = await parsers.math("1 + 1") | |||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parsers.math
function usage example should use await
consistently with the function being asynchronous.
generated by pr-docs-review-commit
async_mismatch
@@ -548,7 +548,7 @@ defTool("math_eval", "Evaluates a math expression", { | |||
required: ["expression"], | |||
}, async (args) => { | |||
const { expression } = args | |||
return "" + (parsers.math(expression) ?? "?") | |||
return "" + (await parsers.math(expression) ?? "?") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parsers.math
function usage example should use await
consistently with the function being asynchronous.
generated by pr-docs-review-commit
async_mismatch
@@ -49,13 +49,14 @@ export function createParsers(options: { | |||
CSV: (text, options) => | |||
CSVTryParse(filenameOrFileToContent(text), options), | |||
XLSX: async (file, options) => | |||
XLSXTryParse(await host.readFile(file?.filename), options), | |||
await XLSXTryParse(await host.readFile(file?.filename), options), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The XLSXTryParse
function is async and returns a promise, but it's not being awaited here. This could lead to unexpected behavior. Please add await
before XLSXTryParse
. 🔄
generated by pr-review-commit
async_await
@@ -984,7 +984,7 @@ interface Parsers { | |||
* Parses and evaluates a math expression | |||
* @param expression math expression compatible with mathjs | |||
*/ | |||
math(expression: string): string | number | undefined | |||
math(expression: string): Promise<string | number | undefined> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The math
function in the Parsers
interface is declared to return a Promise<string | number | undefined>
, but the actual implementation of the function in parsers.ts
returns string | number | undefined
. This discrepancy could lead to type errors. Please ensure that the function's return type matches its implementation. 😊
generated by pr-review-commit
incorrect_type
const { trace, defaultValue } = options || {} | ||
try { | ||
if (!expr) return defaultValue | ||
const { evaluate } = await import("mathjs") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dynamic import of 'mathjs' can lead to performance issues and makes the code harder to statically analyze. Consider importing this module at the top of the file if it does not have side effects. 😊
generated by pr-review-commit
dynamic_import
@@ -49,13 +49,14 @@ export function createParsers(options: { | |||
CSV: (text, options) => | |||
CSVTryParse(filenameOrFileToContent(text), options), | |||
XLSX: async (file, options) => | |||
XLSXTryParse(await host.readFile(file?.filename), options), | |||
await XLSXTryParse(await host.readFile(file?.filename), options), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The await
inside the XLSXTryParse
function call is inside a loop. This can lead to performance issues as it forces each iteration of the loop to wait for the promise to resolve before continuing. Consider refactoring this code to use Promise.all
to allow the promises to resolve concurrently. 😊
generated by pr-review-commit
await_in_loop
@@ -210,7 +210,7 @@ const captures = await parsers.code(file, "(interface_declaration) @i") | |||
The `parsers.math` function uses [mathjs](https://mathjs.org/) to parse a math expression. | |||
|
|||
```js | |||
const res = parsers.math("1 + 1") | |||
const res = await parsers.math("1 + 1") | |||
``` | |||
|
|||
## .env |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate section 'math' in documentation.
generated by pr-docs-review-commit
duplicate_section
@@ -49,13 +49,14 @@ export function createParsers(options: { | |||
CSV: (text, options) => | |||
CSVTryParse(filenameOrFileToContent(text), options), | |||
XLSX: async (file, options) => | |||
XLSXTryParse(await host.readFile(file?.filename), options), | |||
await XLSXTryParse(await host.readFile(file?.filename), options), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The XLSXTryParse
function is asynchronous and returns a promise, but it's not being awaited here. This could lead to unexpected behavior. Please use the await
keyword to ensure the promise is resolved before proceeding. 🔄
generated by pr-review-commit
async_await_usage
@@ -984,7 +984,7 @@ interface Parsers { | |||
* Parses and evaluates a math expression | |||
* @param expression math expression compatible with mathjs | |||
*/ | |||
math(expression: string): string | number | undefined | |||
math(expression: string): Promise<string | number | undefined> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the return type of the math
function from string | number | undefined
to Promise<string | number | undefined>
is a breaking change. This could break existing code that uses this function.
generated by pr-review-commit
breaking_change
const { trace, defaultValue } = options || {} | ||
try { | ||
if (!expr) return defaultValue | ||
const { evaluate } = await import("mathjs") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The evaluate
function from mathjs
is called without any error handling. If the evaluation fails (for example, if the expression is not valid), an unhandled exception will be thrown. Consider adding error handling to improve the robustness of the code. 😊
generated by pr-review-commit
missing_error_handling
@@ -49,13 +49,14 @@ export function createParsers(options: { | |||
CSV: (text, options) => | |||
CSVTryParse(filenameOrFileToContent(text), options), | |||
XLSX: async (file, options) => | |||
XLSXTryParse(await host.readFile(file?.filename), options), | |||
await XLSXTryParse(await host.readFile(file?.filename), options), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The XLSXTryParse
function is now asynchronous, but it's called without await
here. This could lead to unexpected behavior as the function might not have completed before its result is used. Consider adding await
before the function call. 😊
generated by pr-review-commit
missing_await
@@ -210,7 +210,7 @@ const captures = await parsers.code(file, "(interface_declaration) @i") | |||
The `parsers.math` function uses [mathjs](https://mathjs.org/) to parse a math expression. | |||
|
|||
```js | |||
const res = parsers.math("1 + 1") | |||
const res = await parsers.math("1 + 1") | |||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parsers.math
function call should be awaited with async
.
generated by pr-docs-review-commit
async_missing
@@ -49,13 +49,14 @@ export function createParsers(options: { | |||
CSV: (text, options) => | |||
CSVTryParse(filenameOrFileToContent(text), options), | |||
XLSX: async (file, options) => | |||
XLSXTryParse(await host.readFile(file?.filename), options), | |||
await XLSXTryParse(await host.readFile(file?.filename), options), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The XLSX
function is declared as async but there is no await keyword used in its body. This might lead to unexpected behavior. Please ensure that the function is using the await keyword correctly. 🧐
generated by pr-review-commit
async_function_without_await
@@ -15,6 +13,7 @@ export async function DOCXTryParse( | |||
): Promise<string> { | |||
const { trace } = options || {} | |||
try { | |||
const { extractRawText } = await import("mammoth") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mammoth
module is dynamically imported but there is no check to ensure that the module is actually installed. Consider adding a check to ensure that the module is installed before importing it.
generated by pr-review-commit
missing_dependency
Improve startup time by moving various non-critical dependencies as dynamic imports
math_eval
tool has been updated in two ways. First, insystem.mdx
anawait
keyword has been added when calling theparsers.math
function, indicating that this is now an asynchronous operation 🔄. Second, insystem.math.genai.js
similarly, anawait
has been added when callingparsers.math
, again suggesting this function is now asynchronous.mathjs
has been added as a dependency in thepackage.json
of packagescli
andcore
, likely to provide advanced math operations for the application 🧮.azuretoken.ts
file has been created in thepackages/cli/src
directory. This looks to be handling Azure token creation logic, by importing theDefaultAzureCredential
from@azure/identity
🆔.nodehost.ts
has been updated with the content from the newly addedazuretoken.ts
file. This suggests a refactoring of the Azure token logic into its own module for better code organization and reuse ⌗.mammoth
for docx parsing andmathjs
for math operations) have been changed to dynamic imports, likely to help improve application startup performance by only loading the actual module code when it's needed (lazy-loading) 🚀.xlsx
file parser has been changed from a synchronous function to an async function. This will allow the .xlsx parsing to occur in asynchronous manner, likely improving the performance of this operation in the system 📊.cli
&core
'spackage.json
by increasing the indentation of the file content, making it easier to read 📝.