Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Feature/ts tsup #73

Closed
wants to merge 15 commits into from
Closed

Conversation

JamieLee0510
Copy link

this PR is for refactor original javascript version to typescript + tsup;
also contain test cases, but example cases not yet.

@JamieLee0510 JamieLee0510 mentioned this pull request May 8, 2024
@JamieLee0510
Copy link
Author

Have updated this pr from current diff

Copy link
Contributor

@fuegoio fuegoio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your work! 🎉

Some high-level note: we should I think remove jest and replace it by vitest, especially to get rid of babel as a dependency.

src/utils/init-fetch.ts Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you combine the JSDoc with the Typescript definitions please :)? You need to add the fields description as comments above fields in the TS def.

const mockResponse = mockChatResponsePayload();
client._fetch = mockFetch(200, mockResponse);
globalThis.fetch = mockFetch(200, mockResponse) as any;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment above but let's use a private fetch only for our package!

total_tokens: number;
completion_tokens: number;
};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to put the interfaces again here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just clean it in further commit.

shims:true,
skipNodeModulesBundle:true,
clean:true
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it build with source maps as well?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes could build source map in tsup.

@JamieLee0510
Copy link
Author

JamieLee0510 commented May 14, 2024

Some high-level note: we should I think remove jest and replace it by vitest, especially to get rid of babel as a dependency.

Currently I still use jest but get rid of babel by jest config setting preset: 'ts-jest/presets/default-esm', which could work fine as well.

please kindly help check the updated PR :)

this.endpoint = endpoint;
this.apiKey = apiKey;
export default class MistralClient {
private apiKey: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for better or worse, these were public fields in the .d.ts file from 0.2

*/
async _fetch(...args) {
public async _fetch(input: string | Request, init?: RequestInit){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be private. You can access it in the tests as client['_fetch']

return response.body;
} else {
const reader = response.body.getReader();
}else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like formatting needs running? }els {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one I think it might need something like .prettierrc config to align formatting afterwards.
I have noticed that there was a pr related with single-quote.

await new Promise((resolve) =>
setTimeout(resolve, Math.pow(2, (attempts + 1)) * 500),
);
console.debug(`Retrying request on response status: ${response.status}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've dropped some of the text here:
"""
Response: ${await response.text()},
Attempt: ${attempts + 1},
"""

@JamieLee0510
Copy link
Author

all issues raised by @sublimator in previous batch have been resolved, thanks :)

@sublimator
Copy link
Contributor

sublimator commented May 14, 2024 via email

@sublimator
Copy link
Contributor

sublimator commented May 14, 2024 via email

});

return controller.signal;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seem it wants you to add an extra line at the end

@@ -1,12 +1,20 @@
import jest from 'jest-mock';
import { jest } from '@jest/globals';
import { ChatCompletionResponse, Embedding, EmbeddingResponse, ListModelsResponse } from "@mistralai/mistralai/utils/type"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow surprised that import works

* @param {number} batchSize
* @return {Object}
* @param batchSize number of embeddings to generate
* @returns EmbeddingResponsePayload
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linter isn't crying about returns (vs return)? I guess not. I thought I recalled it doing so for me.

* @return {Object}
*/
export function mockEmbeddingRequest() {
// TODO:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undone TODO

"outDir": "dist",
"baseUrl": "./",
"paths": {
"@mistralai/mistralai/*": ["src/*"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's how that import worked!

@@ -1,132 +1,121 @@
const VERSION = '0.0.3';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this PR would be based on top of the latest commit in main. It doesn't seem to be, given VERSION of 0.0.3 ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it is set 0.2.0 in latest commit in main branch:

const VERSION = '0.2.0';

or anything I misunderstand?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, when looking at the diff for this PR we are seeing 0.0.3
That's because this branch is commits based on an old version of main
It complicates review a little bit

export function combineSignals(signals: AbortSignal[]):AbortSignal {
const controller = new AbortController();
signals.forEach((signal) => {
if (!signal) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, yeah, it was taking an array of AbortSignal | undefined

`HTTP error! status: ${response.status} ` +
`Response: \n${await response.text()}`,
);
throw new MistralAPIError(`HTTP error! status: ${response.status}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing Response: \n${await response.text()} from the og


/**
* Returns a list of the available models
* @return {Promise<Object>}
* @returns
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consistent return vs returns?

Personally I would just lose the JSDoc now that it's typescript

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

due to this discussion:
#73 (comment)

I agree with jsdoc making code more readable, but okay with both.

@JamieLee0510
Copy link
Author

Is it possible to deal with code formatting in other PR?
I think it could add other config file after discussion.

@JamieLee0510 JamieLee0510 requested a review from fuegoio May 20, 2024 09:56
@jwerre
Copy link

jwerre commented Jun 7, 2024

Looking forward to this! Lack of Commonjs support has prevented me from using this.

@JamieLee0510
Copy link
Author

Looking forward to this! Lack of Commonjs support has prevented me from using this.

sure let me catch up the latest commit and merge into this pr
hope Mistral team could approve this pr

@JamieLee0510
Copy link
Author

@fuegoio
Please kindly help check the updated version.
This version is also fetched up job and file features~

@GaspardBT
Copy link
Contributor

Thanks for opening this PR. We have deprecated this package in favor of mistralai/client-ts, which is the new official Mistral client, compatible with both TypeScript and JavaScript.

You can find all installation information here.

This change is effective starting with version 1.0.0 of the npm package.

@GaspardBT GaspardBT closed this Oct 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants