MCPcopy Create free account
hub / github.com/PaddlePaddle/FastDeploy / send_request

Function send_request

tests/ce/server/core/utils.py:29–56  ·  view source on GitHub ↗

向指定URL发送POST请求,并返回响应结果。 Args: url (str): 请求的目标URL。 payload (dict): 请求的负载数据,应该是一个字典类型。 timeout (int, optional): 请求的超时时间,默认为600秒。 stream (bool, optional): 是否以流的方式下载响应内容,默认为False。 Returns: response: 请求的响应结果,如果请求失败则返回None。

(url, payload, timeout=60, stream=False)

Source from the content-addressed store, hash-verified

27
28
29def send_request(url, payload, timeout=60, stream=False):
30 """
31 向指定URL发送POST请求,并返回响应结果。
32
33 Args:
34 url (str): 请求的目标URL。
35 payload (dict): 请求的负载数据,应该是一个字典类型。
36 timeout (int, optional): 请求的超时时间,默认为600秒。
37 stream (bool, optional): 是否以流的方式下载响应内容,默认为False。
38
39 Returns:
40 response: 请求的响应结果,如果请求失败则返回None。
41 """
42 headers = {
43 "Content-Type": "application/json",
44 }
45 base_logger.info("🔄 正在请求模型接口...")
46
47 try:
48 res = requests.post(url, headers=headers, json=payload, stream=stream, timeout=timeout)
49 base_logger.info("🟢 接收响应中...\n")
50 return res
51 except requests.exceptions.Timeout:
52 base_logger.error(f"❌ 请求超时(超过 {timeout} 秒)")
53 return None
54 except requests.exceptions.RequestException as e:
55 base_logger.error(f"❌ 请求失败:{e}")
56 return None
57
58
59def get_stream_chunks(response):

Callers 15

test_null_metadataFunction · 0.90
test_top_p_exceed_1Function · 0.90
test_stop_seq_exceed_numFunction · 0.90
test_multilingual_inputFunction · 0.90
test_too_long_inputFunction · 0.90
test_empty_inputFunction · 0.90
test_prompt_only_spacesFunction · 0.90

Calls 2

infoMethod · 0.45
errorMethod · 0.45

Tested by 15

test_null_metadataFunction · 0.72
test_top_p_exceed_1Function · 0.72
test_stop_seq_exceed_numFunction · 0.72
test_multilingual_inputFunction · 0.72
test_too_long_inputFunction · 0.72
test_empty_inputFunction · 0.72
test_prompt_only_spacesFunction · 0.72