(system: LLMRequest["system"], hint: CacheHint)
| 52 | } |
| 53 | |
| 54 | const markLastSystem = (system: LLMRequest["system"], hint: CacheHint): LLMRequest["system"] => { |
| 55 | if (system.length === 0) return system |
| 56 | const last = system.length - 1 |
| 57 | if (system[last]!.cache) return system |
| 58 | return system.map((part, i) => (i === last ? { ...part, cache: hint } : part)) |
| 59 | } |
| 60 | |
| 61 | const lastIndexOfRole = (messages: ReadonlyArray<Message>, role: Message["role"]): number => |
| 62 | messages.findLastIndex((m) => m.role === role) |