-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1110 from arc53/logging
feat: logging
- Loading branch information
Showing
12 changed files
with
91 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
from celery import Celery | ||
from application.core.settings import settings | ||
from celery.signals import setup_logging | ||
|
||
def make_celery(app_name=__name__): | ||
celery = Celery(app_name, broker=settings.CELERY_BROKER_URL, backend=settings.CELERY_RESULT_BACKEND) | ||
celery.conf.update(settings) | ||
return celery | ||
|
||
@setup_logging.connect | ||
def config_loggers(*args, **kwargs): | ||
from application.core.logging_config import setup_logging | ||
setup_logging() | ||
|
||
celery = make_celery() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from logging.config import dictConfig | ||
|
||
def setup_logging(): | ||
dictConfig({ | ||
'version': 1, | ||
'formatters': { | ||
'default': { | ||
'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s', | ||
} | ||
}, | ||
"handlers": { | ||
"console": { | ||
"class": "logging.StreamHandler", | ||
"stream": "ext://sys.stdout", | ||
"formatter": "default", | ||
} | ||
}, | ||
'root': { | ||
'level': 'INFO', | ||
'handlers': ['console'], | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,22 @@ | ||
from transformers import GPT2TokenizerFast | ||
import tiktoken | ||
|
||
tokenizer = GPT2TokenizerFast.from_pretrained('gpt2') | ||
tokenizer.model_max_length = 100000 | ||
def count_tokens(string): | ||
return len(tokenizer(string)['input_ids']) | ||
_encoding = None | ||
|
||
def get_encoding(): | ||
global _encoding | ||
if _encoding is None: | ||
_encoding = tiktoken.get_encoding("cl100k_base") | ||
return _encoding | ||
|
||
def num_tokens_from_string(string: str) -> int: | ||
encoding = get_encoding() | ||
num_tokens = len(encoding.encode(string)) | ||
return num_tokens | ||
|
||
def count_tokens_docs(docs): | ||
docs_content = "" | ||
for doc in docs: | ||
docs_content += doc.page_content | ||
|
||
tokens = num_tokens_from_string(docs_content) | ||
return tokens |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters