hjxdl 0.3.15__py3-none-any.whl → 0.3.16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hdl/_version.py +2 -2
 - hdl/utils/llm/llm_wrapper.py +124 -0
 - {hjxdl-0.3.15.dist-info → hjxdl-0.3.16.dist-info}/METADATA +1 -1
 - {hjxdl-0.3.15.dist-info → hjxdl-0.3.16.dist-info}/RECORD +7 -6
 - {hjxdl-0.3.15.dist-info → hjxdl-0.3.16.dist-info}/LICENSE +0 -0
 - {hjxdl-0.3.15.dist-info → hjxdl-0.3.16.dist-info}/WHEEL +0 -0
 - {hjxdl-0.3.15.dist-info → hjxdl-0.3.16.dist-info}/top_level.txt +0 -0
 
    
        hdl/_version.py
    CHANGED
    
    
| 
         @@ -0,0 +1,124 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            import yaml
         
     | 
| 
      
 2 
     | 
    
         
            +
            import typing as t
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            from openai import OpenAI
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            class OpenAIWrapper(object):
         
     | 
| 
      
 8 
     | 
    
         
            +
                def __init__(
         
     | 
| 
      
 9 
     | 
    
         
            +
                    self,
         
     | 
| 
      
 10 
     | 
    
         
            +
                    client_conf: dict = None,
         
     | 
| 
      
 11 
     | 
    
         
            +
                    client_conf_dir: str = None,
         
     | 
| 
      
 12 
     | 
    
         
            +
                    load_conf: bool = True,
         
     | 
| 
      
 13 
     | 
    
         
            +
                    *args,
         
     | 
| 
      
 14 
     | 
    
         
            +
                    **kwargs
         
     | 
| 
      
 15 
     | 
    
         
            +
                ):
         
     | 
| 
      
 16 
     | 
    
         
            +
                    self.client_conf = {}
         
     | 
| 
      
 17 
     | 
    
         
            +
                    if client_conf is None:
         
     | 
| 
      
 18 
     | 
    
         
            +
                        assert client_conf_dir is not None
         
     | 
| 
      
 19 
     | 
    
         
            +
                        self.client_conf_path = client_conf_dir
         
     | 
| 
      
 20 
     | 
    
         
            +
                        if load_conf:
         
     | 
| 
      
 21 
     | 
    
         
            +
                            self.load_clients()
         
     | 
| 
      
 22 
     | 
    
         
            +
                    else:
         
     | 
| 
      
 23 
     | 
    
         
            +
                        self.client_conf = client_conf
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                    # self.clients = {}
         
     | 
| 
      
 26 
     | 
    
         
            +
                    for _, conf in self.client_conf.items():
         
     | 
| 
      
 27 
     | 
    
         
            +
                        conf["client"] = OpenAI(
         
     | 
| 
      
 28 
     | 
    
         
            +
                            base_url=conf["host"],
         
     | 
| 
      
 29 
     | 
    
         
            +
                            api_key=conf.get("api_key", "dummy_key"),
         
     | 
| 
      
 30 
     | 
    
         
            +
                            *args,
         
     | 
| 
      
 31 
     | 
    
         
            +
                            **kwargs
         
     | 
| 
      
 32 
     | 
    
         
            +
                        )
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                def add_client(
         
     | 
| 
      
 35 
     | 
    
         
            +
                    self,
         
     | 
| 
      
 36 
     | 
    
         
            +
                    client_id: str,
         
     | 
| 
      
 37 
     | 
    
         
            +
                    host: str,
         
     | 
| 
      
 38 
     | 
    
         
            +
                    port: int = None,
         
     | 
| 
      
 39 
     | 
    
         
            +
                    model: str = "default_model",
         
     | 
| 
      
 40 
     | 
    
         
            +
                    api_key: str = "dummy_key",
         
     | 
| 
      
 41 
     | 
    
         
            +
                    **kwargs
         
     | 
| 
      
 42 
     | 
    
         
            +
                ):
         
     | 
| 
      
 43 
     | 
    
         
            +
                    self.client_conf[client_id] = {}
         
     | 
| 
      
 44 
     | 
    
         
            +
                    if not host.startswith('http') and port:
         
     | 
| 
      
 45 
     | 
    
         
            +
                        host = f"http://{host}:{port}/v1"
         
     | 
| 
      
 46 
     | 
    
         
            +
                    self.client_conf[client_id]['host'] = host
         
     | 
| 
      
 47 
     | 
    
         
            +
                    self.client_conf[client_id]['model'] = model
         
     | 
| 
      
 48 
     | 
    
         
            +
                    self.client_conf[client_id]['client'] = OpenAI(
         
     | 
| 
      
 49 
     | 
    
         
            +
                        base_url=host,
         
     | 
| 
      
 50 
     | 
    
         
            +
                        api_key=api_key,
         
     | 
| 
      
 51 
     | 
    
         
            +
                        **kwargs
         
     | 
| 
      
 52 
     | 
    
         
            +
                    )
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                def load_clients(self):
         
     | 
