Skip to content

Commit 558df34

Browse files
author
Andrei Bratu
committed
Relax dependency requirements
1 parent 649718b commit 558df34

File tree

7 files changed

+541
-512
lines changed

7 files changed

+541
-512
lines changed

poetry.lock

Lines changed: 500 additions & 489 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,28 @@ packages = [
3131
Repository = 'https://github.com/humanloop/humanloop-python'
3232

3333
[tool.poetry.dependencies]
34-
python = "^3.9"
34+
python = ">=3.9,<4"
3535
httpx = ">=0.21.2"
3636
httpx-sse = "0.4.0"
3737
pydantic = ">= 1.9.2"
3838
pydantic-core = "^2.18.2"
3939
typing_extensions = ">= 4.0.0"
4040
parse = "^1.20.2"
41-
opentelemetry-sdk = "<=1.27.0"
42-
opentelemetry-api = "<=1.27.0"
43-
opentelemetry-instrumentation-openai = "<=0.33.3"
44-
opentelemetry-instrumentation-cohere = "<=0.33.3"
45-
opentelemetry-instrumentation-anthropic = "<=0.33.3"
46-
opentelemetry-instrumentation-groq = "<=0.33.3"
47-
opentelemetry-instrumentation-replicate = "<=0.33.3"
41+
opentelemetry-sdk = ">=1.20.0"
42+
opentelemetry-api = ">=1.20.0"
43+
opentelemetry-instrumentation-openai = ">=0.30"
44+
opentelemetry-instrumentation-cohere = ">=0.30"
45+
opentelemetry-instrumentation-anthropic = ">=0.30"
46+
opentelemetry-instrumentation-groq = ">=0.33.11"
47+
opentelemetry-instrumentation-replicate = ">=0.30"
48+
opentelemetry-instrumentation-bedrock = ">=0.0.1"
4849

4950
[tool.poetry.group.dev.dependencies]
50-
parse-type = "^0.6.4"
51-
anthropic = "^0.37.1"
52-
groq = "^0.11.0"
53-
cohere = "^5.11.2"
54-
replicate = "^1.0.3"
51+
parse-type = ">=0.6.4"
52+
anthropic = ">=0.37.1"
53+
groq = ">=0.11.0"
54+
cohere = ">=3.0"
55+
replicate = ">=1.0.3"
5556
jsonschema = "^4.23.0"
5657
types-jsonschema = "^4.23.0.20240813"
5758
mypy = "^1.0.1"
@@ -62,7 +63,7 @@ types-python-dateutil = "^2.9.0.20240316"
6263
ruff = "^0.5.6"
6364
python-dotenv = "^1.0.1"
6465
openai = "^1.52.2"
65-
pandas = "^2.2.3"
66+
pandas = ">=1.3.2"
6667

6768
[tool.pytest.ini_options]
6869
testpaths = [ "tests" ]

src/humanloop/decorators/flow.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
import logging
32
from functools import wraps
43
from typing import Any, Callable, Mapping, Optional, Sequence
@@ -64,19 +63,23 @@ def wrapper(*args: Sequence[Any], **kwargs: Mapping[str, Any]) -> Any:
6463
# Call the decorated function
6564
try:
6665
output = func(*args, **kwargs)
67-
output = jsonify_if_not_string(
66+
output_stringified = jsonify_if_not_string(
6867
func=func,
6968
output=output,
7069
)
7170
error = None
7271
except Exception as e:
7372
logger.error(f"Error calling {func.__name__}: {e}")
7473
output = None
74+
output_stringified = jsonify_if_not_string(
75+
func=func,
76+
output=None,
77+
)
7578
error = str(e)
7679

7780
flow_log = {
7881
"inputs": inputs,
79-
"output": output,
82+
"output": output_stringified,
8083
"error": error,
8184
}
8285
if inputs:

src/humanloop/decorators/prompt.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,23 @@ def wrapper(*args: Sequence[Any], **kwargs: Mapping[str, Any]) -> Any:
5454
# Call the decorated function
5555
try:
5656
output = func(*args, **kwargs)
57-
output = jsonify_if_not_string(
57+
output_stringified = jsonify_if_not_string(
5858
func=func,
5959
output=output,
6060
)
6161
error = None
6262
except Exception as e:
6363
logger.error(f"Error calling {func.__name__}: {e}")
6464
output = None
65+
output_stringified = jsonify_if_not_string(
66+
func=func,
67+
output=output,
68+
)
6569
error = str(e)
6670

6771
prompt_log = {
6872
"inputs": args_to_inputs(func, args, kwargs),
69-
"output": output,
73+
"output": output_stringified,
7074
"error": error,
7175
}
7276
write_to_opentelemetry_span(

src/humanloop/decorators/tool.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,24 @@ def wrapper(*args, **kwargs):
7272
# Call the decorated function
7373
try:
7474
output = func(*args, **kwargs)
75-
output = jsonify_if_not_string(
75+
output_stringified = jsonify_if_not_string(
7676
func=func,
7777
output=output,
7878
)
7979
error = None
8080
except Exception as e:
8181
logger.error(f"Error calling {func.__name__}: {e}")
8282
output = None
83+
output_stringified = jsonify_if_not_string(
84+
func=func,
85+
output=output,
86+
)
8387
error = str(e)
8488

8589
# Populate known Tool Log attributes
8690
tool_log = {
8791
"inputs": args_to_inputs(func, args, kwargs),
88-
"output": output,
92+
"output": output_stringified,
8993
"error": error,
9094
}
9195

src/humanloop/otel/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ def instrument_provider(provider: TracerProvider):
3737

3838
ReplicateInstrumentor().instrument(tracer_provider=provider)
3939

40+
if module_is_installed("boto3"):
41+
from opentelemetry.instrumentation.bedrock import BedrockInstrumentor
42+
43+
BedrockInstrumentor().instrument(tracer_provider=provider)
44+
4045

4146
class FlowContext(TypedDict):
4247
trace_id: NotRequired[str]

tests/decorators/test_tool_decorator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ def calculator(operation: str, num1: float, num2: float) -> float:
3131

3232
# WHEN calling the @tool decorated function
3333
result = calculator(operation="add", num1=1, num2=2)
34+
assert result == 3
3435
# THEN a single span is created and the log and file attributes are correctly set
3536
spans = exporter.get_finished_spans()
3637
assert len(spans) == 1
3738
hl_file: dict[str, Any] = read_from_opentelemetry_span(span=spans[0], key=HUMANLOOP_FILE_KEY)
3839
hl_log: dict[str, Any] = read_from_opentelemetry_span(span=spans[0], key=HUMANLOOP_LOG_KEY)
39-
assert hl_log["output"] == result == 3
40+
assert hl_log["output"] == str(result) == "3"
4041
assert hl_log["inputs"] == {
4142
"operation": "add",
4243
"num1": 1,
@@ -408,7 +409,7 @@ def foo_bar(foo: Foo):
408409
return foo.a + foo.b # type: ignore
409410

410411
# THEN a ValueError is raised
411-
assert exc.value.args[0].startswith("foo_bar: Unsupported type hint")
412+
assert exc.value.args[0].startswith("Error parsing signature of @tool annotated function foo_bar")
412413

413414

414415
def test_tool_as_higher_order_function(

0 commit comments

Comments
 (0)