Skip to content

Commit

Permalink
feat: add README and release please for anthropic instrumentor (#925)
Browse files Browse the repository at this point in the history
  • Loading branch information
21ShisodeParth authored Aug 20, 2024
1 parent bb742d6 commit e8b8973
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,23 @@ OpenInference provides a set of instrumentations for popular machine learning SD
| [`openinference-instrumentation-litellm`](./python/instrumentation/openinference-instrumentation-litellm) | OpenInference Instrumentation for liteLLM. | [![PyPI Version](https://img.shields.io/pypi/v/openinference-instrumentation-litellm.svg)](https://pypi.python.org/pypi/openinference-instrumentation-litellm) |
| [`openinference-instrumentation-groq`](./python/instrumentation/openinference-instrumentation-groq) | OpenInference Instrumentation for Groq. | [![PyPI Version](https://img.shields.io/pypi/v/openinference-instrumentation-groq.svg)](https://pypi.python.org/pypi/openinference-instrumentation-groq) |
| [`openinference-instrumentation-instructor`](./python/instrumentation/openinference-instrumentation-instructor) | OpenInference Instrumentation for Instructor. | [![PyPI Version](https://img.shields.io/pypi/v/openinference-instrumentation-instructor.svg)](https://pypi.python.org/pypi/openinference-instrumentation-instructor) |
| [`openinference-instrumentation-anthropic`](./python/instrumentation/openinference-instrumentation-instructor) | OpenInference Instrumentation for Anthropic. | [![PyPI Version](https://img.shields.io/pypi/v/openinference-instrumentation-anthropic.svg)](https://pypi.python.org/pypi/openinference-instrumentation-anthropic) |


### Examples

| Name | Description | Complexity Level |
|------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------|------------------|
| [OpenAI SDK](python/instrumentation/openinference-instrumentation-openai/examples/) | OpenAI Python SDK, including chat completions and embeddings | Beginner |
| [MistralAI SDK](python/instrumentation/openinference-instrumentation-mistralai/examples/) | MistraAI Python SDK | Beginner |
| [MistralAI SDK](python/instrumentation/openinference-instrumentation-mistralai/examples/) | MistralAI Python SDK | Beginner |
| [VertexAI SDK](python/instrumentation/openinference-instrumentation-vertexai/examples/) | VertexAI Python SDK | Beginner |
| [LlamaIndex](python/instrumentation/openinference-instrumentation-llama-index/examples/) | LlamaIndex query engines | Beginner |
| [DSPy](python/instrumentation/openinference-instrumentation-dspy/examples/) | DSPy primitives and custom RAG modules | Beginner |
| [Boto3 Bedrock Client](python/instrumentation/openinference-instrumentation-bedrock/examples/) | Boto3 Bedrock client | Beginner |
| [LangChain](python/instrumentation/openinference-instrumentation-langchain/examples/) | LangChain primitives and simple chains | Beginner |
| [LiteLLM](python/instrumentation/openinference-instrumentation-litellm/) | A lightweight LiteLLM framework | Beginner |
| [Groq](python/instrumentation/openinference-instrumentation-groq/examples/) | Groq and AsyncGroq chat completions | Beginner |
| [Anthropic](python/instrumentation/openinference-instrumentation-anthropic/examples/) | Anthropic Messages client | Beginner |
| [LlamaIndex + Next.js Chatbot](python/examples/llama-index/) | A fully functional chatbot using Next.js and a LlamaIndex FastAPI backend | Intermediate |
| [LangServe](python/examples/langserve/) | A LangChain application deployed with LangServe using custom metadata on a per-request basis | Intermediate |
| [DSPy](python/examples/dspy-rag-fastapi/) | A DSPy RAG application using FastAPI, Weaviate, and Cohere | Intermediate |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
# OpenInference Groq Instrumentation
# OpenInference Anthropic Instrumentation

Python autoinstrumentation library for the [Groq](https://wow.groq.com/why-groq/) package
Python autoinstrumentation library for the [Anthropic](https://www.anthropic.com/api) package

This package implements OpenInference tracing for both the Groq and AsyncGroq clients.
This package implements the following Anthropic clients:
- `Messages`
- `Completions`
- `AsyncMessages`
- `AsyncCompletions`

These traces are fully OpenTelemetry compatible and can be sent to an OpenTelemetry collector for viewing, such as [Arize `phoenix`](https://github.com/Arize-ai/phoenix).


## Installation

```shell
pip install openinference-instrumentation-groq
pip install openinference-instrumentation-anthropic
```

## Quickstart

Through your *terminal*, install required packages.

```shell
pip install openinference-instrumentation-groq groq arize-phoenix opentelemetry-sdk opentelemetry-exporter-otlp
pip install openinference-instrumentation-anthropic anthropic arize-phoenix opentelemetry-sdk opentelemetry-exporter-otlp
```

You can start Phoenix with the following terminal command:
Expand All @@ -30,41 +34,40 @@ By default, Phoenix listens on `http://localhost:6006`. You can visit the app vi

Try the following code in a *Python file*.

1. Set up `GroqInstrumentor` to trace your application and sends the traces to Phoenix.
2. Then, set your Groq API key as an environment variable.
3. Lastly, create a Groq client, make a request, then go see your results in Phoenix at `http://localhost:6006`!
1. Set up `AnthropicInstrumentor` to trace your application and sends the traces to Phoenix.
2. Then, set your Anthropic API key as an environment variable.
3. Lastly, create a Anthropic client, make a request, then go see your results in Phoenix at `http://localhost:6006`!

```python
import os
from groq import Groq
from openinference.instrumentation.groq import GroqInstrumentor
from anthropic import Anthropic
from openinference.instrumentation.anthropic import AnthropicInstrumentor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk import trace as trace_sdk
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
# Configure GroqInstrumentor with Phoenix endpoint
# Configure AnthropicInstrumentor with Phoenix endpoint
endpoint = "http://127.0.0.1:6006/v1/traces"
tracer_provider = trace_sdk.TracerProvider()
tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))
GroqInstrumentor().instrument(tracer_provider=tracer_provider)
AnthropicInstrumentor().instrument(tracer_provider=tracer_provider)
os.environ["GROQ_API_KEY"] = "YOUR_KEY_HERE"
os.environ["ANTHROPIC_API_KEY"] = "YOUR_KEY_HERE"
client = Groq()
client = Anthropic()
chat_completion = client.chat.completions.create(
response = client.messages.create(
max_tokens=1024,
messages=[
{
"role": "user",
"content": "Explain the importance of low latency LLMs",
"content": "Tell me about the history of Iceland!",
}
],
model="llama3-8b-8192",
model="claude-3-opus-20240229",
)
if __name__ == "__main__":
print(chat_completion.choices[0].message.content)
print(response)
```

Now, on the Phoenix UI on your browser, you should see the traces from your Groq application. Click on a trace, then the "Attributes" tab will provide you with in-depth information regarding execution!
Now, on the Phoenix UI on your browser, you should see the traces from your Anthropic application. Click on a trace, then the "Attributes" tab will provide you with in-depth information regarding execution!
4 changes: 4 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
"python/instrumentation/openinference-instrumentation-instructor": {
"package-name": "python-openinference-instrumentation-instructor",
"release-type": "python"
},
"python/instrumentation/openinference-instrumentation-anthropic": {
"package-name": "python-openinference-instrumentation-anthropic",
"release-type": "python"
}
}
}

0 comments on commit e8b8973

Please sign in to comment.