| 
      
 55 
     | 
    
         
            +
                    with open(self.client_conf_path, 'r') as file:
         
     | 
| 
      
 56 
     | 
    
         
            +
                        data = yaml.safe_load(file)
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                    # 更新 host 字段
         
     | 
| 
      
 59 
     | 
    
         
            +
                    for _, value in data.items():
         
     | 
| 
      
 60 
     | 
    
         
            +
                        host = value.get('host', '')
         
     | 
| 
      
 61 
     | 
    
         
            +
                        port = value.get('port', '')
         
     | 
| 
      
 62 
     | 
    
         
            +
                        if not host.startswith('http') and port:  # 确保有 port 才处理
         
     | 
| 
      
 63 
     | 
    
         
            +
                            value['host'] = f"http://{host}:{port}/v1"
         
     | 
| 
      
 64 
     | 
    
         
            +
                    self.client_conf = data
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                def get_resp(
         
     | 
| 
      
 68 
     | 
    
         
            +
                    self,
         
     | 
| 
      
 69 
     | 
    
         
            +
                    prompt,
         
     | 
| 
      
 70 
     | 
    
         
            +
                    client_id: str = None,
         
     | 
| 
      
 71 
     | 
    
         
            +
                    history: list = None,
         
     | 
| 
      
 72 
     | 
    
         
            +
                    sys_info: str = None,
         
     | 
| 
      
 73 
     | 
    
         
            +
                    assis_info: str = None,
         
     | 
| 
      
 74 
     | 
    
         
            +
                    images: list = None,
         
     | 
| 
      
 75 
     | 
    
         
            +
                    image_keys: tuple = ("image_url", "url"),
         
     | 
| 
      
 76 
     | 
    
         
            +
                    model: str=None,
         
     | 
| 
      
 77 
     | 
    
         
            +
                    tools: list = None,
         
     | 
| 
      
 78 
     | 
    
         
            +
                    stream: bool = True,
         
     | 
| 
      
 79 
     | 
    
         
            +
                    **kwargs: t.Any,
         
     | 
| 
      
 80 
     | 
    
         
            +
                ):
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
                    client = self.client_conf[client_id]['client']
         
     | 
| 
      
 83 
     | 
    
         
            +
                    messages = []
         
     | 
| 
      
 84 
     | 
    
         
            +
                    if history:
         
     | 
| 
      
 85 
     | 
    
         
            +
                        messages = history
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
                    if sys_info:
         
     | 
| 
      
 88 
     | 
    
         
            +
                        messages.append({
         
     | 
| 
      
 89 
     | 
    
         
            +
                            "role": "system",
         
     | 
| 
      
 90 
     | 
    
         
            +
                            "content": sys_info
         
     | 
| 
      
 91 
     | 
    
         
            +
                        })
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
                    if not model:
         
     | 
| 
      
 95 
     | 
    
         
            +
                        model = self.client_conf[client_id]["model"]
         
     | 
| 
      
 96 
     | 
    
         
            +
                    # Adjust the image_keys to be a tuple of length 3 based on its current length
         
     | 
| 
      
 97 
     | 
    
         
            +
                    if isinstance(image_keys, str):
         
     | 
| 
      
 98 
     | 
    
         
            +
                        image_keys = (image_keys,) * 3
         
     | 
| 
      
 99 
     | 
    
         
            +
                    elif len(image_keys) == 2:
         
     | 
| 
      
 100 
     | 
    
         
            +
                        image_keys = (image_keys[0],) + tuple(image_keys)
         
     | 
| 
      
 101 
     | 
    
         
            +
                    elif len(image_keys) == 1:
         
     | 
| 
      
 102 
     | 
    
         
            +
                        image_keys = (image_keys[0],) * 3
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                    content = []
         
     | 
| 
      
 105 
     | 
    
         
            +
                    if images:
         
     | 
| 
      
 106 
     | 
    
         
            +
                        if isinstance(images, str):
         
     | 
| 
      
 107 
     | 
    
         
            +
                            images = [images]
         
     | 
| 
      
 108 
     | 
    
         
            +
                        for img in images:
         
     | 
| 
      
 109 
     | 
    
         
            +
                            content.append({
         
     | 
| 
      
 110 
     | 
    
         
            +
                                "type": image_keys[0],
         
     | 
| 
      
 111 
     | 
    
         
            +
                                image_keys[1]: {
         
     | 
| 
      
 112 
     | 
    
         
            +
                                    image_keys[2]: img
         
     | 
| 
      
 113 
     | 
    
         
            +
                                }
         
     | 
| 
      
 114 
     | 
    
         
            +
                            })
         
     | 
| 
      
 115 
     | 
    
         
            +
                    else:
         
     | 
| 
      
 116 
     | 
    
         
            +
                        # If no images are provided, content is simply the prompt text
         
     | 
| 
      
 117 
     | 
    
         
            +
                        content = prompt
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
                    # Add the user's input as a message
         
     | 
