Skip to content

Commit 786a879

Browse files
committed
.
1 parent 8800cb9 commit 786a879

File tree

4 files changed

+32
-30
lines changed

4 files changed

+32
-30
lines changed

backend/onyx/evals/eval_cli.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import argparse
77
import json
8-
import logging
98
import os
109
from typing import Any
1110

@@ -121,7 +120,6 @@ def run_remote(
121120

122121

123122
def main() -> None:
124-
logging.basicConfig(level=logging.INFO)
125123
"""Main CLI entry point."""
126124
parser = argparse.ArgumentParser(
127125
description="Run evaluations with local configurations"

backend/onyx/llm/chat_llm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from langchain_core.prompt_values import PromptValue
2727
from litellm.utils import get_supported_openai_params
2828

29+
from onyx.configs.app_configs import BRAINTRUST_ENABLED
2930
from onyx.configs.app_configs import LOG_DANSWER_MODEL_INTERACTIONS
3031
from onyx.configs.app_configs import MOCK_LLM_RESPONSE
3132
from onyx.configs.chat_configs import QA_TIMEOUT
@@ -49,9 +50,8 @@
4950
litellm.drop_params = True
5051
litellm.telemetry = False
5152

52-
# if BRAINTRUST_ENABLED:
53-
# print("Setting LiteLLM callbacks to braintrust")
54-
# litellm.callbacks = ["braintrust"]
53+
if BRAINTRUST_ENABLED:
54+
litellm.callbacks = ["braintrust"]
5555

5656
_LLM_PROMPT_LONG_TERM_LOG_CATEGORY = "llm_prompt"
5757
VERTEX_CREDENTIALS_FILE_KWARG = "vertex_credentials"

backend/onyx/llm/interfaces.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from braintrust import traced
66
from langchain.schema.language_model import LanguageModelInput
7+
from langchain_core.messages import AIMessageChunk
78
from langchain_core.messages import BaseMessage
89
from pydantic import BaseModel
910

@@ -33,32 +34,29 @@ class LLMConfig(BaseModel):
3334

3435

3536
def log_prompt(prompt: LanguageModelInput) -> None:
36-
# if isinstance(prompt, list):
37-
# for ind, msg in enumerate(prompt):
38-
# if isinstance(msg, AIMessageChunk):
39-
# if msg.content:
40-
# log_msg = msg.content
41-
# elif msg.tool_call_chunks:
42-
# # log_msg = "Tool Calls: " + str(
43-
# # [
44-
# # {
45-
# # key: value
46-
# # for key, value in tool_call.items()
47-
# # if key != "index"
48-
# # }
49-
# # for tool_call in msg.tool_call_chunks
50-
# # ]
51-
# # )
52-
# pass
53-
# else:
54-
# pass
55-
# # logger.debug(f"Message {ind}:\n{log_msg}")
56-
# else:
57-
# # logger.debug(f"Message {ind}:\n{msg.content}")
58-
# pass
37+
if isinstance(prompt, list):
38+
for ind, msg in enumerate(prompt):
39+
if isinstance(msg, AIMessageChunk):
40+
if msg.content:
41+
log_msg = msg.content
42+
elif msg.tool_call_chunks:
43+
log_msg = "Tool Calls: " + str(
44+
[
45+
{
46+
key: value
47+
for key, value in tool_call.items()
48+
if key != "index"
49+
}
50+
for tool_call in msg.tool_call_chunks
51+
]
52+
)
53+
else:
54+
pass
55+
logger.debug(f"Message {ind}:\n{log_msg}")
56+
else:
57+
logger.debug(f"Message {ind}:\n{msg.content}")
5958
if isinstance(prompt, str):
60-
# logger.debug(f"Prompt:\n{prompt}")
61-
pass
59+
logger.debug(f"Prompt:\n{prompt}")
6260

6361

6462
class LLM(abc.ABC):

backend/onyx/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from onyx.configs.app_configs import APP_PORT
3636
from onyx.configs.app_configs import AUTH_RATE_LIMITING_ENABLED
3737
from onyx.configs.app_configs import AUTH_TYPE
38+
from onyx.configs.app_configs import BRAINTRUST_ENABLED
3839
from onyx.configs.app_configs import DISABLE_GENERATIVE_AI
3940
from onyx.configs.app_configs import LOG_ENDPOINT_LATENCY
4041
from onyx.configs.app_configs import OAUTH_CLIENT_ID
@@ -51,6 +52,7 @@
5152
from onyx.db.engine.connection_warmup import warm_up_connections
5253
from onyx.db.engine.sql_engine import get_session_with_current_tenant
5354
from onyx.db.engine.sql_engine import SqlEngine
55+
from onyx.evals.tracing import setup_braintrust
5456
from onyx.file_store.file_store import get_default_file_store
5557
from onyx.server.api_key.api import router as api_key_router
5658
from onyx.server.auth_check import check_router_auth
@@ -252,6 +254,10 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
252254
if DISABLE_GENERATIVE_AI:
253255
logger.notice("Generative AI Q&A disabled")
254256

257+
if BRAINTRUST_ENABLED:
258+
setup_braintrust()
259+
logger.notice("Braintrust tracing initialized")
260+
255261
# fill up Postgres connection pools
256262
await warm_up_connections()
257263

0 commit comments

Comments
 (0)