> ## Documentation Index
> Fetch the complete documentation index at: https://fastmcp-ts.docs.prefect.io/llms.txt
> Use this file to discover all available pages before exploring further.

# GenericSamplingAdapter

Defined in: [client/sampling/generic.ts:46](https://github.com/PrefectHQ/fastmcp-ts/blob/e4b6038f642b529f601463a576229747afebe9a4/src/client/sampling/generic.ts#L46)

Contribution template. Wraps any async function into a SamplingHandler.

The adapter resolves the model from modelPreferences, defaults maxTokens,
and threads onToken through. Message format conversion, tool translation,
and streaming are the caller's responsibility.

Example:

```ts theme={null}
const adapter = new GenericSamplingAdapter(async ({ model, messages }) => {
  const text = await myLlm.complete(model, messages)
  return { role: 'assistant', content: { type: 'text', text }, model, stopReason: 'endTurn' }
})
```

## Implements

* [`SamplingAdapter`](/api/client/interfaces/SamplingAdapter)

## Constructors

### Constructor

```ts theme={null}
new GenericSamplingAdapter(fn, options?): GenericSamplingAdapter;
```

Defined in: [client/sampling/generic.ts:50](https://github.com/PrefectHQ/fastmcp-ts/blob/e4b6038f642b529f601463a576229747afebe9a4/src/client/sampling/generic.ts#L50)

#### Parameters

##### fn

[`GenericCompletionFn`](/api/client/type-aliases/GenericCompletionFn)

##### options?

[`SamplingAdapterOptions`](/api/client/interfaces/SamplingAdapterOptions) & \{
`defaultModel?`: `string`;
}

#### Returns

`GenericSamplingAdapter`

## Methods

### asHandler()

```ts theme={null}
asHandler(): SamplingHandler;
```

Defined in: [client/sampling/generic.ts:58](https://github.com/PrefectHQ/fastmcp-ts/blob/e4b6038f642b529f601463a576229747afebe9a4/src/client/sampling/generic.ts#L58)

#### Returns

[`SamplingHandler`](/api/client/type-aliases/SamplingHandler)

#### Implementation of

[`SamplingAdapter`](/api/client/interfaces/SamplingAdapter).[`asHandler`](/api/client/interfaces/SamplingAdapter#ashandler)
