|
1 | 1 | """Module with the logic to create and manage traces and steps."""
|
2 | 2 |
|
| 3 | +import time |
3 | 4 | import asyncio
|
4 |
| -import contextvars |
5 | 5 | import inspect
|
6 | 6 | import logging
|
7 |
| -import time |
8 |
| -from contextlib import contextmanager |
| 7 | +import contextvars |
| 8 | +from typing import Any, Dict, List, Tuple, Optional, Awaitable, Generator |
9 | 9 | from functools import wraps
|
10 |
| -from typing import Any, Awaitable, Dict, Generator, List, Optional, Tuple |
| 10 | +from contextlib import contextmanager |
11 | 11 |
|
| 12 | +from . import enums, steps, traces |
| 13 | +from .. import utils |
12 | 14 | from ..._client import Openlayer
|
| 15 | +from ..._base_client import DefaultHttpxClient |
13 | 16 | from ...types.inference_pipelines.data_stream_params import ConfigLlmData
|
14 |
| -from .. import utils |
15 |
| -from . import enums, steps, traces |
16 | 17 |
|
17 | 18 | logger = logging.getLogger(__name__)
|
18 | 19 |
|
19 |
| -_publish = utils.get_env_variable("OPENLAYER_DISABLE_PUBLISH") != "true" |
| 20 | +TRUE_LIST = ["true", "on", "1"] |
| 21 | + |
| 22 | +_publish = utils.get_env_variable("OPENLAYER_DISABLE_PUBLISH") not in TRUE_LIST |
| 23 | +_verify_ssl = utils.get_env_variable("OPENLAYER_VERIFY_SSL").lower() in TRUE_LIST |
20 | 24 | _client = None
|
21 | 25 | if _publish:
|
22 |
| - _client = Openlayer() |
| 26 | + if _verify_ssl: |
| 27 | + _client = Openlayer() |
| 28 | + else: |
| 29 | + _client = Openlayer( |
| 30 | + http_client=DefaultHttpxClient( |
| 31 | + verify=False, |
| 32 | + ), |
| 33 | + ) |
23 | 34 |
|
24 | 35 | _current_step = contextvars.ContextVar("current_step")
|
25 | 36 | _current_trace = contextvars.ContextVar("current_trace")
|
@@ -142,8 +153,8 @@ def trace(
|
142 | 153 | Examples
|
143 | 154 | --------
|
144 | 155 |
|
145 |
| - To trace a function, simply decorate it with the ``@trace()`` decorator. By doing so, |
146 |
| - the functions inputs, outputs, and metadata will be automatically logged to your |
| 156 | + To trace a function, simply decorate it with the ``@trace()`` decorator. By doing |
| 157 | + so, the functions inputs, outputs, and metadata will be automatically logged to your |
147 | 158 | Openlayer project.
|
148 | 159 |
|
149 | 160 | >>> import os
|
@@ -204,7 +215,8 @@ def wrapper(*func_args, **func_kwargs):
|
204 | 215 | log_context(inputs.get(context_kwarg))
|
205 | 216 | else:
|
206 | 217 | logger.warning(
|
207 |
| - "Context kwarg `%s` not found in inputs of the current function.", |
| 218 | + "Context kwarg `%s` not found in inputs of the " |
| 219 | + "current function.", |
208 | 220 | context_kwarg,
|
209 | 221 | )
|
210 | 222 |
|
@@ -235,8 +247,8 @@ def trace_async(
|
235 | 247 | Examples
|
236 | 248 | --------
|
237 | 249 |
|
238 |
| - To trace a function, simply decorate it with the ``@trace()`` decorator. By doing so, |
239 |
| - the functions inputs, outputs, and metadata will be automatically logged to your |
| 250 | + To trace a function, simply decorate it with the ``@trace()`` decorator. By doing |
| 251 | + so, the functions inputs, outputs, and metadata will be automatically logged to your |
240 | 252 | Openlayer project.
|
241 | 253 |
|
242 | 254 | >>> import os
|
@@ -297,7 +309,8 @@ async def wrapper(*func_args, **func_kwargs):
|
297 | 309 | log_context(inputs.get(context_kwarg))
|
298 | 310 | else:
|
299 | 311 | logger.warning(
|
300 |
| - "Context kwarg `%s` not found in inputs of the current function.", |
| 312 | + "Context kwarg `%s` not found in inputs of the " |
| 313 | + "current function.", |
301 | 314 | context_kwarg,
|
302 | 315 | )
|
303 | 316 |
|
|
0 commit comments