File size: 931 Bytes
81e6403
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from typing import Dict, List, Any
from lmdeploy import pipeline
from lmdeploy.vl import load_image
from lmdeploy.messages import TurbomindEngineConfig

class EndpointHandler():
    def __init__(self, path):
        # Preload the model at initialization
        backend_config = TurbomindEngineConfig(model_name ="deepseek-ai/deepseek-coder-33b-instruct",model_format='hf',tp=1)
        self.pipe = pipeline(f"{path}", backend_config=backend_config, log_level='INFO')

    def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
        """

        data args:

            inputs (:obj: `str`)

            kwargs

        Return:

            A :obj:`str`| `Dict`: will be serialized and returned

        """
        query = data.get('query')
        if not query:
            return [{'error': 'No query provided'}]
        
        response = self.pipe([query])
        return {'response': response.text}