Skip to content

Commit

Permalink
Merge pull request #15 from mistralai/gaspardBT/fix-stream-tc
Browse files Browse the repository at this point in the history
Fix agent stream and tool type
  • Loading branch information
GaspardBT authored Aug 16, 2024
2 parents 7bdb8dd + 737f8d1 commit 2020733
Show file tree
Hide file tree
Showing 280 changed files with 4,490 additions and 399 deletions.
24 changes: 16 additions & 8 deletions .speakeasy/gen.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
lockVersion: 2.0.0
id: 81b65c50-f2e3-40a3-bd65-346524007b3d
management:
docChecksum: a7c4268dd1228c969aecfd7cfdb6ca3c
docChecksum: c19f5a86b8045af32a46604ee5478061
docVersion: 0.0.2
speakeasyVersion: 1.357.4
generationVersion: 2.390.6
releaseVersion: 1.0.2
configChecksum: 6c6983431817f47e5b2f8404eb1ab0dd
speakeasyVersion: 1.372.0
generationVersion: 2.399.0
releaseVersion: 1.1.2
configChecksum: 73da950b6151099c2d5a87da13ba3360
repoURL: https://github.com/mistralai/client-ts.git
installationURL: https://github.com/mistralai/client-ts
published: true
features:
typescript:
additionalDependencies: 0.1.0
constsAndDefaults: 0.1.6
core: 3.12.3
constsAndDefaults: 0.1.8
core: 3.13.2
defaultEnabledRetries: 0.1.0
devContainers: 2.90.0
envVarSecurityUsage: 0.1.1
Expand All @@ -25,13 +25,14 @@ features:
globalServerURLs: 2.82.4
nameOverrides: 2.81.2
nullables: 0.1.0
openEnums: 0.1.1
responseFormat: 0.2.3
retries: 2.83.0
sdkHooks: 0.1.0
serverEvents: 0.1.4
serverEventsSentinels: 0.1.0
serverIDs: 2.81.2
unions: 2.85.6
unions: 2.85.7
generatedFiles:
- src/funcs/modelsList.ts
- src/funcs/modelsRetrieve.ts
Expand Down Expand Up @@ -66,6 +67,7 @@ generatedFiles:
- src/sdk/sdk.ts
- .eslintrc.cjs
- .npmignore
- FUNCTIONS.md
- RUNTIMES.md
- jsr.json
- package.json
Expand All @@ -79,6 +81,7 @@ generatedFiles:
- src/lib/event-streams.ts
- src/lib/http.ts
- src/lib/is-plain-object.ts
- src/lib/logger.ts
- src/lib/matchers.ts
- src/lib/primitives.ts
- src/lib/retries.ts
Expand All @@ -91,6 +94,7 @@ generatedFiles:
- src/models/errors/sdkerror.ts
- src/models/errors/sdkvalidationerror.ts
- src/types/blobs.ts
- src/types/constdatetime.ts
- src/types/enums.ts
- src/types/fp.ts
- src/types/index.ts
Expand Down Expand Up @@ -219,6 +223,7 @@ generatedFiles:
- docs/models/components/chatcompletionchoice.md
- docs/models/components/assistantmessagerole.md
- docs/models/components/assistantmessage.md
- docs/models/components/tooltypes.md
- docs/models/components/toolcall.md
- docs/models/components/arguments.md
- docs/models/components/functioncall.md
Expand All @@ -227,6 +232,7 @@ generatedFiles:
- docs/models/components/messages.md
- docs/models/components/toolchoice.md
- docs/models/components/chatcompletionrequest.md
- docs/models/components/tooltooltypes.md
- docs/models/components/tool.md
- docs/models/components/functiont.md
- docs/models/components/responseformats.md
Expand Down Expand Up @@ -260,6 +266,8 @@ generatedFiles:
- docs/models/components/agentscompletionrequesttoolchoice.md
- docs/models/components/agentscompletionrequest.md
- docs/models/components/agentscompletionstreamrequeststop.md
- docs/models/components/agentscompletionstreamrequestmessages.md
- docs/models/components/agentscompletionstreamrequesttoolchoice.md
- docs/models/components/agentscompletionstreamrequest.md
- docs/models/components/embeddingresponse.md
- docs/models/components/embeddingresponsedata.md
Expand Down
2 changes: 1 addition & 1 deletion .speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ generation:
auth:
oAuth2ClientCredentialsEnabled: true
typescript:
version: 1.0.2
version: 1.1.2
additionalDependencies:
dependencies: {}
devDependencies: {}
Expand Down
33 changes: 30 additions & 3 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
speakeasyVersion: 1.357.4
sources: {}
speakeasyVersion: 1.372.0
sources:
mistral-azure-source:
sourceNamespace: mistral-openapi-azure
sourceRevisionDigest: sha256:bc53dba5935490a409045de3c39ccf9e90243a289656dd538a542990aa376cca
sourceBlobDigest: sha256:4173c3be19775dd2bdd4ce28bb9ae6655650df75f2b689a44c3362d418d69d49
tags:
- latest
mistral-google-cloud-source:
sourceNamespace: mistral-openapi-google-cloud
sourceRevisionDigest: sha256:ab52d75474e071db240ed9a5367dc6374867b5c9306d478dcfdf8f7b7d08607f
sourceBlobDigest: sha256:d5f9c665861d7fedd5093567d13e1f7f6a12b82137fbbecda4708007b15030ba
tags:
- latest
mistral-openapi:
sourceNamespace: mistral-openapi
sourceRevisionDigest: sha256:e4d5f5fe40e7f1141006ba40c1d85b743ce5dc2407635ca2e776ba0dfb00a398
sourceBlobDigest: sha256:56f1bbe3a050c9505e003bb9790e443084922bff74b072805757076cdb8a136e
tags:
- latest
targets:
mistralai-azure-sdk:
source: mistral-azure-source
sourceNamespace: mistral-openapi-azure
sourceRevisionDigest: sha256:bc53dba5935490a409045de3c39ccf9e90243a289656dd538a542990aa376cca
sourceBlobDigest: sha256:4173c3be19775dd2bdd4ce28bb9ae6655650df75f2b689a44c3362d418d69d49
outLocation: ./packages/mistralai-azure
mistralai-gcp-sdk:
source: mistral-google-cloud-source
sourceNamespace: mistral-openapi-google-cloud
sourceRevisionDigest: sha256:ab52d75474e071db240ed9a5367dc6374867b5c9306d478dcfdf8f7b7d08607f
sourceBlobDigest: sha256:d5f9c665861d7fedd5093567d13e1f7f6a12b82137fbbecda4708007b15030ba
outLocation: ./packages/mistralai-gcp
mistralai-sdk:
source: mistral-openapi
outLocation: /github/workspace/repo
sourceNamespace: mistral-openapi
sourceRevisionDigest: sha256:e4d5f5fe40e7f1141006ba40c1d85b743ce5dc2407635ca2e776ba0dfb00a398
sourceBlobDigest: sha256:56f1bbe3a050c9505e003bb9790e443084922bff74b072805757076cdb8a136e
outLocation: /Users/gaspard/public-mistral/client-ts
workflow:
workflowVersion: 1.0.0
speakeasyVersion: latest
Expand Down
107 changes: 107 additions & 0 deletions FUNCTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Standalone Functions