| 
      
 120 
     | 
    
         
            +
                    messages.append({
         
     | 
| 
      
 121 
     | 
    
         
            +
                        "role": "user",
         
     | 
| 
      
 122 
     | 
    
         
            +
                        "content": content
         
     | 
| 
      
 123 
     | 
    
         
            +
                    })
         
     | 
| 
      
 124 
     | 
    
         
            +
             
     | 
| 
         @@ -1,5 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            hdl/__init__.py,sha256=GffnD0jLJdhkd-vo989v40N90sQbofkayRBwxc6TVhQ,72
         
     | 
| 
       2 
     | 
    
         
            -
            hdl/_version.py,sha256= 
     | 
| 
      
 2 
     | 
    
         
            +
            hdl/_version.py,sha256=D8u-23f8Le_E16tPMMyTPeU4VTKL4yR8GkJhKkxDaXE,413
         
     | 
| 
       3 
3 
     | 
    
         
             
            hdl/args/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
         
     | 
| 
       4 
4 
     | 
    
         
             
            hdl/args/loss_args.py,sha256=s7YzSdd7IjD24rZvvOrxLLFqMZQb9YylxKeyelSdrTk,70
         
     | 
| 
       5 
5 
     | 
    
         
             
            hdl/controllers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
         
     | 
| 
         @@ -133,14 +133,15 @@ hdl/utils/llm/chatgr.py,sha256=5F5PJHe8vz3iCfi4TT54DCLRi1UeJshECdVtgvvvao0,3696 
     | 
|
| 
       133 
133 
     | 
    
         
             
            hdl/utils/llm/embs.py,sha256=Tf0FOYrOFZp7qQpEPiSCXzlgyHH0X9HVTUtsup74a9E,7174
         
     | 
| 
       134 
134 
     | 
    
         
             
            hdl/utils/llm/extract.py,sha256=2sK_WJzmYIc8iuWaM9DA6Nw3_6q1O4lJ5pKpcZo-bBA,6512
         
     | 
| 
       135 
135 
     | 
    
         
             
            hdl/utils/llm/llama_chat.py,sha256=watcHGOaz-bv3x-yDucYlGk5f8FiqfFhwWogrl334fk,4387
         
     | 
| 
      
 136 
     | 
    
         
            +
            hdl/utils/llm/llm_wrapper.py,sha256=sE0vays3ndXTa1HozoLOERYcloxyBW63EWdSwMLp2Yo,3511
         
     | 
| 
       136 
137 
     | 
    
         
             
            hdl/utils/llm/vis.py,sha256=SSP6tOwKLq0hWcpM3twI9TitqzBmKjlcGrnXEWYlCzM,26055
         
     | 
| 
       137 
138 
     | 
    
         
             
            hdl/utils/llm/visrag.py,sha256=0i-VrxqgiV-J7R3VPshu9oc7-rKjFJOldYik3HDXj6M,10176
         
     | 
| 
       138 
139 
     | 
    
         
             
            hdl/utils/schedulers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
         
     | 
| 
       139 
140 
     | 
    
         
             
            hdl/utils/schedulers/norm_lr.py,sha256=bDwCmdEK-WkgxQMFBiMuchv8Mm7C0-GZJ6usm-PQk14,4461
         
     | 
| 
       140 
141 
     | 
    
         
             
            hdl/utils/weather/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
         
     | 
| 
       141 
142 
     | 
    
         
             
            hdl/utils/weather/weather.py,sha256=k11o6wM15kF8b9NMlEfrg68ak-SfSYLN3nOOflFUv-I,4381
         
     | 
| 
       142 
     | 
    
         
            -
            hjxdl-0.3. 
     | 
| 
       143 
     | 
    
         
            -
            hjxdl-0.3. 
     | 
| 
       144 
     | 
    
         
            -
            hjxdl-0.3. 
     | 
| 
       145 
     | 
    
         
            -
            hjxdl-0.3. 
     | 
| 
       146 
     | 
    
         
            -
            hjxdl-0.3. 
     | 
| 
      
 143 
     | 
    
         
            +
            hjxdl-0.3.16.dist-info/LICENSE,sha256=lkMiSbeZHBQLB9LJEkS9-L3Z-LBC4yGnKrzHSG8RkPM,2599
         
     | 
| 
      
 144 
     | 
    
         
            +
            hjxdl-0.3.16.dist-info/METADATA,sha256=cCJsd4iB2Da-q95aYZ6GmY6TT0f9nHOCtjNDg1WQDC0,1310
         
     | 
| 
      
 145 
     | 
    
         
            +
            hjxdl-0.3.16.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
         
     | 
| 
      
 146 
     | 
    
         
            +
            hjxdl-0.3.16.dist-info/top_level.txt,sha256=-kxwTM5JPhylp06z3zAVO3w6_h7wtBfBo2zgM6YZoTk,4
         
     | 
| 
      
 147 
     | 
    
         
            +
            hjxdl-0.3.16.dist-info/RECORD,,
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     |