用 GPT-Image-2 做课程配图:如何减少找图时间的素材到成图提效方案
2026-06-11 3350428
2026-06-11 0
vLLM 是一款专为大语言模型推理加速而设计的框架,实现了 KV 缓存内存几乎零浪费,解决了内存管理瓶颈问题。

更多 vLLM 中文文档及教程可访问 →go.hyper.ai/Wa62f
*在线运行 vLLM 入门教程:零基础分步指南
源码 examples/online_serving/api_client.py
# SPDX-License-Identifier: Apache-2.0
"""示例 python 客户端`vllm.entrypoints.api_server'
注意: API 服务器仅用于演示和简单性能基准测试。它不用于生产。
为了生产使用,我们建议 `vllm serve''和 OpenAi 客户端 API。
"""
import argparse
import json
from collections.abc import Iterable
import requests
def clear_line(n: int = 1) -> None:
LINE_UP = ' 33[1A'
LINE_CLEAR = 'x1b[2K'
for _ in range(n):
print(LINE_UP, end=LINE_CLEAR, flush=True)
def post_http_request(prompt: str,
api_url: str,
n: int = 1,
stream: bool = False) -> requests.Response:
headers = {"User-Agent": "Test Client"}
pload = {
"prompt": prompt,
"n": n,
"use_beam_search": True,
"temperature": 0.0,
"max_tokens": 16,
"stream": stream,
}
response = requests.post(api_url,
headers=headers,
json=pload,
stream=stream)
return response
def get_streaming_response(response: requests.Response) -> Iterable[list[str]]:
for chunk in response.iter_lines(chunk_size=8192,
decode_unicode=False,
delimiter=b"n"):
if chunk:
data = json.loads(chunk.decode("utf-8"))
output = data["text"]
yield output
def get_response(response: requests.Response) -> list[str]:
data = json.loads(response.content)
output = data["text"]
return output
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--host", type=str, default="localhost")
parser.add_argument("--port", type=int, default=8000)
parser.add_argument("--n", type=int, default=4)
parser.add_argument("--prompt", type=str, default="San Francisco is a")
parser.add_argument("--stream", action="store_true")
args = parser.parse_args()
prompt = args.prompt
api_url = f"http://{args.host}:{args.port}/generate"
n = args.n
stream = args.stream
print(f"Prompt: {prompt!r}n", flush=True)
response = post_http_request(prompt, api_url, n, stream)
if stream:
num_printed_lines = 0
for h in get_streaming_response(response):
clear_line(num_printed_lines)
num_printed_lines = 0
for i, line in enumerate(h):
num_printed_lines += 1
print(f"Beam candidate {i}: {line!r}", flush=True)
else:
output = get_response(response)
for i, line in enumerate(output):
print(f"Beam candidate {i}: {line!r}", flush=True)
用 GPT-Image-2 做课程配图:如何减少找图时间的素材到成图提效方案
2026-06-11 3350428
用GPT-Image-2制作PPT视觉辅助图:避免风格混乱的“提示词体系”与验证方法
2026-06-11 3350427
用 GPT-Image-2 做社媒运营配图:如何批量产出并保持风格一致与可控性
2026-06-11 3350426
用GPT-Image-2打造品牌视觉灵感板:高效组织提示词的结构化模板与验证流程
2026-06-11 3350425
用 GPT-Image-2 做创意提案图:提升表达效率的提示词工程与最小验证法 新手可上手
2026-06-11 3350424