MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / addCacheControl

Method addCacheControl

src/api/providers/minimax.ts:242–270  ·  view source on GitHub ↗

* Add cache control to the last two user messages for prompt caching

(
		messages: Anthropic.Messages.MessageParam[],
		cacheControl: CacheControlEphemeral,
	)

Source from the content-addressed store, hash-verified

240 * Add cache control to the last two user messages for prompt caching
241 */
242 private addCacheControl(
243 messages: Anthropic.Messages.MessageParam[],
244 cacheControl: CacheControlEphemeral,
245 ): Anthropic.Messages.MessageParam[] {
246 const userMsgIndices = messages.reduce(
247 (acc, msg, index) => (msg.role === "user" ? [...acc, index] : acc),
248 [] as number[],
249 )
250
251 const lastUserMsgIndex = userMsgIndices[userMsgIndices.length - 1] ?? -1
252 const secondLastMsgUserIndex = userMsgIndices[userMsgIndices.length - 2] ?? -1
253
254 return messages.map((message, index) => {
255 if (index === lastUserMsgIndex || index === secondLastMsgUserIndex) {
256 return {
257 ...message,
258 content:
259 typeof message.content === "string"
260 ? [{ type: "text", text: message.content, cache_control: cacheControl }]
261 : message.content.map((content, contentIndex) =>
262 contentIndex === message.content.length - 1
263 ? { ...content, cache_control: cacheControl }
264 : content,
265 ),
266 }
267 }
268 return message
269 })
270 }
271
272 getModel() {
273 const modelId = this.options.apiModelId

Callers 1

createMessageMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected