Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup #121

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions langfuse/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from langfuse.api.resources.score.types.create_score_request import CreateScoreRequest
from langfuse.api.resources.trace.types.create_trace_request import CreateTraceRequest
from langfuse.environment import get_common_release_envs
from langfuse.logging import clean_logger
from langfuse.model import (
DatasetItem,
CreateDatasetRunItemRequest,
Expand Down Expand Up @@ -58,16 +59,10 @@ def __init__(
logging.basicConfig()
self.log.setLevel(logging.DEBUG)

httpx_logger = logging.getLogger("httpx")
httpx_logger.setLevel(logging.WARNING) # Set the desired log level
console_handler = logging.StreamHandler()
httpx_logger.addHandler(console_handler)
clean_logger()
else:
self.log.setLevel(logging.WARNING)
httpx_logger = logging.getLogger("httpx")
httpx_logger.setLevel(logging.WARNING) # Set the desired log level
console_handler = logging.StreamHandler()
httpx_logger.addHandler(console_handler)
clean_logger()

self.task_manager = TaskManager(debug=debug)

Expand Down
12 changes: 12 additions & 0 deletions langfuse/logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import logging


def clean_logger():
httpx_logger = logging.getLogger("httpx")
httpx_logger.setLevel(logging.WARNING) # Set the desired log level
console_handler = logging.StreamHandler()
httpx_logger.addHandler(console_handler)

backoff_logger = logging.getLogger("backoff")
backoff_logger.setLevel(logging.WARNING) # Set the desired log level
backoff_logger.addHandler(console_handler)
4 changes: 4 additions & 0 deletions langfuse/task_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import backoff

from langfuse.logging import clean_logger


class Task:
def __init__(self, task_id, function, predecessor_id: str = None):
Expand Down Expand Up @@ -40,8 +42,10 @@ def __init__(self, debug=False, max_task_queue_size=10_000, max_task_age=600):
# See https://docs.python.org/3/howto/logging.html#what-happens-if-no-configuration-is-provided
logging.basicConfig()
self.log.setLevel(logging.DEBUG)
clean_logger()
else:
self.log.setLevel(logging.WARNING)
clean_logger()

self.init_resources()

Expand Down
36 changes: 18 additions & 18 deletions tests/test_core_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

def test_flush():
# set up the consumer with more requests than a single batch will allow
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)

for i in range(2):
langfuse.trace(
Expand All @@ -36,7 +36,7 @@ def test_flush():


def test_shutdown():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)

for i in range(2):
langfuse.trace(
Expand All @@ -54,7 +54,7 @@ def test_shutdown():


def test_create_score():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)
api_wrapper = LangfuseAPI()

trace = langfuse.trace(
Expand Down Expand Up @@ -97,7 +97,7 @@ def test_create_score():


def test_create_trace():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)
api_wrapper = LangfuseAPI()
trace_name = create_uuid()

Expand All @@ -120,7 +120,7 @@ def test_create_trace():


def test_create_generation():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)
api_wrapper = LangfuseAPI()

timestamp = datetime.now()
Expand Down Expand Up @@ -181,7 +181,7 @@ def test_create_generation():


def test_create_span():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)
api_wrapper = LangfuseAPI()

timestamp = datetime.now()
Expand Down Expand Up @@ -225,7 +225,7 @@ def test_create_span():


def test_score_trace():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)
api_wrapper = LangfuseAPI()

trace_name = create_uuid()
Expand Down Expand Up @@ -262,7 +262,7 @@ def test_score_trace():


def test_score_span():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)
api_wrapper = LangfuseAPI()

spanId = create_uuid()
Expand Down Expand Up @@ -309,7 +309,7 @@ def test_score_span():


def test_create_trace_and_span():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)
api_wrapper = LangfuseAPI()

trace_name = create_uuid()
Expand All @@ -331,7 +331,7 @@ def test_create_trace_and_span():


def test_create_trace_and_generation():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)
api_wrapper = LangfuseAPI()

trace_name = create_uuid()
Expand All @@ -353,7 +353,7 @@ def test_create_trace_and_generation():


def test_create_generation_and_trace():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)
api_wrapper = LangfuseAPI()

trace_name = create_uuid()
Expand All @@ -375,7 +375,7 @@ def test_create_generation_and_trace():


def test_update_generation():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)
api = get_api()

generation = langfuse.generation(InitialGeneration(name="generation"))
Expand All @@ -395,7 +395,7 @@ def test_update_generation():


def test_update_span():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)
api = get_api()

span = langfuse.span(InitialSpan(name="span"))
Expand All @@ -415,7 +415,7 @@ def test_update_span():


def test_create_trace_and_event():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)
api_wrapper = LangfuseAPI()

trace_name = create_uuid()
Expand All @@ -439,7 +439,7 @@ def test_create_trace_and_event():
def test_create_span_and_generation():
api = get_api()

langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)

span = langfuse.span(InitialSpan(name="span"))
langfuse.generation(InitialGeneration(traceId=span.trace_id, name="generation"))
Expand All @@ -459,7 +459,7 @@ def test_create_span_and_generation():


def test_create_trace_with_id_and_generation():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)
api_wrapper = LangfuseAPI()

trace_name = create_uuid()
Expand Down Expand Up @@ -549,7 +549,7 @@ def test_end_span():


def test_get_generations():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)

timestamp = datetime.now()

Expand Down Expand Up @@ -582,7 +582,7 @@ def test_get_generations():


def test_get_generations_by_user():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)

timestamp = datetime.now()

Expand Down
10 changes: 5 additions & 5 deletions tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


def test_create_and_get_dataset():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)

name = create_uuid()
langfuse.create_dataset(CreateDatasetRequest(name=name))
Expand All @@ -25,7 +25,7 @@ def test_create_and_get_dataset():


def test_create_dataset_item():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)
name = create_uuid()
langfuse.create_dataset(CreateDatasetRequest(name=name))

Expand All @@ -38,7 +38,7 @@ def test_create_dataset_item():


def test_linking_observation():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)

dataset_name = create_uuid()
langfuse.create_dataset(CreateDatasetRequest(name=dataset_name))
Expand Down Expand Up @@ -66,7 +66,7 @@ def test_linking_observation():


def test_linking_via_id_observation():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)

dataset_name = create_uuid()
langfuse.create_dataset(CreateDatasetRequest(name=dataset_name))
Expand Down Expand Up @@ -96,7 +96,7 @@ def test_linking_via_id_observation():

@pytest.mark.skip(reason="inference cost")
def test_langchain_dataset():
langfuse = Langfuse(debug=True)
langfuse = Langfuse(debug=False)
dataset_name = create_uuid()
langfuse.create_dataset(CreateDatasetRequest(name=dataset_name))

Expand Down
Loading