You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Every call to the decorated function will create a Log against the Tool. For example:
268
+
The return value of the decorated function must be JSON serializable.
271
269
272
-
```python
273
-
calculator(a=1, b=2)
274
-
```
270
+
If the function raises an exception, the created Log will have `output`
271
+
set to null, and the `error` field populated.
275
272
276
-
Will create the following Log:
273
+
:param path: The path of the File in the Humanloop workspace.
277
274
278
-
```python
279
-
{
280
-
"inputs": {
281
-
a: 1,
282
-
b: 2
283
-
},
284
-
"output": 3
285
-
}
286
-
```
275
+
:param setup_values: Values needed to setup the Tool, defined in [JSON Schema](https://json-schema.org/)
287
276
288
-
The decorated function should return a string or the output should be JSON serializable. If
289
-
the output cannot be serialized, TypeError will be raised.
290
-
291
-
If the function raises an exception, the log created by the function will have the output
292
-
field set to None and the error field set to the string representation of the exception.
293
-
294
-
:param path: The path to the Tool. If not provided, the function name
295
-
will be used as the path and the File will be created in the root
296
-
of your organization's workspace.
297
-
298
-
:param tool_kernel: Attributes that define the Tool. See `class:ToolKernelRequestParams`
277
+
:param attributes: Additional fields to describe the Tool. Helpful to separate Tool versions from each other with details on how they were created or used.
299
278
"""
300
279
returntool_decorator_factory(
301
280
opentelemetry_tracer=self._opentelemetry_tracer,
@@ -310,13 +289,13 @@ def flow(
310
289
path: str,
311
290
attributes: Optional[dict[str, Any]] =None,
312
291
):
313
-
"""Decorator for declaring a [Flow](https://humanloop.com/docs/explanation/flows) in code.
292
+
"""Trace SDK logging calls through [Flows](https://humanloop.com/docs/explanation/flows).
293
+
294
+
Use it as the entrypoint of your LLM feature. Logging calls like `prompts.call(...)`,
295
+
`tools.call(...)`, or other Humanloop decorators will be automatically added to the trace.
314
296
315
-
A [Flow](https://humanloop.com/docs/explanation/flows) wrapped callable should
316
-
be used as the entrypoint of your LLM feature. Call other functions wrapped with
317
-
Humanloop decorators to create a trace of Logs on Humanloop.
297
+
For example:
318
298
319
-
Here's an example of declaring a [Flow](https://humanloop.com/docs/explanation/flows) in code:
320
299
```python
321
300
@prompt(template="You are an assistant on the following topics: {{topics}}.")
322
301
def call_llm(messages):
@@ -330,7 +309,7 @@ def call_llm(messages):
330
309
).choices[0].message.content
331
310
332
311
@flow(attributes={"version": "v1"})
333
-
def entrypoint():
312
+
def agent():
334
313
while True:
335
314
messages = []
336
315
user_input = input("You: ")
@@ -342,23 +321,23 @@ def entrypoint():
342
321
print(f"Assistant: {response}")
343
322
```
344
323
345
-
In this example, the Flow instruments a conversational agent where the
346
-
Prompt defined in `call_llm` is called multiple times in a loop. Calling
347
-
`entrypoint` will create a Flow Trace under which multiple Prompt Logs
348
-
will be nested, allowing you to track the whole conversation session
349
-
between the user and the assistant.
324
+
Each call to agent will create a trace corresponding to the conversation
325
+
session. Multiple Prompt Logs will be created as the LLM is called. They
326
+
will be added to the trace, allowing you to see the whole conversation
327
+
in the UI.
350
328
351
-
The decorated function should return a string or the output should be JSON serializable. If
352
-
the output cannot be serialized, TypeError will be raised.
329
+
If the function returns a ChatMessage-like object, the Log will
330
+
populate the `output_message` field. Otherwise, it will serialize
331
+
the return value and populate the `output` field.
353
332
354
-
If the function raises an exception, the log created by the function will have the output
355
-
field set to None and the error field set to the string representation of the exception.
333
+
If an exception is raised, the output fields will be set to None
334
+
and the error message will be set in the Log's `error` field.
356
335
357
336
:param path: The path to the Flow. If not provided, the function name
358
337
will be used as the path and the File will be created in the root
359
338
of your organization workspace.
360
339
361
-
:param flow_kernel: Attributes that define the Flow. See `class:ToolKernelRequestParams`
340
+
:param attributes: Additional fields to describe the Flow. Helpful to separate Flow versions from each other with details on how they were created or used.
0 commit comments