MCPcopy Create free account
hub / github.com/abetlen/llama-cpp-python / __getitem__

Method __getitem__

llama_cpp/llama_cache.py:130–139  ·  view source on GitHub ↗
(self, key: Sequence[int])

Source from the content-addressed store, hash-verified

128 return min_key
129
130 def __getitem__(self, key: Sequence[int]) -> "llama_cpp.llama.LlamaState":
131 key = tuple(key)
132 _key = self._find_longest_prefix_key(key)
133 if _key is None:
134 raise KeyError("Key not found")
135 value: "llama_cpp.llama.LlamaState" = self.cache.pop(_key) # type: ignore
136 # NOTE: This puts an integer as key in cache, which breaks,
137 # Llama.longest_token_prefix(k, key) above since k is not a tuple of ints/tokens
138 # self.cache.push(_key, side="front") # type: ignore
139 return value
140
141 def __contains__(self, key: Sequence[int]) -> bool:
142 return self._find_longest_prefix_key(tuple(key)) is not None

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected