Skip to content

Commit 94019c4

Browse files
authored
Fix user (#46)
* 增加用户id * 单元测试
1 parent 12fbaa1 commit 94019c4

File tree

7 files changed

+29
-4
lines changed

7 files changed

+29
-4
lines changed

tests/integration_tests/test_charglm3.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def test_completions_charglm(logging_conf):
2525
"bot_name": "苏梦远",
2626
"user_name": "陆星辰"
2727
},
28+
user_id="12345678"
2829
)
2930
print(response)
3031

tests/integration_tests/test_chat.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def test_completions_temp0(logging_conf):
2727
top_p=0.7,
2828
temperature=0,
2929
max_tokens=2000,
30+
user_id="12345678"
3031
)
3132
print(response)
3233

@@ -57,6 +58,7 @@ def test_completions_temp1(logging_conf):
5758
top_p=0.7,
5859
temperature=1,
5960
max_tokens=2000,
61+
user_id="12345678"
6062
)
6163
print(response)
6264

@@ -89,6 +91,7 @@ def test_completions_top0(logging_conf):
8991
top_p=0,
9092
temperature=0.9,
9193
max_tokens=2000,
94+
user_id="12345678"
9295
)
9396
print(response)
9497

@@ -121,6 +124,7 @@ def test_completions_top1(logging_conf):
121124
top_p=1,
122125
temperature=0.9,
123126
max_tokens=2000,
127+
user_id="12345678"
124128
)
125129
print(response)
126130

@@ -160,6 +164,7 @@ def test_completions(logging_conf):
160164
}
161165
}
162166
],
167+
user_id="12345678",
163168
extra_body={"temperature": 0.5, "max_tokens": 50},
164169
)
165170
print(response)
@@ -201,6 +206,7 @@ def test_completions_disenable_web_search(logging_conf):
201206
}
202207
}
203208
],
209+
user_id="12345678",
204210
extra_body={"temperature": 0.5, "max_tokens": 50},
205211
)
206212
print(response)
@@ -243,6 +249,7 @@ def test_completions_enable_web_search(logging_conf):
243249
}
244250
],
245251
extra_body={"temperature": 0.5, "max_tokens": 50},
252+
user_id="12345678"
246253
)
247254
print(response)
248255

@@ -275,6 +282,7 @@ def test_completions_stream(logging_conf):
275282
{"role": "user", "content": "创造一个更精准、吸引人的slogan"}
276283
],
277284
extra_body={"temperature": 0.5, "max_tokens": 50},
285+
user_id="12345678"
278286
)
279287
for item in response:
280288
print(item)
@@ -323,7 +331,9 @@ def test_completions_vis(logging_conf):
323331
}
324332
]
325333
}
326-
]
334+
],
335+
336+
user_id="12345678"
327337
)
328338
print(response)
329339

@@ -371,7 +381,9 @@ def test_completions_vis_base64(test_file_path, logging_conf):
371381
}
372382
]
373383
}
374-
]
384+
],
385+
386+
user_id="12345678"
375387
)
376388
print(response)
377389

@@ -411,6 +423,8 @@ def test_async_completions(logging_conf):
411423
}
412424
],
413425
extra_body={"temperature": 0.5, "max_tokens": 50},
426+
427+
user_id="12345678"
414428
)
415429
print(response)
416430

tests/integration_tests/test_images.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def test_images(logging_conf):
1313
model="cogview-3", #填写需要调用的模型名称
1414
prompt="一只可爱的小猫咪",
1515
extra_body={"user_id": "1222212"},
16+
user_id="12345678"
1617
)
1718
print(response)
1819

tests/integration_tests/test_videos.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ def test_videos(logging_conf):
1111
try:
1212
response = client.videos.generations(
1313
model="cogvideo",
14-
prompt="一些相信光的人,举着奥特曼"
14+
prompt="一个开船的人",
15+
16+
user_id="1212222"
1517
)
1618
print(response)
1719

@@ -32,7 +34,8 @@ def test_videos_image_url(logging_conf):
3234
response = client.videos.generations(
3335
model="cogvideo",
3436
image_url="https://cdn.bigmodel.cn/static/platform/images/solutions/car/empowerment/icon-metric.png",
35-
prompt="一些相信光的人,举着奥特曼"
37+
prompt="一些相信光的人,举着奥特曼",
38+
user_id="12222211"
3639
)
3740
print(response)
3841

zhipuai/api_resource/chat/async_completions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def create(
2727
*,
2828
model: str,
2929
request_id: Optional[str] | NotGiven = NOT_GIVEN,
30+
user_id: Optional[str] | NotGiven = NOT_GIVEN,
3031
do_sample: Optional[Literal[False]] | Literal[True] | NotGiven = NOT_GIVEN,
3132
temperature: Optional[float] | NotGiven = NOT_GIVEN,
3233
top_p: Optional[float] | NotGiven = NOT_GIVEN,
@@ -72,6 +73,7 @@ def create(
7273
body = {
7374
"model": model,
7475
"request_id": request_id,
76+
"user_id": user_id,
7577
"temperature": temperature,
7678
"top_p": top_p,
7779
"do_sample": do_sample,

zhipuai/api_resource/chat/completions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def create(
2929
*,
3030
model: str,
3131
request_id: Optional[str] | NotGiven = NOT_GIVEN,
32+
user_id: Optional[str] | NotGiven = NOT_GIVEN,
3233
do_sample: Optional[Literal[False]] | Literal[True] | NotGiven = NOT_GIVEN,
3334
stream: Optional[Literal[False]] | Literal[True] | NotGiven = NOT_GIVEN,
3435
temperature: Optional[float] | NotGiven = NOT_GIVEN,
@@ -74,6 +75,7 @@ def create(
7475
body = deepcopy_minimal({
7576
"model": model,
7677
"request_id": request_id,
78+
"user_id": user_id,
7779
"temperature": temperature,
7880
"top_p": top_p,
7981
"do_sample": do_sample,

zhipuai/api_resource/images.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def generations(
2929
style: Optional[str] | NotGiven = NOT_GIVEN,
3030
user: str | NotGiven = NOT_GIVEN,
3131
request_id: Optional[str] | NotGiven = NOT_GIVEN,
32+
user_id: Optional[str] | NotGiven = NOT_GIVEN,
3233
extra_headers: Headers | None = None,
3334
extra_body: Body | None = None,
3435
disable_strict_validation: Optional[bool] | None = None,
@@ -48,6 +49,7 @@ def generations(
4849
"size": size,
4950
"style": style,
5051
"user": user,
52+
"user_id": user_id,
5153
"request_id": request_id,
5254
},
5355
options=make_request_options(

0 commit comments

Comments
 (0)