Skip to content

Commit

Permalink
feat: mistral bump (#256)
Browse files Browse the repository at this point in the history
* feat: mistral bump

* fix: remove unused input
  • Loading branch information
xavidop authored Mar 8, 2025
1 parent e9b4c41 commit e2bc8c2
Show file tree
Hide file tree
Showing 10 changed files with 746 additions and 272 deletions.
44 changes: 44 additions & 0 deletions docs/docs/plugins/mistral.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,50 @@ const embedding = await ai.embed({
console.log(embedding);
```

## Vision

```typescript
import { openPixtral } from 'genkitx-mistral';

const { text } = await ai.generate({
prompt: [{ media: { url: 'https://my-photo.jpg' } }, { text: input }],
model: openPixtral,
config: {
version: 'pixtral-12b-2409',
},
});

return JSON.stringify(text);
```

## OCR

```typescript
import { ocr } from 'genkitx-mistral';

export const ocrFlow = ai.defineFlow(
{
name: 'ocrFlow',
inputSchema: z.string(),
outputSchema: z.string(),
},
async (input) => {
const { text } = await ai.generate({
model: ocr,
prompt: 'parse the document',
config: {
document: {
documentUrl: input,
type: 'document_url',
},
},
});

return JSON.stringify(text);
}
);
```

### Within a flow

```typescript
Expand Down
5 changes: 4 additions & 1 deletion examples/mistral/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
"build": "tsc",
"build:watch": "tsc --watch",
"genkit:dev": "cross-env GENKIT_ENV=dev npm run dev",
"genkit:start": "cross-env GENKIT_ENV=dev genkit start -- tsx --watch src/index.ts",
"dev": "export GENKIT_RUNTIME_ID=$(openssl rand -hex 8) && node lib/index.js 2>&1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@genkit-ai/express": "^1.1.0",
"genkit": "^0.9.0 || ^1.0.0",
"genkitx-mistral": "file:../../plugins/mistral"
"genkitx-mistral": "file:../../plugins/mistral",
"tsx": "^4.19.3"
},
"devDependencies": {
"cross-env": "^7.0.3",
Expand Down
53 changes: 52 additions & 1 deletion examples/mistral/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
* limitations under the License.
*/

import { startFlowServer } from '@genkit-ai/express';
import dotenv from 'dotenv';
import { genkit, z } from 'genkit';
import mistral, { openMistral7B, mistralembed } from 'genkitx-mistral';
import mistral, {
openMistral7B,
mistralembed,
openPixtral,
} from 'genkitx-mistral';
import { ocr } from '../../../plugins/mistral/src/ocr';

dotenv.config();

Expand Down Expand Up @@ -56,3 +62,48 @@ export const embedFlow = ai.defineFlow(
return JSON.stringify(embedding);
}
);

export const visionFlow = ai.defineFlow(
{
name: 'visionFlow',
inputSchema: z.string(),
outputSchema: z.string(),
},
async (input) => {
const { text } = await ai.generate({
prompt: [{ media: { url: 'https://my-photo.jpg' } }, { text: input }],
model: openPixtral,
config: {
version: 'pixtral-12b-2409',
},
});

return JSON.stringify(text);
}
);

export const ocrFlow = ai.defineFlow(
{
name: 'ocrFlow',
inputSchema: z.string(),
outputSchema: z.string(),
},
async (input) => {
const { text } = await ai.generate({
model: ocr,
prompt: 'parse the document',
config: {
document: {
documentUrl: input,
type: 'document_url',
},
},
});

return JSON.stringify(text);
}
);

startFlowServer({
flows: [embedFlow, jokeFlow, visionFlow, ocrFlow],
});
Loading

0 comments on commit e2bc8c2

Please sign in to comment.