Skip to content

Commit

Permalink
Use Platformatic Mistral client (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
flakey5 authored Apr 24, 2024
1 parent 107190c commit bd4b5fa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
8 changes: 4 additions & 4 deletions ai-providers/mistral.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReadableStream, UnderlyingByteSource, ReadableByteStreamController } from 'node:stream/web'
import { ChatCompletionResponseChunk } from '@mistralai/mistralai'
import { ChatCompletionResponseChunk } from '@platformatic/mistral-client'
import { AiProvider, NoContentError, StreamChunkCallback } from './provider'
import { AiStreamEvent, encodeEvent } from './event'

Expand Down Expand Up @@ -60,7 +60,7 @@ interface MistralProviderCtorOptions {
export class MistralProvider implements AiProvider {
model: string
apiKey: string
client?: import('@mistralai/mistralai').default = undefined
client?: import('@platformatic/mistral-client').default = undefined

constructor ({ model, apiKey }: MistralProviderCtorOptions) {
this.model = model
Expand All @@ -69,7 +69,7 @@ export class MistralProvider implements AiProvider {

async ask (prompt: string): Promise<string> {
if (this.client === undefined) {
const { default: MistralClient } = await import('@mistralai/mistralai')
const { default: MistralClient } = await import('@platformatic/mistral-client')
this.client = new MistralClient(this.apiKey)
}

Expand All @@ -89,7 +89,7 @@ export class MistralProvider implements AiProvider {

async askStream (prompt: string, chunkCallback?: StreamChunkCallback): Promise<ReadableStream> {
if (this.client === undefined) {
const { default: MistralClient } = await import('@mistralai/mistralai')
const { default: MistralClient } = await import('@platformatic/mistral-client')
this.client = new MistralClient(this.apiKey)
}

Expand Down
15 changes: 6 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
"@fastify/error": "^3.4.1",
"@fastify/rate-limit": "^9.1.0",
"@fastify/type-provider-typebox": "^4.0.0",
"@mistralai/mistralai": "^0.1.3",
"@platformatic/config": "^1.24.0",
"@platformatic/generators": "^1.24.0",
"@platformatic/mistral-client": "^0.1.0",
"@platformatic/service": "^1.24.0",
"fast-json-stringify": "^5.13.0",
"fastify-user": "^0.3.3",
Expand Down

0 comments on commit bd4b5fa

Please sign in to comment.