https://github.com/beenotung/mistral-client
Client SDK for Mistral AI API with rate limit throttling and helper functions to convert stream delta messages to html/markdown/text
https://github.com/beenotung/mistral-client
ai api client html llm markdown mistral rate-limit sdk stream text throttling typescript
Last synced: about 2 months ago
JSON representation
Client SDK for Mistral AI API with rate limit throttling and helper functions to convert stream delta messages to html/markdown/text
- Host: GitHub
- URL: https://github.com/beenotung/mistral-client
- Owner: beenotung
- License: bsd-2-clause
- Created: 2025-03-22T18:13:16.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-22T23:47:16.000Z (over 1 year ago)
- Last Synced: 2025-08-18T12:00:18.173Z (10 months ago)
- Topics: ai, api, client, html, llm, markdown, mistral, rate-limit, sdk, stream, text, throttling, typescript
- Language: TypeScript
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mistral-client
Client SDK for Mistral AI API.
[](https://www.npmjs.com/package/mistral-client)
## Features
- Rate limit throttling
- Helper functions to convert stream delta messages to html/markdown/text
- Typescript support
## Installation
```bash
npm install mistral-client
```
You can also install `mistral-client` with [pnpm](https://pnpm.io/), [yarn](https://yarnpkg.com/), or [slnpm](https://github.com/beenotung/slnpm)
## Usage Example
### Setup Client SDK
```typescript
import { MistralClient, completionContentToString } from 'mistral-client'
async function main() {
let client = new MistralClient({ apiKey: 'your-api-key' })
let prompt = `Introduce ts-liveview in zh-hk`
// use async or stream mode, see examples below
}
main().catch(e => console.error(e))
```
### Chat Completion in Async Mode
```typescript
let completion = await client.askAsync({
model: 'mistral-large-latest',
messages: [{ role: 'user', content: prompt }],
})
let content = completionContentToString(completion?.message.content)
console.log(content)
```
### Chat Completion in Streaming Mode
```typescript
let stream = client.askInStream({
model: 'mistral-large-latest',
messages: [{ role: 'user', content: prompt }],
})
for await (let completion of stream) {
let content = completionContentToString(completion.delta.content)
process.stdout.write(content)
}
process.stdout.write('\n[end]\n')
```
## Typescript Signature
```typescript
export class MistralClient {
constructor(options: { apiKey: string })
askAsync(
request: ChatCompletionRequest,
options?: RequestOptions,
): Promise
askInStream(
request: ChatCompletionRequest,
options?: RequestOptions,
): AsyncGenerator
}
export function completionContentToString(
content:
| ChatCompletionChoice['message']['content']
| CompletionResponseStreamChoice['delta']['content'],
options?: {
/** default 'text' */
format?: 'html' | 'markdown' | 'text'
},
): string
```
## License
This project is licensed with [BSD-2-Clause](./LICENSE)
This is free, libre, and open-source software. It comes down to four essential freedoms [[ref]](https://seirdy.one/2021/01/27/whatsapp-and-the-domestication-of-users.html#fnref:2):
- The freedom to run the program as you wish, for any purpose
- The freedom to study how the program works, and change it so it does your computing as you wish
- The freedom to redistribute copies so you can help others
- The freedom to distribute copies of your modified versions to others