Skip to content

Commit

Permalink
update configs
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbdias committed Sep 17, 2024
1 parent 2acca09 commit df46f84
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 84 deletions.
20 changes: 20 additions & 0 deletions examples/quick-start-llm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
help: Makefile ## show list of commands
@echo "Choose a command to run:"
@echo ""
@awk 'BEGIN {FS = ":.*?## "} /[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-40s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort

build-images: ## build images used by docker compose file
@docker compose build

start/with-docker: build-images ## build and run app using docker compose
@docker compose up

start/with-docker/only-observability: ## run observability stack using docker compose in debug mode
@docker compose up otel-collector jaeger

start/with-local: ## run app using docker compose
@docker compose up -d otel-collector jaeger
@OTEL_SERVICE_NAME=quick-start-llm OTEL_TRACES_EXPORTER=otlp OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://localhost:4317 opentelemetry-instrument streamlit run ./app/streamlit_app.py

stop: ## stop all running containers
@docker compose down
11 changes: 9 additions & 2 deletions examples/quick-start-llm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ python -m venv ./_venv
source _venv/bin/activate

# install requirements
pip install -r requirements.txt
pip install -r app/requirements.txt

# install OTel auto-instrumentation
opentelemetry-bootstrap -a install

# add openai api key
echo "OPENAI_API_KEY={your-open-ai-api-key}" >> .env
Expand All @@ -22,7 +25,11 @@ echo "OPENAI_API_KEY={your-open-ai-api-key}" >> .env
### Run example

```bash
streamlit run ./app/streamlit_app.py
OTEL_SERVICE_NAME=quick-start-llm \
OTEL_TRACES_EXPORTER=console,otlp \
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=localhost:4317 \
opentelemetry-instrument \
streamlit run ./app/streamlit_app.py
```

### References
Expand Down
1 change: 1 addition & 0 deletions examples/quick-start-llm/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ WORKDIR /opt/app
COPY . .

RUN pip install --no-cache-dir -r requirements.txt
RUN opentelemetry-bootstrap -a install`

CMD [ "streamlit", "run", "streamlit_app.py", "--server.port=8051", "--server.address=0.0.0.0" ]
Binary file modified examples/quick-start-llm/app/__pycache__/telemetry.cpython-312.pyc
Binary file not shown.
Binary file not shown.
57 changes: 0 additions & 57 deletions examples/quick-start-llm/app/llm/provider_huggingface_bart.py

This file was deleted.

2 changes: 0 additions & 2 deletions examples/quick-start-llm/app/llm/providers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from .provider_google_gemini import GoogleGeminiProvider
from .provider_huggingface_bart import HuggingFaceBartProvider
from .provider_openai_chatgpt import OpenAIChatGPTProvider

_providers = [
GoogleGeminiProvider(),
HuggingFaceBartProvider(),
OpenAIChatGPTProvider()
]

Expand Down
1 change: 0 additions & 1 deletion examples/quick-start-llm/app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
streamlit==1.38.0
langchain==0.2.16
langchain-openai==0.1.24
langchain-huggingface==0.0.3
langchain-google-genai==1.0.10
langchain-community==0.2.16
python-dotenv==1.0.1
Expand Down
20 changes: 13 additions & 7 deletions examples/quick-start-llm/app/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
# Load environment variables from .env file
load_dotenv()

# Initialize OpenLit
from telemetry import init as telemetry_init, heartbeat as telemetry_heartbeat, otlp_endpoint
# Initialize telemetry
from telemetry import init as telemetry_init, otlp_endpoint
tracer = telemetry_init() # run telemetry.init() before loading any other modules to capture any module-level telemetry
telemetry_heartbeat(tracer)

# from telemetry import heartbeat as telemetry_heartbeat
# telemetry_heartbeat(tracer)

import streamlit as st

Expand All @@ -16,8 +18,13 @@ def read_default_text():
with open("./example.txt") as f:
return f.read()

@tracer.start_as_current_span("perform_summarization")
def perform_summarization(provider_type, source_text):
provider = get_provider(provider_type)
return provider.summarize(source_text)

############################
# App start
# UI App start
############################

# Streamlit app
Expand All @@ -37,7 +44,7 @@ def read_default_text():
def callback():
st.session_state['source_text'] = read_default_text()

st.button("Add default text", on_click=callback)
st.button("Add example text", on_click=callback)
source_text = st.text_area("Source Text", label_visibility="collapsed", height=250, key="source_text")

# If the 'Summarize' button is clicked
Expand All @@ -48,8 +55,7 @@ def callback():
else:
try:
with st.spinner('Please wait...'):
provider = get_provider(provider_type)
summary = provider.summarize(source_text)
summary = perform_summarization(provider_type, source_text)
st.success(summary)
except Exception as e:
st.exception(f"An error occurred: {e}")
8 changes: 1 addition & 7 deletions examples/quick-start-llm/app/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,10 @@ def init():
Traceloop.init(
exporter=OTLPSpanExporter(endpoint=otlp_endpoint, insecure=True)
)
# openlit.init(
# environment='development',
# application_name=otlp_service_name,
# tracer=tracer,
# disable_metrics=True,
# collect_gpu_stats=False
# )

return tracer

# Test method to guarantee that the telemetry is working
def heartbeat(tracer):
with tracer.start_as_current_span("heartbeat"):
current_span = trace.get_current_span()
Expand Down
2 changes: 0 additions & 2 deletions examples/quick-start-llm/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ services:
environment:
- OTEL_SERVICE_NAME=quick-start-llm
- OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317
- HUGGINGFACE_HUB_API_TOKEN=${HUGGINGFACE_HUB_API_TOKEN}
- GOOGLE_API_KEY=${GOOGLE_API_KEY}
- OPENAI_API_KEY=${OPENAI_API_KEY}
ports:
Expand All @@ -24,7 +23,6 @@ services:
image: otel/opentelemetry-collector:0.108.0
ports:
- 4317:4317
- 4318:4318
volumes:
- type: bind
source: ./observability/otelcollector.config.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ receivers:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318

processors:
batch:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
streamlit==1.38.0
langchain==0.2.16
langchain-openai==0.1.24
langchain-huggingface==0.0.3
langchain-google-genai==1.0.10
langchain-community==0.2.16
python-dotenv==1.0.1
openlit==1.22.2
watchdog==5.0.2
opentelemetry-distro==0.45b0
opentelemetry-distro==0.48b0
opentelemetry-exporter-otlp==1.27.0
opentelemetry-exporter-otlp-proto-grpc==1.27.0
traceloop-sdk==0.30.0
watchdog==5.0.2

0 comments on commit df46f84

Please sign in to comment.