uezo / aiproxy

🦉AIProxy is a reverse proxy for ChatGPT API that provides monitoring, logging, and filtering requests and responses.
Apache License 2.0
38 stars 1 forks source link

Update feature to customize log format (ChatGPT) #18 #19

Closed uezo closed 7 months ago

uezo commented 7 months ago

Make custom access log class for worker and item class(es) for each proxy.

class CustomAccessLog(AccessLogBase):
    user = Column(String)

class CustomGPTRequestItem(ChatGPTRequestItem):
    def to_accesslog(self, accesslog_cls: _AccessLogBase) -> _AccessLogBase:
        accesslog = super().to_accesslog(accesslog_cls)

        # In this case, set value of "x-user-id" in request header to newly added colmun "user"
        accesslog.user = self.request_headers.get("x-user-id")

        return accesslog

# Use your custom accesslog
worker = CustomAccessLogWorker(accesslog_cls=CustomAccessLog)

# Use your custom request item
proxy = ChatGPTProxy(access_logger_queue=worker.queue_client, request_item_class=CustomGPTRequestItem)