-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
js_release_alpha/1.5.12 #1314
js_release_alpha/1.5.12 #1314
Conversation
Reviewer ChecklistPlease leverage this checklist to ensure your code review is thorough before approving Testing, Bugs, Errors, Logs, Documentation
System Compatibility
Quality
|
this.api_key = cohere_api_key; | ||
this.model = model || "large"; | ||
} | ||
|
||
public async generate(texts: string[]) { | ||
const response = await CohereAiApi.embed({ | ||
|
||
if (this.cohereAiApi === 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.
I would move this part into the import function. Because it is import logic and not generation logic. It would make the generate function cleaner if you would do
await CohereEmbeddingFunction.import();
const response = await this.cohereAiApi.embed({
The import function would then immediately return if the package is already imported.
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.
you could move it to another function called "loadClient"
something like
private async loadClient(){
if(this.cohereAiApi) return;
try {
// eslint-disable-next-line global-require,import/no-extraneous-dependencies
const { cohere } = await CohereEmbeddingFunction.import();
CohereAiApi = cohere;
CohereAiApi.init(this.api_key);
} catch (_a) {
// @ts-ignore
if (_a.code === 'MODULE_NOT_FOUND') {
throw new Error("Please install the cohere-ai package to use the CohereEmbeddingFunction, `npm install -S cohere-ai`");
}
throw _a; // Re-throw other errors
}
this.cohereAiApi = CohereAiApi;
}
}
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.
i like this change - thanks! will implement
So this is really dumb, but we ended up having to move off of |
alas- fix one thing, another nasty issue presents its head. i will continue to debug this. |
clients/js/tsconfig.json
Outdated
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.
i think this was the main part where I got ESM/CJS error.
using ESNext certainly can fix it
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.
if you consider 'chromadb' is a CommonJS module
as the main problem:
import { ChromaClient } from 'chromadb';
^^^^^^^^^^^^
SyntaxError: Named export 'ChromaClient' not found. The requested module 'chromadb' is a CommonJS module, which may not support all module.exports as named exports. ai
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'chromadb';
const { ChromaClient } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)
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.
@jexroid i dont quite understand - do you approve of this PR or do you think we should do it a different way?
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.
No, the best considerations have been made. here is what I mean:
as you can see in the last code we had: "module": "CommonJS"
. which tells typescript to ONLY
use Commonjs, no matter what you have been told to package.json module to do. it will return you commonjs type for your javascript which will not allow you to use:
import { ChromaClient } from 'chromadb';
because It's not commonjs but it's the module type and you will get :
SyntaxError: Named export 'ChromaClient' not found. The requested module 'chromadb' is a CommonJS module, which may not support all module.exports as named exports. ai
CommonJS modules can always be imported via the default export, for example using:
but when @perzeuss changed it to ESNext
, it told typescript to use a standard and support version of module type. here is a link that can help you with ESNext
:
microsoft/TypeScript#24082
https://www.typescriptlang.org/tsconfig#target
from my perspective, this was the Main problem that causes ESM/Commonjs syntax error.
if there is any other misunderstanding that you need to be sure about, I would be pleased to help
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 main problem was in tsconfig and ESNext will fix it
yarn.lock
Outdated
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.
can be removed?!
clients/js/package-lock.json
Outdated
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.
you should commit this file, if you remove yarn.lock
yarn | ||
yarn test:run | ||
|
||
# moved off of yarn to npm to fix issues with jackspeak/cliui/string-width versions #1314 |
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.
what is this jackspeak/cliui/string-width
issue about?
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.
if you google it - there is a bunch about it - eg
Trying to get tests to cooperate |
should be stacked on top of #1305
merge #1305 first
to ship this, we are removing
WebAI
andTransformers
support (they are much trickier). They will be added back soon.