hjxdl 0.3.14__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/chat.py +24 -2
- hdl/utils/llm/llm_wrapper.py +124 -0
- {hjxdl-0.3.14.dist-info → hjxdl-0.3.16.dist-info}/METADATA +1 -1
- {hjxdl-0.3.14.dist-info → hjxdl-0.3.16.dist-info}/RECORD +8 -7
- {hjxdl-0.3.14.dist-info → hjxdl-0.3.16.dist-info}/LICENSE +0 -0
- {hjxdl-0.3.14.dist-info → hjxdl-0.3.16.dist-info}/WHEEL +0 -0
- {hjxdl-0.3.14.dist-info → hjxdl-0.3.16.dist-info}/top_level.txt +0 -0
hdl/_version.py
CHANGED
hdl/utils/llm/chat.py
CHANGED
@@ -125,6 +125,7 @@ class OpenAI_M:
|
|
125
125
|
self,
|
126
126
|
client_conf: dict = None,
|
127
127
|
client_conf_dir: str = None,
|
128
|
+
load_conf: bool = True,
|
128
129
|
tools: list = None,
|
129
130
|
tool_desc: dict = None,
|
130
131
|
cot_desc: str = None,
|
@@ -150,11 +151,12 @@ class OpenAI_M:
|
|
150
151
|
*args: Additional positional arguments.
|
151
152
|
**kwargs: Additional keyword arguments.
|
152
153
|
"""
|
153
|
-
|
154
|
+
self.client_conf = {}
|
154
155
|
if client_conf is None:
|
155
156
|
assert client_conf_dir is not None
|
156
157
|
self.client_conf_path = client_conf_dir
|
157
|
-
|
158
|
+
if load_conf:
|
159
|
+
self.load_clients()
|
158
160
|
else:
|
159
161
|
self.client_conf = client_conf
|
160
162
|
|
@@ -188,6 +190,26 @@ class OpenAI_M:
|
|
188
190
|
self.cot_desc = cot_desc if cot_desc else COT_TEMPLATE
|
189
191
|
self.od_desc = od_desc if od_desc else OD_TEMPLATE
|
190
192
|
|
193
|
+
def add_client(
|
194
|
+
self,
|
195
|
+
client_id: str,
|
196
|
+
host: str,
|
197
|
+
port: int = None,
|
198
|
+
model: str = "default_model",
|
199
|
+
api_key: str = "dummy_key",
|
200
|
+
**kwargs
|
201
|
+
):
|
202
|
+
self.client_conf[client_id] = {}
|
203
|
+
if not host.startswith('http') and port:
|
204
|
+
host = f"http://{host}:{port}/v1"
|
205
|
+
self.client_conf[client_id]['host'] = host
|
206
|
+
self.client_conf[client_id]['model'] = model
|
207
|
+
self.client_conf[client_id]['client'] = OpenAI(
|
208
|
+
base_url=host,
|
209
|
+
api_key=api_key,
|
210
|
+
**kwargs
|
211
|
+
)
|
212
|
+
|
191
213
|
def load_clients(self):
|
192
214
|
with open(self.client_conf_path, 'r') as file:
|
193
215
|
data = yaml.safe_load(file)
|
@@ -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
|
@@ -128,19 +128,20 @@ hdl/utils/general/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
|
|
128
128
|
hdl/utils/general/glob.py,sha256=Zuf7WHU0UdUPOs9UrhxmrCiMC8GrHxQU6n3mTThv6yc,1120
|
129
129
|
hdl/utils/general/runners.py,sha256=x7QBolp3MrqNV6L4rB6Ueybr26bqkRFZTuXhY0SwyLk,3061
|
130
130
|
hdl/utils/llm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
131
|
-
hdl/utils/llm/chat.py,sha256=
|
131
|
+
hdl/utils/llm/chat.py,sha256=q0zQmf-6DeSYOrC2qDn_QFOlILjRHU69eVRUn0eIIbA,26526
|
132
132
|
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
|