@@ -69,15 +69,19 @@ def _make_messages(
69
69
elif len (even_authors ) == 1 :
70
70
even_author = even_authors .pop ()
71
71
else :
72
- raise discuss_types .AuthorError ("Authors are not strictly alternating" )
72
+ raise discuss_types .AuthorError (
73
+ "Invalid sequence: Authors in the discussion must alternate strictly."
74
+ )
73
75
74
76
odd_authors = set (msg .author for msg in messages [1 ::2 ] if msg .author )
75
77
if not odd_authors :
76
78
odd_author = "1"
77
79
elif len (odd_authors ) == 1 :
78
80
odd_author = odd_authors .pop ()
79
81
else :
80
- raise discuss_types .AuthorError ("Authors are not strictly alternating" )
82
+ raise discuss_types .AuthorError (
83
+ "Invalid sequence: Authors in the discussion must alternate strictly."
84
+ )
81
85
82
86
if all (msg .author for msg in messages ):
83
87
return messages
@@ -130,8 +134,8 @@ def _make_examples_from_flat(
130
134
raise ValueError (
131
135
textwrap .dedent (
132
136
f"""\
133
- You must pass `Primer` objects, pairs of messages, or an * even* number of messages, got:
134
- { len (examples )} messages"""
137
+ Invalid input: You must pass either `Primer` objects, pairs of messages, or an even number of messages.
138
+ Currently, { len (examples )} messages were provided, which is an odd number. """
135
139
)
136
140
)
137
141
result = []
@@ -186,7 +190,7 @@ def _make_examples(
186
190
else :
187
191
if not ("input" in first and "output" in first ):
188
192
raise TypeError (
189
- "To create an `Example` from a dict you must supply both `input` and an `output` keys"
193
+ "Invalid dictionary format: To create an `Example` instance, the dictionary must contain both `input` and `output` keys. "
190
194
)
191
195
else :
192
196
if isinstance (first , discuss_types .MESSAGE_OPTIONS ):
@@ -232,8 +236,7 @@ def _make_message_prompt_dict(
232
236
flat_prompt = (context is not None ) or (examples is not None ) or (messages is not None )
233
237
if flat_prompt :
234
238
raise ValueError (
235
- "You can't set `prompt`, and its fields `(context, examples, messages)`"
236
- " at the same time"
239
+ "Invalid configuration: Either `prompt` or its fields `(context, examples, messages)` should be set, but not both simultaneously."
237
240
)
238
241
if isinstance (prompt , glm .MessagePrompt ):
239
242
return prompt
@@ -245,7 +248,7 @@ def _make_message_prompt_dict(
245
248
keys = set (prompt .keys ())
246
249
if not keys .issubset (discuss_types .MESSAGE_PROMPT_KEYS ):
247
250
raise KeyError (
248
- f"Found extra entries in the prompt dictionary : { keys - discuss_types .MESSAGE_PROMPT_KEYS } "
251
+ f"Invalid prompt dictionary: Extra entries found that are not recognized : { keys - discuss_types .MESSAGE_PROMPT_KEYS } . Please check the keys. "
249
252
)
250
253
251
254
examples = prompt .get ("examples" , None )
@@ -319,7 +322,7 @@ def chat(
319
322
client : glm .DiscussServiceClient | None = None ,
320
323
request_options : helper_types .RequestOptionsType | None = None ,
321
324
) -> discuss_types .ChatResponse :
322
- """Calls the API and returns a `types.ChatResponse` containing the response.
325
+ """Calls the API to initiate a chat with a model using provided parameters
323
326
324
327
Args:
325
328
model: Which model to call, as a string or a `types.Model`.
@@ -419,6 +422,7 @@ async def chat_async(
419
422
client : glm .DiscussServiceAsyncClient | None = None ,
420
423
request_options : helper_types .RequestOptionsType | None = None ,
421
424
) -> discuss_types .ChatResponse :
425
+ """Calls the API asynchronously to initiate a chat with a model using provided parameters"""
422
426
request = _make_generate_message_request (
423
427
model = model ,
424
428
context = context ,
@@ -473,12 +477,13 @@ def reply(
473
477
request_options : helper_types .RequestOptionsType | None = None ,
474
478
) -> discuss_types .ChatResponse :
475
479
if isinstance (self ._client , glm .DiscussServiceAsyncClient ):
476
- raise TypeError (f"reply can't be called on an async client, use reply_async instead." )
480
+ raise TypeError (
481
+ "Invalid operation: The 'reply' method cannot be called on an asynchronous client. Please use the 'reply_async' method instead."
482
+ )
477
483
if self .last is None :
478
484
raise ValueError (
479
- "The last response from the model did not return any candidates.\n "
480
- "Check the `.filters` attribute to see why the responses were filtered:\n "
481
- f"{ self .filters } "
485
+ f"Invalid operation: No candidates returned from the model's last response. "
486
+ f"Please inspect the '.filters' attribute to understand why responses were filtered out. Current filters: { self .filters } "
482
487
)
483
488
484
489
request = self .to_dict ()
@@ -497,7 +502,7 @@ async def reply_async(
497
502
) -> discuss_types .ChatResponse :
498
503
if isinstance (self ._client , glm .DiscussServiceClient ):
499
504
raise TypeError (
500
- f" reply_async can't be called on a non-async client, use reply instead."
505
+ "Invalid method call: ` reply_async` is not supported on a non-async client. Please use the ` reply` method instead."
501
506
)
502
507
request = self .to_dict ()
503
508
request .pop ("candidates" )
@@ -577,6 +582,8 @@ def count_message_tokens(
577
582
client : glm .DiscussServiceAsyncClient | None = None ,
578
583
request_options : helper_types .RequestOptionsType | None = None ,
579
584
) -> discuss_types .TokenCount :
585
+ """Calls the API to calculate the number of tokens used in the prompt."""
586
+
580
587
model = model_types .make_model_name (model )
581
588
prompt = _make_message_prompt (prompt , context = context , examples = examples , messages = messages )
582
589
0 commit comments