ai-sdk-ollama
Version:
Vercel AI SDK Provider for Ollama using official ollama-js library
276 lines • 10.7 kB
TypeScript
import { z } from 'zod';
import type { Ollama } from 'ollama';
type OllamaWithWebFetch = Ollama;
/**
* Configuration options for the web fetch tool
*/
export interface WebFetchToolOptions {
/**
* Timeout for fetch requests in milliseconds
* @default 30000
*/
timeout?: number;
/**
* Maximum content length to return in characters
* @default 10000
*/
maxContentLength?: number;
/**
* Ollama client instance to use for web fetch
* If not provided, will need to be injected at runtime
*/
client?: OllamaWithWebFetch;
}
/**
* Input schema for web fetch requests
*/
export declare const webFetchInputSchema: z.ZodObject<{
url: z.ZodString;
}, z.core.$strip>;
export declare const webFetchInputJsonSchema: {
readonly type: 'object';
readonly properties: {
readonly url: {
readonly type: 'string';
readonly format: 'uri';
readonly description: 'The URL to fetch content from';
};
};
readonly required: readonly ['url'];
readonly additionalProperties: false;
};
/**
* Output schema for web fetch results
*/
export type WebFetchOutput = {
content: string;
title?: string;
url: string;
contentLength: number;
error?: string;
};
/**
* Creates a web fetch tool that allows AI models to retrieve content from specific URLs.
*
* This tool uses Ollama's web fetch capabilities to retrieve and parse web page content,
* making it accessible to AI models for analysis, summarization, or answering questions
* about specific web pages.
*
* @param options - Configuration options for the web fetch tool
* @returns A tool that can be used in AI SDK generateText/streamText calls
*
* @example
* ```typescript
* import { generateText } from 'ai';
* import { ollama } from 'ai-sdk-ollama';
*
* const result = await generateText({
* model: ollama('llama3.2'),
* prompt: 'Summarize the main points from this article: https://example.com/article',
* tools: {
* webFetch: ollama.tools.webFetch()
* }
* });
* ```
*/
export declare function webFetch(options?: WebFetchToolOptions): ({
title?: string;
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
metadata?: import("@ai-sdk/provider").JSONObject;
inputSchema: import("ai").FlexibleSchema<{
url: string;
}>;
contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
url: string;
}, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
onInputDelta?: ((options: {
inputTextDelta: string;
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
onInputAvailable?: ((options: {
input: {
url: string;
};
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
toModelOutput?: ((options: {
toolCallId: string;
input: {
url: string;
};
output: NoInfer<WebFetchOutput>;
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
} & {
outputSchema?: import("ai").FlexibleSchema<WebFetchOutput> | undefined;
execute: import("ai").ToolExecuteFunction<{
url: string;
}, WebFetchOutput, NoInfer<import("@ai-sdk/provider-utils").Context>>;
} & {
description?: string | ((options: {
context: NoInfer<import("@ai-sdk/provider-utils").Context>;
experimental_sandbox?: import("ai").Experimental_SandboxSession;
}) => string) | undefined;
strict?: boolean;
inputExamples?: {
input: NoInfer<{
url: string;
}>;
}[] | undefined;
id?: never;
isProviderExecuted?: never;
args?: never;
supportsDeferredResults?: never;
} & {
type?: undefined | 'function';
} & {
execute: import("ai").ToolExecuteFunction<{
url: string;
}, WebFetchOutput, NoInfer<import("@ai-sdk/provider-utils").Context>>;
}) | ({
title?: string;
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
metadata?: import("@ai-sdk/provider").JSONObject;
inputSchema: import("ai").FlexibleSchema<{
url: string;
}>;
contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
url: string;
}, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
onInputDelta?: ((options: {
inputTextDelta: string;
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
onInputAvailable?: ((options: {
input: {
url: string;
};
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
toModelOutput?: ((options: {
toolCallId: string;
input: {
url: string;
};
output: NoInfer<WebFetchOutput>;
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
} & {
outputSchema?: import("ai").FlexibleSchema<WebFetchOutput> | undefined;
execute: import("ai").ToolExecuteFunction<{
url: string;
}, WebFetchOutput, NoInfer<import("@ai-sdk/provider-utils").Context>>;
} & {
description?: string | ((options: {
context: NoInfer<import("@ai-sdk/provider-utils").Context>;
experimental_sandbox?: import("ai").Experimental_SandboxSession;
}) => string) | undefined;
strict?: boolean;
inputExamples?: {
input: NoInfer<{
url: string;
}>;
}[] | undefined;
id?: never;
isProviderExecuted?: never;
args?: never;
supportsDeferredResults?: never;
} & {
type: 'dynamic';
} & {
execute: import("ai").ToolExecuteFunction<{
url: string;
}, WebFetchOutput, NoInfer<import("@ai-sdk/provider-utils").Context>>;
}) | ({
title?: string;
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
metadata?: import("@ai-sdk/provider").JSONObject;
inputSchema: import("ai").FlexibleSchema<{
url: string;
}>;
contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
url: string;
}, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
onInputDelta?: ((options: {
inputTextDelta: string;
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
onInputAvailable?: ((options: {
input: {
url: string;
};
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
toModelOutput?: ((options: {
toolCallId: string;
input: {
url: string;
};
output: NoInfer<WebFetchOutput>;
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
} & {
outputSchema?: import("ai").FlexibleSchema<WebFetchOutput> | undefined;
execute: import("ai").ToolExecuteFunction<{
url: string;
}, WebFetchOutput, NoInfer<import("@ai-sdk/provider-utils").Context>>;
} & {
type: 'provider';
id: `${string}.${string}`;
args: Record<string, unknown>;
description?: never;
strict?: never;
inputExamples?: never;
} & {
isProviderExecuted: false;
supportsDeferredResults?: never;
} & {
execute: import("ai").ToolExecuteFunction<{
url: string;
}, WebFetchOutput, NoInfer<import("@ai-sdk/provider-utils").Context>>;
}) | ({
title?: string;
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
metadata?: import("@ai-sdk/provider").JSONObject;
inputSchema: import("ai").FlexibleSchema<{
url: string;
}>;
contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
url: string;
}, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
onInputDelta?: ((options: {
inputTextDelta: string;
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
onInputAvailable?: ((options: {
input: {
url: string;
};
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
toModelOutput?: ((options: {
toolCallId: string;
input: {
url: string;
};
output: NoInfer<WebFetchOutput>;
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
} & {
outputSchema?: import("ai").FlexibleSchema<WebFetchOutput> | undefined;
execute: import("ai").ToolExecuteFunction<{
url: string;
}, WebFetchOutput, NoInfer<import("@ai-sdk/provider-utils").Context>>;
} & {
type: 'provider';
id: `${string}.${string}`;
args: Record<string, unknown>;
description?: never;
strict?: never;
inputExamples?: never;
} & {
isProviderExecuted: true;
supportsDeferredResults?: boolean;
} & {
execute: import("ai").ToolExecuteFunction<{
url: string;
}, WebFetchOutput, NoInfer<import("@ai-sdk/provider-utils").Context>>;
});
export {};
//# sourceMappingURL=web-fetch.d.ts.map