> [!NOTE]
> This section is useful if you are using a bundler and targetting browsers and
> runtimes where the size of an application affects performance and load times.
Every method in this SDK is also available as a standalone function. This
alternative API is suitable when targetting the browser or serverless runtimes
and using a bundler to build your application since all unused functionality
will be tree-shaken away. This includes code for unused methods, Zod schemas,
encoding helpers and response handlers. The result is dramatically smaller
impact on the application's final bundle size which grows very slowly as you use
more and more functionality from this SDK.

Calling methods through the main SDK class remains a valid and generally more
more ergonomic option. Standalone functions represent an optimisation for a
specific category of applications.

## Example

```typescript
import { MistralCore } from "@mistralai/mistralai/core.js";
import { filesUpload } from "@mistralai/mistralai/funcs/filesUpload.js";
import { SDKValidationError } from "@mistralai/mistralai/models/errors/sdkvalidationerror.js";
import { openAsBlob } from "node:fs";

// Use `MistralCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const mistral = new MistralCore({
apiKey: process.env["MISTRAL_API_KEY"] ?? "",
});

async function run() {
const res = await filesUpload(mistral, {
file: await openAsBlob("./sample-file"),
});

switch (true) {
case res.ok:
// The success case will be handled outside of the switch block
break;
case res.error instanceof SDKValidationError:
// Pretty-print validation errors.
return console.log(res.error.pretty());
case res.error instanceof Error:
return console.log(res.error);
default:
// TypeScript's type checking will fail on the following line if the above
// cases were not exhaustive.
res.error satisfies never;
throw new Error("Assertion failed: expected error checks to be exhaustive: " + res.error);
}


const { value: result } = res;

// Handle the result
console.log(result)
}

