9
9
10
10
import json
11
11
12
- from core import (
13
- TEMPLATE ,
14
- URL ,
15
- build_request_payload ,
16
- send_request ,
17
- )
12
+ from core import TEMPLATE , URL , build_request_payload , send_request
18
13
19
14
COMPLETIONS_URL = URL .replace ("/v1/chat/completions" , "/v1/completions" )
20
15
@@ -29,17 +24,17 @@ def test_completion_stream_text_after_process_raw_prediction():
29
24
"stream" : True ,
30
25
"stream_options" : {"include_usage" : True , "continuous_usage_stats" : True },
31
26
"max_tokens" : 50 ,
32
- "return_token_ids" : True
27
+ "return_token_ids" : True ,
33
28
}
34
-
29
+
35
30
payload = build_request_payload (TEMPLATE , data )
36
31
resp = send_request (COMPLETIONS_URL , payload , stream = True )
37
32
for line in resp .iter_lines (decode_unicode = True ):
38
33
if line .strip () == "data: [DONE]" :
39
34
break
40
35
if line .strip () == "" or not line .startswith ("data: " ):
41
36
continue
42
- line = line [len ("data: " ):]
37
+ line = line [len ("data: " ) :]
43
38
response_data = json .loads (line )
44
39
45
40
choice = response_data ["choices" ][0 ]
@@ -51,21 +46,16 @@ def test_completion_stream_text_after_process_raw_prediction():
51
46
reasoning_content = choice ["reasoning_content" ]
52
47
text = choice ["text" ]
53
48
assert reasoning_content or text in raw_prediction , "raw_prediction取值结果不正确"
54
- if "finish_reason" in line .strip () :
49
+ if "finish_reason" in line .strip ():
55
50
break
56
51
57
-
58
- def test_completion_text_after_process_raw_predictio_return_tokrn_ids ():
52
+
53
+ def test_completion_text_after_process_raw_predictio_return_token_ids ():
59
54
"""
60
55
/v1/completions接口,非流式接口
61
56
返回属性"text_after_process"和"reasoning_content"
62
57
"""
63
- data = {
64
- "stream" : False ,
65
- "prompt" : "你是谁" ,
66
- "max_tokens" : 50 ,
67
- "return_token_ids" : True
68
- }
58
+ data = {"stream" : False , "prompt" : "你是谁" , "max_tokens" : 50 , "return_token_ids" : True }
69
59
payload = build_request_payload (TEMPLATE , data )
70
60
resp = send_request (COMPLETIONS_URL , payload ).json ()
71
61
@@ -80,14 +70,10 @@ def test_completion_text_after_process_raw_predictio_return_tokrn_ids():
80
70
81
71
def test_completion_text_after_process_raw_prediction ():
82
72
"""
83
- /v1/completions接口,无return_tokrn_ids参数
73
+ /v1/completions接口,无return_token_ids参数
84
74
非流式接口中,无return token ids 属性"text_after_process"和"reasoning_content"值为null
85
75
"""
86
- data = {
87
- "stream" : False ,
88
- "prompt" : "你是谁" ,
89
- "max_tokens" : 50
90
- }
76
+ data = {"stream" : False , "prompt" : "你是谁" , "max_tokens" : 50 }
91
77
payload = build_request_payload (TEMPLATE , data )
92
78
resp = send_request (COMPLETIONS_URL , payload ).json ()
93
79
@@ -108,17 +94,17 @@ def test_stream_text_after_process_raw_prediction():
108
94
"stream" : True ,
109
95
"stream_options" : {"include_usage" : True , "continuous_usage_stats" : True },
110
96
"max_tokens" : 50 ,
111
- "return_token_ids" : True
97
+ "return_token_ids" : True ,
112
98
}
113
99
114
100
payload = build_request_payload (TEMPLATE , data )
115
101
resp = send_request (URL , payload , stream = True )
116
102
for line in resp .iter_lines (decode_unicode = True ):
117
- if line .strip () == "data: [DONE]" :
103
+ if line .strip () == "data: [DONE]" :
118
104
break
119
105
if line .strip () == "" or not line .startswith ("data: " ):
120
106
continue
121
- line = line [len ("data: " ):]
107
+ line = line [len ("data: " ) :]
122
108
response_data = json .loads (line )
123
109
124
110
choice = response_data ["choices" ][0 ]
@@ -130,11 +116,11 @@ def test_stream_text_after_process_raw_prediction():
130
116
reasoning_content = choice ["delta" ]["reasoning_content" ]
131
117
content = choice ["delta" ]["content" ]
132
118
assert reasoning_content or content in raw_prediction , "raw_prediction取值结果不正确"
133
- if "finish_reason" in line .strip () :
119
+ if "finish_reason" in line .strip ():
134
120
break
135
121
136
-
137
- def test_text_after_process_raw_prediction_return_tokrn_ids ():
122
+
123
+ def test_text_after_process_raw_prediction_return_token_ids ():
138
124
"""
139
125
/v1/chat/completions接口,非流式接口
140
126
返回属性"text_after_process"和"reasoning_content"
@@ -161,7 +147,7 @@ def test_text_after_process_raw_prediction_return_tokrn_ids():
161
147
162
148
def test_text_after_process_raw_prediction ():
163
149
"""
164
- /v1/chat/completions接口,无return_tokrn_ids参数
150
+ /v1/chat/completions接口,无return_token_ids参数
165
151
无return token ids 属性"text_after_process"和"reasoning_content"值为null
166
152
"""
167
153
data = {
@@ -179,5 +165,3 @@ def test_text_after_process_raw_prediction():
179
165
180
166
raw_prediction = resp ["choices" ][0 ]["message" ]["raw_prediction" ]
181
167
assert raw_prediction is None , "raw_prediction取值结果不正确"
182
-
183
-
0 commit comments