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

Only warnings+ from azure.core.pipelines.policies.http_logging_policy #130

Merged
merged 3 commits into from
Oct 16, 2024
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: 6 additions & 5 deletions assistants/prospector-assistant/assistant/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from assistant_extensions.attachments import AttachmentsExtension
from content_safety.evaluators import CombinedContentSafetyEvaluator
from openai.types.chat import ChatCompletionMessageParam
from pydantic import BaseModel
from pydantic import BaseModel, ConfigDict
from semantic_workbench_api_model.workbench_model import (
AssistantStateEvent,
ConversationEvent,
Expand Down Expand Up @@ -348,16 +348,17 @@ async def respond_to_conversation(
if config.agents_config.artifact_agent.enabled:
# define the structured response format for the AI model
class StructuredResponseFormat(BaseModel):
class Config:
extra = "forbid"
schema_extra = {
model_config = ConfigDict(
extra="forbid",
json_schema_extra={
"description": (
"The response format for the assistant. Use the assistant_response field for the"
" response content and the artifacts_to_create_or_update field for any artifacts"
" to create or update."
),
"required": ["assistant_response", "artifacts_to_create_or_update"],
}
},
)

assistant_response: str
artifacts_to_create_or_update: list[Artifact]
Expand Down
4 changes: 3 additions & 1 deletion libraries/python/openai-client/openai_client/client.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
from openai import AsyncAzureOpenAI, AsyncOpenAI
from openai.lib.azure import AsyncAzureADTokenProvider

from .config import (
ServiceConfig,
AzureOpenAIApiKeyAuthConfig,
AzureOpenAIAzureIdentityAuthConfig,
AzureOpenAIServiceConfig,
OpenAIServiceConfig,
ServiceConfig,
)


Expand Down Expand Up @@ -51,6 +52,7 @@ def create_client(service_config: ServiceConfig, *, api_version: str = "2024-08-

def _get_azure_bearer_token_provider() -> AsyncAzureADTokenProvider:
global _lazy_initialized_azure_bearer_token_provider

if _lazy_initialized_azure_bearer_token_provider is None:
_lazy_initialized_azure_bearer_token_provider = get_bearer_token_provider(
DefaultAzureCredential(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging
import logging.config
import re

import asgi_correlation_id
from pydantic_settings import BaseSettings
from pythonjsonlogger import jsonlogger
from rich.logging import RichHandler


class LoggingSettings(BaseSettings):
Expand Down Expand Up @@ -55,7 +55,7 @@ def __init__(self, max_message_length: int):
class DebugLevelForNoisyLogFilter(logging.Filter):
"""Lowers log level to DEBUG for logs that match specific logger names and message patterns."""

def __init__(self, log_level: int, *names_and_patterns: tuple[str, re.Pattern]):
def __init__(self, log_level: int, names_and_patterns: list[tuple[str, re.Pattern]]):
self._log_level = log_level
self._names_and_patterns = names_and_patterns

Expand All @@ -74,22 +74,60 @@ def filter(self, record: logging.LogRecord) -> bool:
def config(settings: LoggingSettings):
log_level = logging.getLevelNamesMapping()[settings.log_level.upper()]

handler = RichHandler(rich_tracebacks=True)
handler = "rich"
if settings.json_format:
handler = JSONHandler(max_message_length=settings.json_format_maximum_message_length)

handler.addFilter(asgi_correlation_id.CorrelationIdFilter(uuid_length=8, default_value="-"))
handler.addFilter(
DebugLevelForNoisyLogFilter(
log_level,
# noisy assistant-service ping requests
("httpx", re.compile(r"PUT .+/assistant-service-registrations/[^\s]+ \"HTTP")),
)
)

logging.basicConfig(
level=log_level,
format="%(name)35s [%(correlation_id)s] %(message)s",
datefmt="[%X]",
handlers=[handler],
)
handler = "json"

logging.config.dictConfig({
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"default": {
"format": "%(name)35s [%(correlation_id)s] %(message)s",
"datefmt": "[%X]",
},
"json": {
"()": CustomJSONFormatter,
"format": "%(name)s %(filename)s %(module)s %(lineno)s %(levelname)s %(correlation_id)s %(message)s",
"timestamp": True,
"max_message_length": settings.json_format_maximum_message_length,
},
},
"handlers": {
"rich": {
"class": "rich.logging.RichHandler",
"rich_tracebacks": True,
"formatter": "default",
"filters": ["asgi_correlation_id", "debug_level_for_noisy_logs"],
},
"json": {
"class": "logging.StreamHandler",
"formatter": "json",
"filters": ["asgi_correlation_id", "debug_level_for_noisy_logs"],
},
},
"loggers": {
"azure.core.pipeline.policies.http_logging_policy": {
"level": "WARNING",
},
},
"root": {
"handlers": [handler],
"level": log_level,
},
"filters": {
"debug_level_for_noisy_logs": {
"()": DebugLevelForNoisyLogFilter,
"log_level": log_level,
"names_and_patterns": [
# noisy assistant-service ping requests
("httpx", re.compile(r"PUT .+/assistant-service-registrations/[^\s]+ \"HTTP")),
],
},
"asgi_correlation_id": {
"()": asgi_correlation_id.CorrelationIdFilter,
"uuid_length": 8,
"default_value": "-",
},
},
})
8 changes: 4 additions & 4 deletions workbench-service/alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ sqlalchemy.url =
hooks = ruff_check, ruff_format

ruff_check.type = exec
ruff_check.executable = ruff
ruff_check.options = check --fix REVISION_SCRIPT_FILENAME
ruff_check.executable = uvx
ruff_check.options = ruff check --fix REVISION_SCRIPT_FILENAME

ruff_format.type = exec
ruff_format.executable = ruff
ruff_format.options = format REVISION_SCRIPT_FILENAME
ruff_format.executable = uvx
ruff_format.options = ruff format REVISION_SCRIPT_FILENAME