From 2ab2a5603e72fc6c5e815ca7cd1e237068372f1c Mon Sep 17 00:00:00 2001 From: Karthik Kalyanaraman <105607645+karthikscale3@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:53:39 -0700 Subject: [PATCH 1/5] Revert back to Langtrace Exporter (#385) * fix * Bump version --- src/langtrace_python_sdk/langtrace.py | 3 ++- src/langtrace_python_sdk/version.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/langtrace_python_sdk/langtrace.py b/src/langtrace_python_sdk/langtrace.py index 94749621..b01aade2 100644 --- a/src/langtrace_python_sdk/langtrace.py +++ b/src/langtrace_python_sdk/langtrace.py @@ -74,6 +74,7 @@ validate_instrumentations, ) from langtrace_python_sdk.utils.langtrace_sampler import LangtraceSampler +from langtrace_python_sdk.extensions.langtrace_exporter import LangTraceExporter from sentry_sdk.types import Event, Hint logging.disable(level=logging.INFO) @@ -149,7 +150,7 @@ def get_exporter(config: LangtraceConfig, host: str): headers = get_headers(config) host = f"{host}/api/trace" if host == LANGTRACE_REMOTE_URL else host if "http" in host.lower() or "https" in host.lower(): - return HTTPExporter(endpoint=host, headers=headers) + return LangTraceExporter(host, config.api_key, config.disable_logging) else: return GRPCExporter(endpoint=host, headers=headers) diff --git a/src/langtrace_python_sdk/version.py b/src/langtrace_python_sdk/version.py index d539d50c..911557b8 100644 --- a/src/langtrace_python_sdk/version.py +++ b/src/langtrace_python_sdk/version.py @@ -1 +1 @@ -__version__ = "3.1.1" +__version__ = "3.1.2" From d74f25cd90b289eb6e1a59187bd2c0e4d0905deb Mon Sep 17 00:00:00 2001 From: Karthik Kalyanaraman <105607645+karthikscale3@users.noreply.github.com> Date: Mon, 21 Oct 2024 18:58:58 -0700 Subject: [PATCH 2/5] Release 3.1.13 (#388) * remove logs * remove requirements * Bump version * Squash * Support xAI (#387) * support xai * fix --- src/langtrace_python_sdk/constants/instrumentation/common.py | 1 + src/langtrace_python_sdk/instrumentation/groq/patch.py | 4 ++++ src/langtrace_python_sdk/instrumentation/litellm/patch.py | 4 ++++ src/langtrace_python_sdk/instrumentation/openai/patch.py | 4 ++++ src/langtrace_python_sdk/version.py | 2 +- 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/langtrace_python_sdk/constants/instrumentation/common.py b/src/langtrace_python_sdk/constants/instrumentation/common.py index 4c4ec63f..53ff5d65 100644 --- a/src/langtrace_python_sdk/constants/instrumentation/common.py +++ b/src/langtrace_python_sdk/constants/instrumentation/common.py @@ -33,6 +33,7 @@ "MISTRAL": "Mistral", "EMBEDCHAIN": "Embedchain", "AUTOGEN": "Autogen", + "XAI": "XAI", } LANGTRACE_ADDITIONAL_SPAN_ATTRIBUTES_KEY = "langtrace_additional_attributes" diff --git a/src/langtrace_python_sdk/instrumentation/groq/patch.py b/src/langtrace_python_sdk/instrumentation/groq/patch.py index 220387ac..9b9b545e 100644 --- a/src/langtrace_python_sdk/instrumentation/groq/patch.py +++ b/src/langtrace_python_sdk/instrumentation/groq/patch.py @@ -55,6 +55,8 @@ def traced_method(wrapped, instance, args, kwargs): service_provider = SERVICE_PROVIDERS["PPLX"] elif "azure" in get_base_url(instance): service_provider = SERVICE_PROVIDERS["AZURE"] + elif "x.ai" in get_base_url(instance): + service_provider = SERVICE_PROVIDERS["XAI"] # handle tool calls in the kwargs llm_prompts = [] @@ -274,6 +276,8 @@ async def traced_method(wrapped, instance, args, kwargs): service_provider = SERVICE_PROVIDERS["PPLX"] elif "azure" in get_base_url(instance): service_provider = SERVICE_PROVIDERS["AZURE"] + elif "x.ai" in get_base_url(instance): + service_provider = SERVICE_PROVIDERS["XAI"] # handle tool calls in the kwargs llm_prompts = [] diff --git a/src/langtrace_python_sdk/instrumentation/litellm/patch.py b/src/langtrace_python_sdk/instrumentation/litellm/patch.py index 09c77477..a6cbb183 100644 --- a/src/langtrace_python_sdk/instrumentation/litellm/patch.py +++ b/src/langtrace_python_sdk/instrumentation/litellm/patch.py @@ -248,6 +248,8 @@ def traced_method( service_provider = SERVICE_PROVIDERS["AZURE"] elif "groq" in get_base_url(instance): service_provider = SERVICE_PROVIDERS["GROQ"] + elif "x.ai" in get_base_url(instance): + service_provider = SERVICE_PROVIDERS["XAI"] llm_prompts = [] for item in kwargs.get("messages", []): tools = get_tool_calls(item) @@ -336,6 +338,8 @@ async def traced_method( service_provider = SERVICE_PROVIDERS["PPLX"] elif "azure" in get_base_url(instance): service_provider = SERVICE_PROVIDERS["AZURE"] + elif "x.ai" in get_base_url(instance): + service_provider = SERVICE_PROVIDERS["XAI"] llm_prompts = [] for item in kwargs.get("messages", []): tools = get_tool_calls(item) diff --git a/src/langtrace_python_sdk/instrumentation/openai/patch.py b/src/langtrace_python_sdk/instrumentation/openai/patch.py index d2902aa5..3b0da8b3 100644 --- a/src/langtrace_python_sdk/instrumentation/openai/patch.py +++ b/src/langtrace_python_sdk/instrumentation/openai/patch.py @@ -249,6 +249,8 @@ def traced_method( service_provider = SERVICE_PROVIDERS["AZURE"] elif "groq" in get_base_url(instance): service_provider = SERVICE_PROVIDERS["GROQ"] + elif "x.ai" in get_base_url(instance): + service_provider = SERVICE_PROVIDERS["XAI"] llm_prompts = [] for item in kwargs.get("messages", []): tools = get_tool_calls(item) @@ -337,6 +339,8 @@ async def traced_method( service_provider = SERVICE_PROVIDERS["PPLX"] elif "azure" in get_base_url(instance): service_provider = SERVICE_PROVIDERS["AZURE"] + elif "x.ai" in get_base_url(instance): + service_provider = SERVICE_PROVIDERS["XAI"] llm_prompts = [] for item in kwargs.get("messages", []): tools = get_tool_calls(item) diff --git a/src/langtrace_python_sdk/version.py b/src/langtrace_python_sdk/version.py index 911557b8..f7493720 100644 --- a/src/langtrace_python_sdk/version.py +++ b/src/langtrace_python_sdk/version.py @@ -1 +1 @@ -__version__ = "3.1.2" +__version__ = "3.1.3" From 4e823c5613936a310229bdc595cddac86d2fd43d Mon Sep 17 00:00:00 2001 From: Karthik Kalyanaraman <105607645+karthikscale3@users.noreply.github.com> Date: Mon, 21 Oct 2024 19:53:41 -0700 Subject: [PATCH 3/5] Release (#389) * remove logs * remove requirements * Bump version * Squash * Support xAI (#387) * support xai * fix * minor --- src/langtrace_python_sdk/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/langtrace_python_sdk/version.py b/src/langtrace_python_sdk/version.py index f7493720..1fe90f6a 100644 --- a/src/langtrace_python_sdk/version.py +++ b/src/langtrace_python_sdk/version.py @@ -1 +1 @@ -__version__ = "3.1.3" +__version__ = "3.1.4" From 9f2f792e02ab8d1777952a2f29f6f9a46bfc9dd0 Mon Sep 17 00:00:00 2001 From: obinnascale3 <109410793+obinnascale3@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:47:14 +0100 Subject: [PATCH 4/5] Obinna/s3 en 1111 bedrock release (#393) * Support xAI (#387) * support xai * fix * Obinna/s3 en 2723 add bedrock instrumentation (#390) * add aws bedrock intregration * add bedrock examples and update version * run bedrock example --------- Co-authored-by: Obinna Okafor * add bedrock to supported integrations --------- Co-authored-by: Karthik Kalyanaraman <105607645+karthikscale3@users.noreply.github.com> Co-authored-by: Obinna Okafor --- README.md | 1 + pyproject.toml | 5 +- src/examples/awsbedrock_examples/__init__.py | 10 ++ src/examples/awsbedrock_examples/converse.py | 34 ++++ .../constants/instrumentation/aws_bedrock.py | 12 ++ .../constants/instrumentation/common.py | 1 + .../instrumentation/__init__.py | 2 + .../instrumentation/aws_bedrock/__init__.py | 3 + .../aws_bedrock/instrumentation.py | 58 +++++++ .../instrumentation/aws_bedrock/patch.py | 157 ++++++++++++++++++ src/langtrace_python_sdk/langtrace.py | 2 + src/langtrace_python_sdk/types/__init__.py | 7 + src/langtrace_python_sdk/version.py | 2 +- src/run_example.py | 9 +- 14 files changed, 299 insertions(+), 4 deletions(-) create mode 100644 src/examples/awsbedrock_examples/__init__.py create mode 100644 src/examples/awsbedrock_examples/converse.py create mode 100644 src/langtrace_python_sdk/constants/instrumentation/aws_bedrock.py create mode 100644 src/langtrace_python_sdk/instrumentation/aws_bedrock/__init__.py create mode 100644 src/langtrace_python_sdk/instrumentation/aws_bedrock/instrumentation.py create mode 100644 src/langtrace_python_sdk/instrumentation/aws_bedrock/patch.py diff --git a/README.md b/README.md index 711f1c27..dcec366e 100644 --- a/README.md +++ b/README.md @@ -263,6 +263,7 @@ Langtrace automatically captures traces from the following vendors: | Langchain | Framework | :x: | :white_check_mark: | | Langgraph | Framework | :x: | :white_check_mark: | | LlamaIndex | Framework | :white_check_mark: | :white_check_mark: | +| AWS Bedrock | Framework | :white_check_mark: | :white_check_mark: | | LiteLLM | Framework | :x: | :white_check_mark: | | DSPy | Framework | :x: | :white_check_mark: | | CrewAI | Framework | :x: | :white_check_mark: | diff --git a/pyproject.toml b/pyproject.toml index 78226e9c..5cd17fa6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ classifiers = [ "Operating System :: OS Independent", ] dependencies = [ - 'trace-attributes==7.0.4', + 'trace-attributes==7.1.0', 'opentelemetry-api>=1.25.0', 'opentelemetry-sdk>=1.25.0', 'opentelemetry-instrumentation>=0.47b0', @@ -57,7 +57,8 @@ dev = [ "google-generativeai", "google-cloud-aiplatform", "mistralai", - "embedchain" + "boto3", + "embedchain", ] test = ["pytest", "pytest-vcr", "pytest-asyncio"] diff --git a/src/examples/awsbedrock_examples/__init__.py b/src/examples/awsbedrock_examples/__init__.py new file mode 100644 index 00000000..da9a6508 --- /dev/null +++ b/src/examples/awsbedrock_examples/__init__.py @@ -0,0 +1,10 @@ +from examples.awsbedrock_examples.converse import use_converse +from langtrace_python_sdk import langtrace, with_langtrace_root_span + +langtrace.init() + + +class AWSBedrockRunner: + @with_langtrace_root_span("AWS_Bedrock") + def run(self): + use_converse() diff --git a/src/examples/awsbedrock_examples/converse.py b/src/examples/awsbedrock_examples/converse.py new file mode 100644 index 00000000..9619426b --- /dev/null +++ b/src/examples/awsbedrock_examples/converse.py @@ -0,0 +1,34 @@ +import os +import boto3 +from langtrace_python_sdk import langtrace + +langtrace.init(api_key=os.environ["LANGTRACE_API_KEY"]) + +def use_converse(): + model_id = "anthropic.claude-3-haiku-20240307-v1:0" + client = boto3.client( + "bedrock-runtime", + region_name="us-east-1", + aws_access_key_id=os.environ["AWS_ACCESS_KEY_ID"], + aws_secret_access_key=os.environ["AWS_SECRET_ACCESS_KEY"], + ) + conversation = [ + { + "role": "user", + "content": [{"text": "Write a story about a magic backpack."}], + } + ] + + try: + response = client.converse( + modelId=model_id, + messages=conversation, + inferenceConfig={"maxTokens":4096,"temperature":0}, + additionalModelRequestFields={"top_k":250} + ) + response_text = response["output"]["message"]["content"][0]["text"] + print(response_text) + + except (Exception) as e: + print(f"ERROR: Can't invoke '{model_id}'. Reason: {e}") + exit(1) \ No newline at end of file diff --git a/src/langtrace_python_sdk/constants/instrumentation/aws_bedrock.py b/src/langtrace_python_sdk/constants/instrumentation/aws_bedrock.py new file mode 100644 index 00000000..6a7cedef --- /dev/null +++ b/src/langtrace_python_sdk/constants/instrumentation/aws_bedrock.py @@ -0,0 +1,12 @@ +from langtrace.trace_attributes import AWSBedrockMethods + +APIS = { + "CONVERSE": { + "METHOD": AWSBedrockMethods.CONVERSE.value, + "ENDPOINT": "/converse", + }, + "CONVERSE_STREAM": { + "METHOD": AWSBedrockMethods.CONVERSE_STREAM.value, + "ENDPOINT": "/converse-stream", + }, +} diff --git a/src/langtrace_python_sdk/constants/instrumentation/common.py b/src/langtrace_python_sdk/constants/instrumentation/common.py index 53ff5d65..8cc02c9b 100644 --- a/src/langtrace_python_sdk/constants/instrumentation/common.py +++ b/src/langtrace_python_sdk/constants/instrumentation/common.py @@ -34,6 +34,7 @@ "EMBEDCHAIN": "Embedchain", "AUTOGEN": "Autogen", "XAI": "XAI", + "AWS_BEDROCK": "AWS Bedrock", } LANGTRACE_ADDITIONAL_SPAN_ATTRIBUTES_KEY = "langtrace_additional_attributes" diff --git a/src/langtrace_python_sdk/instrumentation/__init__.py b/src/langtrace_python_sdk/instrumentation/__init__.py index 369c5ac9..5e535004 100644 --- a/src/langtrace_python_sdk/instrumentation/__init__.py +++ b/src/langtrace_python_sdk/instrumentation/__init__.py @@ -18,6 +18,7 @@ from .vertexai import VertexAIInstrumentation from .gemini import GeminiInstrumentation from .mistral import MistralInstrumentation +from .aws_bedrock import AWSBedrockInstrumentation from .embedchain import EmbedchainInstrumentation from .litellm import LiteLLMInstrumentation @@ -44,4 +45,5 @@ "VertexAIInstrumentation", "GeminiInstrumentation", "MistralInstrumentation", + "AWSBedrockInstrumentation", ] diff --git a/src/langtrace_python_sdk/instrumentation/aws_bedrock/__init__.py b/src/langtrace_python_sdk/instrumentation/aws_bedrock/__init__.py new file mode 100644 index 00000000..7847fb4e --- /dev/null +++ b/src/langtrace_python_sdk/instrumentation/aws_bedrock/__init__.py @@ -0,0 +1,3 @@ +from .instrumentation import AWSBedrockInstrumentation + +__all__ = ["AWSBedrockInstrumentation"] diff --git a/src/langtrace_python_sdk/instrumentation/aws_bedrock/instrumentation.py b/src/langtrace_python_sdk/instrumentation/aws_bedrock/instrumentation.py new file mode 100644 index 00000000..601ed9ff --- /dev/null +++ b/src/langtrace_python_sdk/instrumentation/aws_bedrock/instrumentation.py @@ -0,0 +1,58 @@ +""" +Copyright (c) 2024 Scale3 Labs + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import importlib.metadata +import logging +from typing import Collection + +from opentelemetry.instrumentation.instrumentor import BaseInstrumentor +from opentelemetry.trace import get_tracer +from wrapt import wrap_function_wrapper as _W + +from langtrace_python_sdk.instrumentation.aws_bedrock.patch import ( + converse, converse_stream +) + +logging.basicConfig(level=logging.FATAL) + +def _patch_client(client, version: str, tracer) -> None: + + # Store original methods + original_converse = client.converse + + # Replace with wrapped versions + client.converse = converse("aws_bedrock.converse", version, tracer)(original_converse) + +class AWSBedrockInstrumentation(BaseInstrumentor): + + def instrumentation_dependencies(self) -> Collection[str]: + return ["boto3 >= 1.35.31"] + + def _instrument(self, **kwargs): + tracer_provider = kwargs.get("tracer_provider") + tracer = get_tracer(__name__, "", tracer_provider) + version = importlib.metadata.version("boto3") + + def wrap_create_client(wrapped, instance, args, kwargs): + result = wrapped(*args, **kwargs) + if args and args[0] == 'bedrock-runtime': + _patch_client(result, version, tracer) + return result + + _W("boto3", "client", wrap_create_client) + + def _uninstrument(self, **kwargs): + pass \ No newline at end of file diff --git a/src/langtrace_python_sdk/instrumentation/aws_bedrock/patch.py b/src/langtrace_python_sdk/instrumentation/aws_bedrock/patch.py new file mode 100644 index 00000000..3acf0e0e --- /dev/null +++ b/src/langtrace_python_sdk/instrumentation/aws_bedrock/patch.py @@ -0,0 +1,157 @@ +""" +Copyright (c) 2024 Scale3 Labs + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import json +from functools import wraps + +from langtrace.trace_attributes import ( + LLMSpanAttributes, + SpanAttributes, +) +from langtrace_python_sdk.utils import set_span_attribute +from langtrace_python_sdk.utils.silently_fail import silently_fail +from opentelemetry import trace +from opentelemetry.trace import SpanKind +from opentelemetry.trace.status import Status, StatusCode +from opentelemetry.trace.propagation import set_span_in_context +from langtrace_python_sdk.constants.instrumentation.common import ( + SERVICE_PROVIDERS, +) +from langtrace_python_sdk.constants.instrumentation.aws_bedrock import APIS +from langtrace_python_sdk.utils.llm import ( + get_extra_attributes, + get_langtrace_attributes, + get_llm_request_attributes, + get_llm_url, + get_span_name, + set_event_completion, + set_span_attributes, +) + + +def traced_aws_bedrock_call(api_name: str, operation_name: str): + def decorator(method_name: str, version: str, tracer): + def wrapper(original_method): + @wraps(original_method) + def wrapped_method(*args, **kwargs): + service_provider = SERVICE_PROVIDERS["AWS_BEDROCK"] + + input_content = [ + { + 'role': message.get('role', 'user'), + 'content': message.get('content', [])[0].get('text', "") + } + for message in kwargs.get('messages', []) + ] + + span_attributes = { + **get_langtrace_attributes(version, service_provider, vendor_type="framework"), + **get_llm_request_attributes(kwargs, operation_name=operation_name, prompts=input_content), + **get_llm_url(args[0] if args else None), + SpanAttributes.LLM_PATH: APIS[api_name]["ENDPOINT"], + **get_extra_attributes(), + } + + if api_name == "CONVERSE": + span_attributes.update({ + SpanAttributes.LLM_REQUEST_MODEL: kwargs.get('modelId'), + SpanAttributes.LLM_REQUEST_MAX_TOKENS: kwargs.get('inferenceConfig', {}).get('maxTokens'), + SpanAttributes.LLM_REQUEST_TEMPERATURE: kwargs.get('inferenceConfig', {}).get('temperature'), + SpanAttributes.LLM_REQUEST_TOP_P: kwargs.get('inferenceConfig', {}).get('top_p'), + }) + + attributes = LLMSpanAttributes(**span_attributes) + + with tracer.start_as_current_span( + name=get_span_name(APIS[api_name]["METHOD"]), + kind=SpanKind.CLIENT, + context=set_span_in_context(trace.get_current_span()), + ) as span: + set_span_attributes(span, attributes) + try: + result = original_method(*args, **kwargs) + _set_response_attributes(span, kwargs, result) + span.set_status(StatusCode.OK) + return result + except Exception as err: + span.record_exception(err) + span.set_status(Status(StatusCode.ERROR, str(err))) + raise err + + return wrapped_method + return wrapper + return decorator + + +converse = traced_aws_bedrock_call("CONVERSE", "converse") + + +def converse_stream(original_method, version, tracer): + def traced_method(wrapped, instance, args, kwargs): + service_provider = SERVICE_PROVIDERS["AWS_BEDROCK"] + + span_attributes = { + **get_langtrace_attributes + (version, service_provider, vendor_type="llm"), + **get_llm_request_attributes(kwargs), + **get_llm_url(instance), + SpanAttributes.LLM_PATH: APIS["CONVERSE_STREAM"]["ENDPOINT"], + **get_extra_attributes(), + } + + attributes = LLMSpanAttributes(**span_attributes) + + with tracer.start_as_current_span( + name=get_span_name(APIS["CONVERSE_STREAM"]["METHOD"]), + kind=SpanKind.CLIENT, + context=set_span_in_context(trace.get_current_span()), + ) as span: + set_span_attributes(span, attributes) + try: + result = wrapped(*args, **kwargs) + _set_response_attributes(span, kwargs, result) + span.set_status(StatusCode.OK) + return result + except Exception as err: + span.record_exception(err) + span.set_status(Status(StatusCode.ERROR, str(err))) + raise err + + return traced_method + + +@silently_fail +def _set_response_attributes(span, kwargs, result): + set_span_attribute(span, SpanAttributes.LLM_RESPONSE_MODEL, kwargs.get('modelId')) + set_span_attribute(span, SpanAttributes.LLM_TOP_K, kwargs.get('additionalModelRequestFields', {}).get('top_k')) + content = result.get('output', {}).get('message', {}).get('content', []) + if len(content) > 0: + role = result.get('output', {}).get('message', {}).get('role', "assistant") + responses = [ + {"role": role, "content": c.get('text', "")} + for c in content + ] + set_event_completion(span, responses) + + if 'usage' in result: + set_span_attributes( + span, + { + SpanAttributes.LLM_USAGE_COMPLETION_TOKENS: result['usage'].get('outputTokens'), + SpanAttributes.LLM_USAGE_PROMPT_TOKENS: result['usage'].get('inputTokens'), + SpanAttributes.LLM_USAGE_TOTAL_TOKENS: result['usage'].get('totalTokens'), + } + ) diff --git a/src/langtrace_python_sdk/langtrace.py b/src/langtrace_python_sdk/langtrace.py index b01aade2..9fd86a75 100644 --- a/src/langtrace_python_sdk/langtrace.py +++ b/src/langtrace_python_sdk/langtrace.py @@ -56,6 +56,7 @@ LiteLLMInstrumentation, LlamaindexInstrumentation, MistralInstrumentation, + AWSBedrockInstrumentation, OllamaInstrumentor, OpenAIInstrumentation, PineconeInstrumentation, @@ -278,6 +279,7 @@ def init( "google-cloud-aiplatform": VertexAIInstrumentation(), "google-generativeai": GeminiInstrumentation(), "mistralai": MistralInstrumentation(), + "boto3": AWSBedrockInstrumentation(), "autogen": AutogenInstrumentation(), } diff --git a/src/langtrace_python_sdk/types/__init__.py b/src/langtrace_python_sdk/types/__init__.py index 0ee5b250..0c6f7b87 100644 --- a/src/langtrace_python_sdk/types/__init__.py +++ b/src/langtrace_python_sdk/types/__init__.py @@ -30,6 +30,7 @@ class InstrumentationType(Enum): SQLALCHEMY = "sqlalchemy" VERTEXAI = "vertexai" WEAVIATE = "weaviate" + AWS_BEDROCK = "boto3" @staticmethod def from_string(value: str): @@ -62,6 +63,11 @@ class VendorMethods(TypedDict): "mistral.embeddings.create", ] + AwsBedrockMethods = Literal[ + "aws_bedrock.converse", + "aws_bedrock.converse_stream", + ] + ChromadbMethods = Literal[ "chromadb.collection.add", "chromadb.collection.query", @@ -112,6 +118,7 @@ class InstrumentationMethods(TypedDict): open_ai: List[VendorMethods.OpenaiMethods] groq: List[VendorMethods.GroqMethods] mistral: List[VendorMethods.MistralMethods] + aws_bedrock: List[VendorMethods.AwsBedrockMethods] pinecone: List[VendorMethods.PineconeMethods] llamaindex: List[VendorMethods.LlamaIndexMethods] chromadb: List[VendorMethods.ChromadbMethods] diff --git a/src/langtrace_python_sdk/version.py b/src/langtrace_python_sdk/version.py index 1fe90f6a..11731085 100644 --- a/src/langtrace_python_sdk/version.py +++ b/src/langtrace_python_sdk/version.py @@ -1 +1 @@ -__version__ = "3.1.4" +__version__ = "3.2.0" diff --git a/src/run_example.py b/src/run_example.py index 864bc8c2..58f1178c 100644 --- a/src/run_example.py +++ b/src/run_example.py @@ -16,10 +16,11 @@ "weaviate": False, "ollama": False, "groq": False, - "autogen": True, + "autogen": False, "vertexai": False, "gemini": False, "mistral": False, + "awsbedrock": True, } if ENABLED_EXAMPLES["anthropic"]: @@ -123,3 +124,9 @@ print(Fore.BLUE + "Running Azure OpenAI example" + Fore.RESET) AzureOpenAIRunner().run() + +if ENABLED_EXAMPLES["awsbedrock"]: + from examples.awsbedrock_examples import AWSBedrockRunner + + print(Fore.BLUE + "Running AWS Bedrock example" + Fore.RESET) + AWSBedrockRunner().run() From 5fc5345077520c50eb748b9ca137d0691980b235 Mon Sep 17 00:00:00 2001 From: Karthik Kalyanaraman Date: Thu, 31 Oct 2024 08:14:39 -0500 Subject: [PATCH 5/5] bump version --- src/langtrace_python_sdk/langtrace.py | 2 +- src/langtrace_python_sdk/version.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/langtrace_python_sdk/langtrace.py b/src/langtrace_python_sdk/langtrace.py index 9fd86a75..24d08fb1 100644 --- a/src/langtrace_python_sdk/langtrace.py +++ b/src/langtrace_python_sdk/langtrace.py @@ -151,7 +151,7 @@ def get_exporter(config: LangtraceConfig, host: str): headers = get_headers(config) host = f"{host}/api/trace" if host == LANGTRACE_REMOTE_URL else host if "http" in host.lower() or "https" in host.lower(): - return LangTraceExporter(host, config.api_key, config.disable_logging) + return HTTPExporter(endpoint=host, headers=headers) else: return GRPCExporter(endpoint=host, headers=headers) diff --git a/src/langtrace_python_sdk/version.py b/src/langtrace_python_sdk/version.py index 11731085..88c513ea 100644 --- a/src/langtrace_python_sdk/version.py +++ b/src/langtrace_python_sdk/version.py @@ -1 +1 @@ -__version__ = "3.2.0" +__version__ = "3.3.0"