mirror of
https://github.com/kennethreitz/simplemind.git
synced 2026-06-05 22:50:18 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c648a922b4 | |||
| 873f5ba5f8 | |||
| 28a7b2f140 | |||
| 173162e798 |
@@ -1,6 +1,12 @@
|
|||||||
Release History
|
Release History
|
||||||
===============
|
===============
|
||||||
|
|
||||||
|
## 0.1.7 (2024-11-01)
|
||||||
|
|
||||||
|
- Add `logger` decorator.
|
||||||
|
- Add `sm.enable_logfire()` function.
|
||||||
|
- General improvements.
|
||||||
|
|
||||||
## 0.1.6 (2024-10-31)
|
## 0.1.6 (2024-10-31)
|
||||||
|
|
||||||
- Add `sm.Plugin` syntax sugar.
|
- Add `sm.Plugin` syntax sugar.
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ import simplemind
|
|||||||
project = "simplemind"
|
project = "simplemind"
|
||||||
copyright = "2024 Kenneth Reitz"
|
copyright = "2024 Kenneth Reitz"
|
||||||
author = "Kenneth Reitz"
|
author = "Kenneth Reitz"
|
||||||
release = "v0.1.6"
|
release = "v0.1.7"
|
||||||
|
|
||||||
# -- General configuration ---------------------------------------------------
|
# -- General configuration ---------------------------------------------------
|
||||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "simplemind"
|
name = "simplemind"
|
||||||
version = "0.1.6"
|
version = "0.1.7"
|
||||||
description = "An experimental client for AI providers that intends to replace LangChain and LangGraph for most common use cases."
|
description = "An experimental client for AI providers that intends to replace LangChain and LangGraph for most common use cases."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
|
|||||||
@@ -113,6 +113,11 @@ def generate_text(
|
|||||||
return provider.generate_text(prompt=prompt, llm_model=llm_model, **kwargs)
|
return provider.generate_text(prompt=prompt, llm_model=llm_model, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def enable_logfire() -> None:
|
||||||
|
"""Enable logfire logging."""
|
||||||
|
settings.logging.enable_logfire()
|
||||||
|
|
||||||
|
|
||||||
# Syntax sugar.
|
# Syntax sugar.
|
||||||
Plugin = BasePlugin
|
Plugin = BasePlugin
|
||||||
|
|
||||||
@@ -125,4 +130,5 @@ __all__ = [
|
|||||||
"BasePlugin",
|
"BasePlugin",
|
||||||
"Session",
|
"Session",
|
||||||
"Plugin",
|
"Plugin",
|
||||||
|
"enable_logfire",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -7,18 +7,24 @@ from .settings import settings
|
|||||||
|
|
||||||
|
|
||||||
def logger(func: Callable[..., Any]) -> Callable[..., Any]:
|
def logger(func: Callable[..., Any]) -> Callable[..., Any]:
|
||||||
"""A @logger decorator that logs the function parameters, function returns, and exceptions raised if logging is enabled."""
|
"""A decorator that logs the function parameters, function returns,
|
||||||
|
and exceptions raised if logging is enabled, using logfire.
|
||||||
|
"""
|
||||||
|
|
||||||
def wrapper(*args, **kwargs) -> Any:
|
def wrapper(*args, **kwargs) -> Any:
|
||||||
if not settings.logging.enabled:
|
if not settings.logging.is_enabled:
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
|
|
||||||
logfire.info(f"Calling {func.__name__} with args: {args}, kwargs: {kwargs}")
|
logfire.info(f"Calling {func.__name__} with args: {args}, kwargs: {kwargs}")
|
||||||
t1 = time.perf_counter()
|
t1 = time.perf_counter()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = func(*args, **kwargs)
|
result = func(*args, **kwargs)
|
||||||
t2 = time.perf_counter()
|
t2 = time.perf_counter()
|
||||||
logfire.info(f"{func.__name__} returned: {result} in {t2-t1} seconds")
|
logfire.info(f"{func.__name__} returned: {result} in {t2-t1} seconds")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
t2 = time.perf_counter()
|
t2 = time.perf_counter()
|
||||||
logfire.error(f"Error in {func.__name__}: {e} in {t2-t1} seconds")
|
logfire.error(f"Error in {func.__name__}: {e} in {t2-t1} seconds")
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from pydantic_settings import BaseSettings, SettingsConfigDict
|
|||||||
class LoggingConfig(BaseSettings):
|
class LoggingConfig(BaseSettings):
|
||||||
"""The class that holds all the logging settings for the application."""
|
"""The class that holds all the logging settings for the application."""
|
||||||
|
|
||||||
enabled: bool = Field(False, description="Enable logging")
|
is_enabled: bool = Field(False, description="Enable logging")
|
||||||
|
|
||||||
model_config = SettingsConfigDict(extra="forbid")
|
model_config = SettingsConfigDict(extra="forbid")
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ class LoggingConfig(BaseSettings):
|
|||||||
"To enable logging, please install logfire: `pip install logfire`"
|
"To enable logging, please install logfire: `pip install logfire`"
|
||||||
) from e
|
) from e
|
||||||
|
|
||||||
self.enabled = True
|
self.is_enabled = True
|
||||||
logfire.configure(**kwargs)
|
logfire.configure(**kwargs)
|
||||||
basicConfig(handlers=[logfire.LogfireLoggingHandler()])
|
basicConfig(handlers=[logfire.LogfireLoggingHandler()])
|
||||||
|
|
||||||
@@ -30,12 +30,12 @@ class LoggingConfig(BaseSettings):
|
|||||||
logfire.configure(**kwargs)
|
logfire.configure(**kwargs)
|
||||||
basicConfig(handlers=[logfire.LogfireLoggingHandler()])
|
basicConfig(handlers=[logfire.LogfireLoggingHandler()])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.enabled = False # Reset flag on failure
|
self.is_enabled = False # Reset flag on failure
|
||||||
raise RuntimeError("Failed to configure logging") from e
|
raise RuntimeError("Failed to configure logging") from e
|
||||||
|
|
||||||
def disable_logfire(self) -> None:
|
def disable_logfire(self) -> None:
|
||||||
"""Disable logging for the application."""
|
"""Disable logging for the application."""
|
||||||
self.enabled = False
|
self.is_enabled = False
|
||||||
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
|
|||||||
Reference in New Issue
Block a user