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

Improve mlchain_context #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
22 changes: 11 additions & 11 deletions mlchain/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
from os import environ

# Mlchain Context
from contextvars import ContextVar
from typing import Any, Dict

_request_scope_context_storage: ContextVar[Dict[Any, Any]] = ContextVar(
"mlchain_context"
)
from .context import mlchain_context

# Gevent fix
if "DISABLE_GEVENT_FIX" not in environ:
# Fix gevent
try:
Expand All @@ -18,28 +28,18 @@
# Handle target environment that doesn't support HTTPS verification
ssl._create_default_https_context = _create_unverified_https_context

# Mlchain Context
from contextvars import ContextVar
from typing import Any, Dict

_request_scope_context_storage: ContextVar[Dict[Any, Any]] = ContextVar(
"mlchain_context"
)

# Parameters of MLchain
__version__ = "0.3.1"
__version__ = "0.3.2"

HOST = "https://www.api.mlchain.ml"
WEB_HOST = HOST
API_ADDRESS = HOST
MODEL_ID = None

from os import environ

environ['OBJC_DISABLE_INITIALIZE_FORK_SAFETY'] = 'YES'

from mlchain.base.log import logger
from .context import mlchain_context

from .base.exceptions import *
from .config import mlconfig
Expand Down
1 change: 1 addition & 0 deletions mlchain/server/flask_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def __get_msgpack_blosc_response(self, output, status=200):

def init_context(self):
uid = str(uuid4())
mlchain_context.set_mlchain_context_id(uid)
mlchain_context['MLCHAIN_CONTEXT_ID'] = uid
return uid

Expand Down
1 change: 1 addition & 0 deletions mlchain/server/starlette_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def __get_msgpack_blosc_response(self, output, status=200):

def init_context(self):
uid = str(uuid4())
mlchain_context.set_mlchain_context_id(uid)
mlchain_context['MLCHAIN_CONTEXT_ID'] = uid
return uid

Expand Down
4 changes: 3 additions & 1 deletion mlchain/server/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ def init_context_with_headers(self, headers, context_id:str = None):
mlchain_context.set(context)

if mlchain_context.MLCHAIN_CONTEXT_ID is None:
mlchain_context.set_mlchain_context_id(context_id)
mlchain_context['MLCHAIN_CONTEXT_ID'] = context_id
else:
context_id = mlchain_context['MLCHAIN_CONTEXT_ID']
context_id = mlchain_context.MLCHAIN_CONTEXT_ID

return context_id

def init_context(self):
uid = str(uuid4())
mlchain_context.set_mlchain_context_id(uid)
mlchain_context['MLCHAIN_CONTEXT_ID'] = uid
return uid

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
from setuptools import setup, find_packages

__version__ = "0.3.1"
__version__ = "0.3.2"

project = "mlchain"

Expand Down