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

Commit

Permalink
Merge pull request #72 from sublimator/nd-update-ts-definitions-2024-…
Browse files Browse the repository at this point in the history
…05-07

fix: typescript definitions
  • Loading branch information
fuegoio authored May 8, 2024
2 parents 7b55eaa + 26f7a59 commit 3312818
Show file tree
Hide file tree
Showing 9 changed files with 579 additions and 78 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ env:
extends: google
ignorePatterns:
- examples/chat-react/
- src/client.d.ts
parserOptions:
ecmaVersion: latest
sourceType: module
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/build_publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ jobs:
run: |
npm run test
# Build TypeScript Examples
- name: Build typescript examples
run: |
cd examples/typescript
npm install
npx tsc --build --verbose tsconfig.json
publish:
needs: lint_and_test
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion examples/chat_with_streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const apiKey = process.env.MISTRAL_API_KEY;

const client = new MistralClient(apiKey);

const chatStreamResponse = await client.chatStream({
const chatStreamResponse = client.chatStream({
model: 'mistral-tiny',
messages: [{role: 'user', content: 'What is the best French cheese?'}],
});
Expand Down
24 changes: 24 additions & 0 deletions examples/typescript/chat_with_streaming.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import MistralClient from '@mistralai/mistralai';

const apiKey = process.env.MISTRAL_API_KEY;

const client = new MistralClient(apiKey);

const responseInterface = '{"best": string, "reasoning": string}';
const chatStreamResponse = client.chatStream({
model: 'open-mistral-7b',
responseFormat: {type: 'json_object'},
messages: [{
role: 'user', content: `
What is the best French cheese?
Answer in ${responseInterface} format`,
}],
});

console.log('Chat Stream:');
for await (const chunk of chatStreamResponse) {
if (chunk.choices[0].delta.content !== undefined) {
const streamText = chunk.choices[0].delta.content;
process.stdout.write(streamText);
}
}
Loading

0 comments on commit 3312818

Please sign in to comment.