Skip to content

Commit

Permalink
chore: use json.dumps instead of str in sanitate attrs (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanbohan authored Oct 27, 2023
1 parent 9611cc0 commit 5288f48
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "greptimeai"
version = "0.1.2"
version = "0.1.3"
description = "Observability tool for LLM application"
authors = [
{ name = "Greptime", email = "[email protected]" },
Expand Down
10 changes: 4 additions & 6 deletions src/greptimeai/langchain/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging
import time
from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, Union
Expand All @@ -21,9 +22,6 @@
_MODEL_NAME_LABEL = "model"

_INSTRUMENT_LIB_NAME = "greptime-llm"
_INSTRUMENT_LIB_VERSION = (
"0.1.2"
)

_GREPTIME_HOST_ENV_NAME = "GREPTIMEAI_HOST"
_GREPTIME_DATABASE_ENV_NAME = "GREPTIMEAI_DATABASE"
Expand Down Expand Up @@ -78,7 +76,7 @@ def _sanitate_list(lst: list) -> list:
if _is_valid_otel_attributes_value_type(item):
result.append(item)
else:
result.append(str(item))
result.append(json.dumps(item))
return result

for key, val in attrs.items():
Expand All @@ -87,7 +85,7 @@ def _sanitate_list(lst: list) -> list:
elif isinstance(val, list):
result[key] = _sanitate_list(val)
else:
result[key] = str(val)
result[key] = json.dumps(val)

return result

Expand Down Expand Up @@ -168,7 +166,7 @@ def _parse_generations(
parse LLMResult.generations[0] to structured fields
"""
if gens and len(gens) > 0:
return filter(None, [_parse_generation(gen) for gen in gens if gen])
return list(filter(None, [_parse_generation(gen) for gen in gens if gen]))

return None

Expand Down
8 changes: 3 additions & 5 deletions src/greptimeai/langchain/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
_GREPTIME_PASSWORD_ENV_NAME,
_GREPTIME_USERNAME_ENV_NAME,
_INSTRUMENT_LIB_NAME,
_INSTRUMENT_LIB_VERSION,
_MODEL_NAME_LABEL,
_SPAN_NAME_AGENT,
_SPAN_NAME_CHAIN,
Expand All @@ -54,6 +53,7 @@
_TimeTable,
_TraceTable,
)
from greptimeai.version import __version__


class _Collector:
Expand Down Expand Up @@ -168,12 +168,10 @@ def _setup_otel_metrics(self):
"""
self._tracer = trace.get_tracer(
instrumenting_module_name=_INSTRUMENT_LIB_NAME,
instrumenting_library_version=_INSTRUMENT_LIB_VERSION,
instrumenting_library_version=__version__,
)

meter = metrics.get_meter(
name=_INSTRUMENT_LIB_NAME, version=_INSTRUMENT_LIB_VERSION
)
meter = metrics.get_meter(name=_INSTRUMENT_LIB_NAME, version=__version__)

self._prompt_tokens_count = meter.create_counter(
"llm_prompt_tokens",
Expand Down
1 change: 1 addition & 0 deletions src/greptimeai/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.1.3"

0 comments on commit 5288f48

Please sign in to comment.