in src/server/cache-manager.ts [47:89]
async create(
createOptions: CachedContentCreateParams,
): Promise<CachedContent> {
const newCachedContent: CachedContent = { ...createOptions };
if (createOptions.ttlSeconds) {
if (createOptions.expireTime) {
throw new GoogleGenerativeAIRequestInputError(
"You cannot specify both `ttlSeconds` and `expireTime` when creating" +
" a content cache. You must choose one.",
);
}
newCachedContent.ttl = createOptions.ttlSeconds.toString() + "s";
delete (newCachedContent as CachedContentCreateParams).ttlSeconds;
}
if (createOptions.systemInstruction) {
newCachedContent.systemInstruction = formatSystemInstruction(
createOptions.systemInstruction,
);
}
if (!newCachedContent.model) {
throw new GoogleGenerativeAIRequestInputError(
"Cached content must contain a `model` field.",
);
}
if (!newCachedContent.model.includes("/")) {
// If path is not included, assume it's a non-tuned model.
newCachedContent.model = `models/${newCachedContent.model}`;
}
const url = new CachedContentUrl(
RpcTask.CREATE,
this.apiKey,
this._requestOptions,
);
const headers = getHeaders(url);
const response = await makeServerRequest(
url,
headers,
JSON.stringify(newCachedContent),
);
return response.json();
}