Kai Jennissen
commited on
tracing
Browse files- .pre-commit-config.yaml +54 -0
- app.py +58 -6
- requirements.in +2 -1
- requirements.txt +4 -2
.pre-commit-config.yaml
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This is a .pre-commit-config.yaml file. The pre-commit tool uses this configuration
|
2 |
+
# to manage and enforce coding standards and checks before code commits.
|
3 |
+
# It helps automate checks for common issues, ensuring that changes committed to the repository
|
4 |
+
# comply with predefined standards and are free of certain types of errors.
|
5 |
+
|
6 |
+
repos:
|
7 |
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
8 |
+
rev: v5.0.0 # The version of the general pre-commit hooks we are using.
|
9 |
+
hooks:
|
10 |
+
- id: check-ast
|
11 |
+
# Checks if Python Abstract Syntax Trees (ASTs) are well-formed, catching syntax errors.
|
12 |
+
|
13 |
+
- id: check-yaml
|
14 |
+
# Verifies the syntax of YAML files, ensuring they are correctly structured.
|
15 |
+
|
16 |
+
- id: end-of-file-fixer
|
17 |
+
# Ensures that all files end with a newline, which is a common POSIX standard.
|
18 |
+
|
19 |
+
- id: trailing-whitespace
|
20 |
+
# Removes any trailing whitespace at the end of lines in text files.
|
21 |
+
|
22 |
+
- id: check-executables-have-shebangs
|
23 |
+
# Ensures that executable files have a shebang line, which indicates how the script should be executed.
|
24 |
+
|
25 |
+
- id: debug-statements
|
26 |
+
# Checks for the presence of debug statements (like Python's breakpoint) that shouldn't be in committed code.
|
27 |
+
|
28 |
+
- id: check-added-large-files
|
29 |
+
args: ["--maxkb=5000"]
|
30 |
+
# Prevents accidentally committing large files to the repository by setting a size limit of 5000KB.
|
31 |
+
|
32 |
+
- id: mixed-line-ending
|
33 |
+
# Ensures consistent line ending style across files, avoiding mixtures that can lead to problems on different platforms.
|
34 |
+
# Checks if Jupyter notebooks are clean and free of output cells.
|
35 |
+
- repo: https://github.com/srstevenson/nb-clean
|
36 |
+
rev: 4.0.1
|
37 |
+
hooks:
|
38 |
+
- id: nb-clean
|
39 |
+
args:
|
40 |
+
- --remove-empty-cells
|
41 |
+
- --preserve-cell-outputs
|
42 |
+
# - repo: https://github.com/PyCQA/isort
|
43 |
+
# rev: 6.0.1 # The version of isort we are using to sort imports in Python files.
|
44 |
+
# hooks:
|
45 |
+
# - id: isort
|
46 |
+
# args: ["--profile", "black", "--filter-files"]
|
47 |
+
# # Configures isort to use the Black formatting profile and only filter files that were selected by pre-commit.
|
48 |
+
# language_version: python3 # Specifies that this should run with Python 3.
|
49 |
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
50 |
+
rev: "v0.9.10" # Specific version of ruff, a fast Python linter.
|
51 |
+
hooks:
|
52 |
+
- id: ruff
|
53 |
+
# Runs ruff to perform linting on the code, checking for stylistic and logical errors not covered by other tools.
|
54 |
+
- id: ruff-format
|
app.py
CHANGED
@@ -1,26 +1,78 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
-
import inspect
|
5 |
import pandas as pd
|
6 |
-
from smolagents import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
# (Keep Constants as is)
|
9 |
# --- Constants ---
|
10 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
11 |
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
# --- Basic Agent Definition ---
|
14 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
15 |
def get_agent():
|
16 |
llm = HfApiModel(
|
17 |
model_id="Qwen/Qwen2.5-Coder-32B-Instruct", token=os.getenv("HF_TOKEN")
|
18 |
)
|
19 |
-
|
20 |
-
tools=[DuckDuckGoSearchTool()],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
model=llm,
|
|
|
22 |
)
|
23 |
-
return
|
24 |
|
25 |
|
26 |
class BasicAgent:
|
@@ -97,7 +149,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
97 |
results_log = []
|
98 |
answers_payload = []
|
99 |
print(f"Running agent on {len(questions_data)} questions...")
|
100 |
-
for item in questions_data:
|
101 |
task_id = item.get("task_id")
|
102 |
question_text = item.get("question")
|
103 |
if not task_id or question_text is None:
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
import requests
|
|
|
4 |
import pandas as pd
|
5 |
+
from smolagents import (
|
6 |
+
ToolCallingAgent,
|
7 |
+
CodeAgent,
|
8 |
+
DuckDuckGoSearchTool,
|
9 |
+
HfApiModel,
|
10 |
+
VisitWebpageTool,
|
11 |
+
)
|
12 |
+
from dotenv import load_dotenv
|
13 |
+
import base64
|
14 |
+
from opentelemetry.sdk.trace import TracerProvider
|
15 |
+
from openinference.instrumentation.smolagents import SmolagentsInstrumentor
|
16 |
+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
|
17 |
+
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
|
18 |
+
from opentelemetry import trace
|
19 |
+
|
20 |
+
load_dotenv()
|
21 |
|
22 |
# (Keep Constants as is)
|
23 |
# --- Constants ---
|
24 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
25 |
|
26 |
|
27 |
+
# Get your own keys from https://cloud.langfuse.com
|
28 |
+
|
29 |
+
|
30 |
+
os.environ["LANGFUSE_HOST"] = "https://cloud.langfuse.com" # 🇪🇺 EU region example
|
31 |
+
# os.environ["LANGFUSE_HOST"] = "https://us.cloud.langfuse.com" # 🇺🇸 US region example
|
32 |
+
|
33 |
+
LANGFUSE_AUTH = base64.b64encode(
|
34 |
+
f"{os.environ.get('LANGFUSE_PUBLIC_KEY')}:{os.environ.get('LANGFUSE_SECRET_KEY')}".encode()
|
35 |
+
).decode()
|
36 |
+
|
37 |
+
os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = (
|
38 |
+
os.environ.get("LANGFUSE_HOST") + "/api/public/otel"
|
39 |
+
)
|
40 |
+
os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = f"Authorization=Basic {LANGFUSE_AUTH}"
|
41 |
+
|
42 |
+
# Create a TracerProvider for OpenTelemetry
|
43 |
+
trace_provider = TracerProvider()
|
44 |
+
|
45 |
+
# Add a SimpleSpanProcessor with the OTLPSpanExporter to send traces
|
46 |
+
trace_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter()))
|
47 |
+
|
48 |
+
# Set the global default tracer provider
|
49 |
+
|
50 |
+
trace.set_tracer_provider(trace_provider)
|
51 |
+
tracer = trace.get_tracer(__name__)
|
52 |
+
|
53 |
+
# Instrument smolagents with the configured provider
|
54 |
+
SmolagentsInstrumentor().instrument(tracer_provider=trace_provider)
|
55 |
+
|
56 |
+
|
57 |
# --- Basic Agent Definition ---
|
58 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
59 |
def get_agent():
|
60 |
llm = HfApiModel(
|
61 |
model_id="Qwen/Qwen2.5-Coder-32B-Instruct", token=os.getenv("HF_TOKEN")
|
62 |
)
|
63 |
+
web_agent = ToolCallingAgent(
|
64 |
+
tools=[DuckDuckGoSearchTool(), VisitWebpageTool()],
|
65 |
+
model=llm,
|
66 |
+
max_steps=10,
|
67 |
+
description="A web agent that can search the web and visit webpages.",
|
68 |
+
)
|
69 |
+
|
70 |
+
manager_agent = CodeAgent(
|
71 |
+
tools=[web_agent],
|
72 |
model=llm,
|
73 |
+
max_steps=10,
|
74 |
)
|
75 |
+
return manager_agent
|
76 |
|
77 |
|
78 |
class BasicAgent:
|
|
|
149 |
results_log = []
|
150 |
answers_payload = []
|
151 |
print(f"Running agent on {len(questions_data)} questions...")
|
152 |
+
for item in questions_data[:1]:
|
153 |
task_id = item.get("task_id")
|
154 |
question_text = item.get("question")
|
155 |
if not task_id or question_text is None:
|
requirements.in
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
gradio[oauth]
|
2 |
requests
|
3 |
-
smolagents[gradio,litellm,openai,telemetry,toolkit,torch,transformers,vision]
|
|
|
|
1 |
gradio[oauth]
|
2 |
requests
|
3 |
+
smolagents[gradio,litellm,openai,telemetry,toolkit,torch,transformers,vision]
|
4 |
+
duckduckgo_search>=7.0.0,<8.0.0
|
requirements.txt
CHANGED
@@ -79,8 +79,10 @@ distro==1.9.0
|
|
79 |
# via openai
|
80 |
dnspython==2.7.0
|
81 |
# via email-validator
|
82 |
-
duckduckgo-search==
|
83 |
-
# via
|
|
|
|
|
84 |
email-validator==2.2.0
|
85 |
# via arize-phoenix
|
86 |
fastapi==0.115.12
|
|
|
79 |
# via openai
|
80 |
dnspython==2.7.0
|
81 |
# via email-validator
|
82 |
+
duckduckgo-search==7.5.5
|
83 |
+
# via
|
84 |
+
# -r requirements.in
|
85 |
+
# smolagents
|
86 |
email-validator==2.2.0
|
87 |
# via arize-phoenix
|
88 |
fastapi==0.115.12
|