mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2025-12-09 03:24:56 +08:00
Signed-off-by: Yeshwanth Surya <yeshsurya@gmail.com> Signed-off-by: Yeshwanth N <yeshsurya@gmail.com> Signed-off-by: yeshsurya <yeshsurya@gmail.com>
61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
|
|
|
from argparse import Namespace
|
|
|
|
from vllm import LLM, EngineArgs
|
|
from vllm.utils.argparse_utils import FlexibleArgumentParser
|
|
|
|
|
|
def parse_args():
|
|
parser = FlexibleArgumentParser()
|
|
parser = EngineArgs.add_cli_args(parser)
|
|
# Set example specific arguments
|
|
parser.set_defaults(
|
|
model="jinaai/jina-embeddings-v3",
|
|
runner="pooling",
|
|
trust_remote_code=True,
|
|
)
|
|
return parser.parse_args()
|
|
|
|
|
|
def main(args: Namespace):
|
|
# Sample prompts.
|
|
prompts = [
|
|
"Follow the white rabbit.", # English
|
|
"Sigue al conejo blanco.", # Spanish
|
|
"Suis le lapin blanc.", # French
|
|
"跟着白兔走。", # Chinese
|
|
"اتبع الأرنب الأبيض.", # Arabic
|
|
"Folge dem weißen Kaninchen.", # German
|
|
]
|
|
|
|
# Create an LLM.
|
|
# You should pass runner="pooling" for embedding models
|
|
llm = LLM(**vars(args))
|
|
|
|
# Generate embedding. The output is a list of EmbeddingRequestOutputs.
|
|
# Only text matching task is supported for now. See #16120
|
|
outputs = llm.embed(prompts)
|
|
|
|
# Print the outputs.
|
|
print("\nGenerated Outputs:")
|
|
print("Only text matching task is supported for now. See #16120")
|
|
print("-" * 60)
|
|
for prompt, output in zip(prompts, outputs):
|
|
embeds = output.outputs.embedding
|
|
embeds_trimmed = (
|
|
(str(embeds[:16])[:-1] + ", ...]") if len(embeds) > 16 else embeds
|
|
)
|
|
print(
|
|
f"Prompt: {prompt!r} \n"
|
|
f"Embeddings for text matching: {embeds_trimmed} "
|
|
f"(size={len(embeds)})"
|
|
)
|
|
print("-" * 60)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
args = parse_args()
|
|
main(args)
|