run();
```

## Result types

Standalone functions differ from SDK methods in that they return a
`Result<Value, Error>` type to capture _known errors_ and document them using
the type system. By avoiding throwing errors, application code maintains clear
control flow and error-handling become part of the regular flow of application
code.

> We use the term "known errors" because standalone functions, and JavaScript
> code in general, can still throw unexpected errors such as `TypeError`s,
> `RangeError`s and `DOMException`s. Exhaustively catching all errors may be
> something this SDK addresses in the future. Nevertheless, there is still a lot
> of benefit from capturing most errors and turning them into values.
The second reason for this style of programming is because these functions will
typically be used in front-end applications where exception throwing is
sometimes discouraged or considered unidiomatic. React and similar ecosystems
and libraries tend to promote this style of programming so that components
render useful content under all states (loading, success, error and so on).

The general pattern when calling standalone functions looks like this:

```typescript
import { Core } from "<sdk-package-name>";
import { fetchSomething } from "<sdk-package-name>/funcs/fetchSomething.js";

const client = new Core();

async function run() {
const result = await fetchSomething(client, { id: "123" });
if (!result.ok) {
// You can throw the error or handle it. It's your choice now.
throw result.error;
}

console.log(result.value);
}

run();
```

Notably, `result.error` above will have an explicit type compared to a try-catch
variation where the error in the catch block can only be of type `unknown` (or
`any` depending on your TypeScript settings).
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,63 @@ We also provide provider specific SDK for:
- [GCP](packages/mistralai-gcp/README.md)
- [Azure](packages/mistralai-azure/README.md)

<!-- Start Standalone functions [standalone-funcs] -->
## Standalone functions

All the methods listed above are available as standalone functions. These
functions are ideal for use in applications running in the browser, serverless
runtimes or other environments where application bundle size is a primary
concern. When using a bundler to build your application, all unused
functionality will be either excluded from the final bundle or tree-shaken away.

To read more about standalone functions, check [FUNCTIONS.md](./FUNCTIONS.md).

<details>

<summary>Available standalone functions</summary>

- [agentsComplete](docs/sdks/agents/README.md#complete)
- [agentsStream](docs/sdks/agents/README.md#stream)
- [chatComplete](docs/sdks/chat/README.md#complete)
- [chatStream](docs/sdks/chat/README.md#stream)
- [embeddingsCreate](docs/sdks/embeddings/README.md#create)
- [filesDelete](docs/sdks/files/README.md#delete)
- [filesList](docs/sdks/files/README.md#list)
- [filesRetrieve](docs/sdks/files/README.md#retrieve)
- [filesUpload](docs/sdks/files/README.md#upload)
- [fimComplete](docs/sdks/fim/README.md#complete)
- [fimStream](docs/sdks/fim/README.md#stream)
- [fineTuningJobsCancel](docs/sdks/jobs/README.md#cancel)
- [fineTuningJobsCreate](docs/sdks/jobs/README.md#create)
- [fineTuningJobsGet](docs/sdks/jobs/README.md#get)
- [fineTuningJobsList](docs/sdks/jobs/README.md#list)
- [fineTuningJobsStart](docs/sdks/jobs/README.md#start)
- [modelsArchive](docs/sdks/models/README.md#archive)
- [modelsDelete](docs/sdks/models/README.md#delete)
- [modelsList](docs/sdks/models/README.md#list)
- [modelsRetrieve](docs/sdks/models/README.md#retrieve)
- [modelsUnarchive](docs/sdks/models/README.md#unarchive)
- [modelsUpdate](docs/sdks/models/README.md#update)


</details>
<!-- End Standalone functions [standalone-funcs] -->

<!-- Start Debugging [debug] -->
## Debugging

To log HTTP requests and responses, you can pass a logger that matches `console`'s interface as an SDK option.

> [!WARNING]
> Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.
```typescript
import { Mistral } from "@mistralai/mistralai";

const sdk = new Mistral({ debugLogger: console });
```
<!-- End Debugging [debug] -->

<!-- Placeholder for Future Speakeasy SDK Sections -->

# Development
Expand Down
Loading

0 comments on commit 2020733

Please sign in to comment.