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

fix: typescript definitions #72

Merged

Conversation

sublimator
Copy link
Contributor

@sublimator sublimator commented May 7, 2024

This should make the typescript definitions at least useable. Currently they seem to be quite broken (per #69, #67 )

Closes #54
Closes #47
Closes #69
Closes #67
Closes #62

@sublimator
Copy link
Contributor Author

@fuegoio

Please look :)

@sublimator sublimator force-pushed the nd-update-ts-definitions-2024-05-07 branch from 9b72652 to c70e2b7 Compare May 7, 2024 05:16
@sublimator sublimator force-pushed the nd-update-ts-definitions-2024-05-07 branch from c70e2b7 to 475821c Compare May 7, 2024 05:17
@sublimator sublimator marked this pull request as ready for review May 7, 2024 05:18
src/client.d.ts Outdated
export interface Message {
role: string;
// TODO: this is not specified at https://docs.mistral.ai/redocusaurus/plugin-redoc-0.yaml
name?: string,
Copy link
Contributor

Choose a reason for hiding this comment

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

Normally there is no name on the message, I think we can remove it.

src/client.d.ts Outdated
function: FunctionCall;
}

export enum ResponseFormats {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should also remove the enums from the types and change them to types. A simple example like this does not work because the enums are TS only:

import MistralClient, { ResponseFormats } from "@mistralai/mistralai";

const chatResponse = await mistralClient.chat({
    model: "mistral-large",
    temperature: 0.1,
    responseFormat: { type: ResponseFormats.json_object },
})`

This raises the error 'mistralai/src/client.js' does not provide an export named 'ResponseFormats'

@sublimator
Copy link
Contributor Author

sublimator commented May 7, 2024 via email

@sublimator
Copy link
Contributor Author

sublimator commented May 7, 2024 via email

@fuegoio
Copy link
Contributor

fuegoio commented May 7, 2024

Oh right, yeah, the enums aren't even defined at runtime are they. I added literals (for ergonomics) and left the enums in there and moved on. They are completely broken though aren't they. A good argument to move to TS :)

In a d.ts file they do not make much sense no. I approve moving to TS to have this kind of nice feature.

@sublimator
Copy link
Contributor Author

@fuegoio

Anything else? I'll look at a full TS port when I have more time

@sublimator
Copy link
Contributor Author

Oh, wait, that's not working, enums still referenced, but no errors, hrmmm

export interface ToolCalls {
id: 'null';
type: ToolType = ToolType.function;
function: FunctionCall;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What happened here? :)

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

id: 'null';
type: ToolType = ToolType.function;

As you mentioned, the enums don't work at runtime, and null is set to match the string null, not the null type (which is actually not appropriate either). Also, it's trying to set a default (ToolType = ToolType.function;) inside a .d.ts file, which I don't believe actually works.

More a rhetorical question than serious :) Wondering how the ..

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah the null string is expected, as before our API change the id returned by the API was always 'null' (the string). Now it is function call ids yes. The default stuff well I'm not sure ahah

@sublimator
Copy link
Contributor Author

sublimator commented May 7, 2024

I'll look at a full TS port when I have more time

In a separate PR, to be clear

edit: the question is if you all want to merge this ( I think it makes sense, as it's still progress, and closes some issues), or wait for a full TS port

@sublimator sublimator mentioned this pull request May 8, 2024
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.

Thanks a lot @sublimator!

@fuegoio fuegoio merged commit 3312818 into mistralai:main May 8, 2024
4 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants