---
url: >-
  https://adk.nht.io/api/@nhtio/adk/batteries/llm/transformers_js/model_source/functions/modelSourceToCache.md
---

# Function: modelSourceToCache()

```ts
function modelSourceToCache(
  hook: TransformersJsModelSource,
  env?: {
    remoteHost?: string;
    remotePathTemplate?: string;
  },
): TransformersCacheLike;
```

Defined in: [src/batteries/llm/transformers\_js/model\_source.ts:95](https://github.com/NHTIO/ADK/blob/v1.20260713.1/src/src/batteries/llm/transformers_js/model_source.ts#L95)

Wrap a [TransformersJsModelSource](../../types/type-aliases/TransformersJsModelSource.md) hook into a Web-Cache-API-compatible object suitable for
`env.customCache`. `match` parses the key, calls the hook, and normalizes the result:
`Uint8Array` → `new Response(bytes)`; `string`/`Response` pass through; `undefined`/throw → fall
through. `put` is a no-op (served files are never re-cached — `toCacheResponse` is false for them).

## Parameters

| Parameter                 | Type                                                                                 | Description                                                       |
| ------------------------- | ------------------------------------------------------------------------------------ | ----------------------------------------------------------------- |
| `hook`                    | [`TransformersJsModelSource`](../../types/type-aliases/TransformersJsModelSource.md) | The consumer's resolver.                                          |
| `env`                     | { `remoteHost?`: `string`; `remotePathTemplate?`: `string`; }                      | Host/template for key parsing (defaults to the library defaults). |
| `env.remoteHost?`         | `string`                                                                             | -                                                                 |
| `env.remotePathTemplate?` | `string`                                                                             | -                                                                 |

## Returns

`TransformersCacheLike`
