BREAKING CHANGE(vercel-ai-sdk): migrate to Vercel AI SDK v6 and introduce provider registry (getModel) returning LanguageModelV3
This commit is contained in:
29
ts_vision/index.ts
Normal file
29
ts_vision/index.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import type { LanguageModelV3 } from '@ai-sdk/provider';
|
||||
|
||||
export interface IVisionOptions {
|
||||
model: LanguageModelV3;
|
||||
image: Buffer | Uint8Array;
|
||||
prompt: string;
|
||||
mediaType?: 'image/jpeg' | 'image/png' | 'image/webp' | 'image/gif';
|
||||
}
|
||||
|
||||
export async function analyzeImage(options: IVisionOptions): Promise<string> {
|
||||
const result = await plugins.generateText({
|
||||
model: options.model,
|
||||
messages: [
|
||||
{
|
||||
role: 'user',
|
||||
content: [
|
||||
{ type: 'text', text: options.prompt },
|
||||
{
|
||||
type: 'image',
|
||||
image: options.image,
|
||||
mediaType: options.mediaType ?? 'image/jpeg',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
return result.text;
|
||||
}
|
||||
2
ts_vision/plugins.ts
Normal file
2
ts_vision/plugins.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
import { generateText } from 'ai';
|
||||
export { generateText };
|
||||
Reference in New Issue
Block a user