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

Method normalized_input

examples/server/server.py:2595–2620  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2593 return self
2594
2595 def normalized_input(self) -> List[Union[str, List[int]]]:
2596 if isinstance(self.input, str):
2597 return [self._validate_text_input(self.input)]
2598 if all(isinstance(token, int) for token in self.input):
2599 return [self._validate_token_input(cast(List[int], self.input))]
2600 if all(isinstance(item, str) for item in self.input):
2601 if len(self.input) > 2048:
2602 raise ValueError("embedding input array must not exceed 2048 items")
2603 return [
2604 self._validate_text_input(item)
2605 for item in cast(List[str], self.input)
2606 ]
2607 if all(
2608 isinstance(item, list)
2609 and all(isinstance(token, int) for token in item)
2610 for item in self.input
2611 ):
2612 if len(self.input) > 2048:
2613 raise ValueError("embedding input array must not exceed 2048 items")
2614 return [
2615 self._validate_token_input(item)
2616 for item in cast(List[List[int]], self.input)
2617 ]
2618 raise ValueError(
2619 "embedding input must be a string, list of strings, token ids, or list of token-id lists"
2620 )
2621
2622
2623class EmbeddingDataResponse(BaseModel):

Callers 2

validate_afterMethod · 0.95
create_embeddingMethod · 0.80

Calls 2

_validate_text_inputMethod · 0.95
_validate_token_inputMethod · 0.95

Tested by

no test coverage detected