30
30
31
31
32
32
def _make_message (content : discuss_types .MessageOptions ) -> glm .Message :
33
+ """Creates a `glm.Message` object from the provided content."""
33
34
if isinstance (content , glm .Message ):
34
35
return content
35
36
if isinstance (content , str ):
@@ -39,6 +40,20 @@ def _make_message(content: discuss_types.MessageOptions) -> glm.Message:
39
40
40
41
41
42
def _make_messages (messages : discuss_types .MessagesOptions ) -> List [glm .Message ]:
43
+ """
44
+ Creates a list of `glm.Message` objects from the provided messages.
45
+
46
+ This function takes a variety of message content inputs, such as strings, dictionaries,
47
+ or `glm.Message` objects, and creates a list of `glm.Message` objects. It ensures that
48
+ the authors of the messages alternate appropriately. If authors are not provided,
49
+ default authors are assigned based on their position in the list.
50
+
51
+ Args:
52
+ messages: The messages to convert.
53
+
54
+ Returns:
55
+ A list of `glm.Message` objects with alternating authors.
56
+ """
42
57
if isinstance (messages , (str , dict , glm .Message )):
43
58
messages = [_make_message (messages )]
44
59
else :
@@ -71,6 +86,7 @@ def _make_messages(messages: discuss_types.MessagesOptions) -> List[glm.Message]
71
86
72
87
73
88
def _make_example (item : discuss_types .ExampleOptions ) -> glm .Example :
89
+ """Creates a `glm.Example` object from the provided item."""
74
90
if isinstance (item , glm .Example ):
75
91
return item
76
92
@@ -91,6 +107,21 @@ def _make_example(item: discuss_types.ExampleOptions) -> glm.Example:
91
107
def _make_examples_from_flat (
92
108
examples : List [discuss_types .MessageOptions ],
93
109
) -> List [glm .Example ]:
110
+ """
111
+ Creates a list of `glm.Example` objects from a list of message options.
112
+
113
+ This function takes a list of `discuss_types.MessageOptions` and pairs them into
114
+ `glm.Example` objects. The input examples must be in pairs to create valid examples.
115
+
116
+ Args:
117
+ examples: The list of `discuss_types.MessageOptions`.
118
+
119
+ Returns:
120
+ A list of `glm.Example objects` created by pairing up the provided messages.
121
+
122
+ Raises:
123
+ ValueError: If the provided list of examples is not of even length.
124
+ """
94
125
if len (examples ) % 2 != 0 :
95
126
raise ValueError (
96
127
textwrap .dedent (
@@ -116,6 +147,19 @@ def _make_examples_from_flat(
116
147
117
148
118
149
def _make_examples (examples : discuss_types .ExamplesOptions ) -> List [glm .Example ]:
150
+ """
151
+ Creates a list of `glm.Example` objects from the provided examples.
152
+
153
+ This function takes various types of example content inputs and creates a list
154
+ of `glm.Example` objects. It handles the conversion of different input types and ensures
155
+ the appropriate structure for creating valid examples.
156
+
157
+ Args:
158
+ examples: The examples to convert.
159
+
160
+ Returns:
161
+ A list of `glm.Example` objects created from the provided examples.
162
+ """
119
163
if isinstance (examples , glm .Example ):
120
164
return [examples ]
121
165
@@ -155,6 +199,23 @@ def _make_message_prompt_dict(
155
199
examples : discuss_types .ExamplesOptions | None = None ,
156
200
messages : discuss_types .MessagesOptions | None = None ,
157
201
) -> glm .MessagePrompt :
202
+ """
203
+ Creates a `glm.MessagePrompt` object from the provided prompt components.
204
+
205
+ This function constructs a `glm.MessagePrompt` object using the provided `context`, `examples`,
206
+ or `messages`. It ensures the proper structure and handling of the input components.
207
+
208
+ Either pass a `prompt` or it's component `context`, `examples`, `messages`.
209
+
210
+ Args:
211
+ prompt: The complete prompt components.
212
+ context: The context for the prompt.
213
+ examples: The examples for the prompt.
214
+ messages: The messages for the prompt.
215
+
216
+ Returns:
217
+ A `glm.MessagePrompt` object created from the provided prompt components.
218
+ """
158
219
if prompt is None :
159
220
prompt = dict (
160
221
context = context ,
@@ -201,6 +262,7 @@ def _make_message_prompt(
201
262
examples : discuss_types .ExamplesOptions | None = None ,
202
263
messages : discuss_types .MessagesOptions | None = None ,
203
264
) -> glm .MessagePrompt :
265
+ """Creates a `glm.MessagePrompt` object from the provided prompt components."""
204
266
prompt = _make_message_prompt_dict (
205
267
prompt = prompt , context = context , examples = examples , messages = messages
206
268
)
@@ -219,6 +281,7 @@ def _make_generate_message_request(
219
281
top_k : float | None = None ,
220
282
prompt : discuss_types .MessagePromptOptions | None = None ,
221
283
) -> glm .GenerateMessageRequest :
284
+ """Creates a `glm.GenerateMessageRequest` object for generating messages."""
222
285
model = model_types .make_model_name (model )
223
286
224
287
prompt = _make_message_prompt (
@@ -236,6 +299,8 @@ def _make_generate_message_request(
236
299
237
300
238
301
def set_doc (doc ):
302
+ """A decorator to set the docstring of a function."""
303
+
239
304
def inner (f ):
240
305
f .__doc__ = doc
241
306
return f
0 commit comments