hjxdl 0.2.77__py3-none-any.whl → 0.2.79__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 +30 -89
- {hjxdl-0.2.77.dist-info → hjxdl-0.2.79.dist-info}/METADATA +1 -1
- {hjxdl-0.2.77.dist-info → hjxdl-0.2.79.dist-info}/RECORD +6 -6
- {hjxdl-0.2.77.dist-info → hjxdl-0.2.79.dist-info}/WHEEL +0 -0
- {hjxdl-0.2.77.dist-info → hjxdl-0.2.79.dist-info}/top_level.txt +0 -0
hdl/_version.py
CHANGED
hdl/utils/llm/chat.py
CHANGED
@@ -32,28 +32,44 @@ def parse_fn_markdown(markdown_text, params_key="params"):
|
|
32
32
|
result[params_key] = params
|
33
33
|
return result
|
34
34
|
|
35
|
+
def parse_fn_markdown(markdown_text, params_key="params"):
|
36
|
+
# 将 Markdown 文本按行分割并去掉空白
|
37
|
+
lines = markdown_text.strip().split("\n")
|
38
|
+
result = {}
|
39
|
+
params = {}
|
40
|
+
|
41
|
+
for line in lines:
|
42
|
+
# 匹配键值对(即 key: value 格式),支持中英文冒号和空白
|
43
|
+
match = re.match(r"-\s*(\w+)\s*[::]\s*(.+)", line.strip())
|
44
|
+
if match:
|
45
|
+
key, value = match.groups()
|
46
|
+
if key == "function_name":
|
47
|
+
result[key] = value.strip() # 固定的 function_name
|
48
|
+
else:
|
49
|
+
params[key] = value.strip() # 其他进入 params
|
50
|
+
|
51
|
+
# 如果有 params_key,就嵌套到该键名下
|
52
|
+
result[params_key] = params
|
53
|
+
return result
|
54
|
+
|
35
55
|
def parse_cot_markdown(markdown_text):
|
36
|
-
#
|
37
|
-
title_match = re.search(r"##\s*(
|
38
|
-
title = title_match.group(1) if title_match else ""
|
39
|
-
# title = title.replace(":", "").replace(":", "").replace(" ", "")
|
56
|
+
# 提取标题(支持跨行)
|
57
|
+
title_match = re.search(r"##\s*(.+?)(?=\n-|\Z)", markdown_text, re.DOTALL)
|
58
|
+
title = title_match.group(1).strip() if title_match else ""
|
40
59
|
|
41
60
|
# 提取工具
|
42
|
-
tool_match = re.search(r"
|
61
|
+
tool_match = re.search(r"-\s*tool\s*[::]\s*(.+?)(?=\n-|\Z)", markdown_text, re.DOTALL)
|
43
62
|
tool = tool_match.group(1).strip() if tool_match else ""
|
44
|
-
# tool = tool.replace(":", "").replace(":", "").replace(" ", "")
|
45
63
|
|
46
|
-
#
|
47
|
-
content_match = re.search(r"
|
48
|
-
content = content_match.group(1) if content_match else ""
|
49
|
-
# content = content.replace(":", "").replace(":", "").replace(" ", "")
|
64
|
+
# 提取内容(支持跨行)
|
65
|
+
content_match = re.search(r"-\s*content\s*[::]\s*(.+?)(?=\n-|\Z)", markdown_text, re.DOTALL)
|
66
|
+
content = content_match.group(1).strip() if content_match else ""
|
50
67
|
|
51
68
|
# 提取停止思考
|
52
|
-
stop_thinking_match = re.search(r"
|
53
|
-
stop_thinking = stop_thinking_match.group(1)
|
69
|
+
stop_thinking_match = re.search(r"-\s*stop_thinking\s*[::]\s*(.+?)(?=\n-|\Z)", markdown_text, re.DOTALL)
|
70
|
+
stop_thinking = stop_thinking_match.group(1).strip().lower() in ["true"] if stop_thinking_match else False
|
54
71
|
|
55
|
-
|
56
|
-
# 组装为字典
|
72
|
+
# 返回解析结果的字典
|
57
73
|
return {
|
58
74
|
"title": title,
|
59
75
|
"tool": tool,
|
@@ -61,81 +77,6 @@ def parse_cot_markdown(markdown_text):
|
|
61
77
|
"stop_thinking": stop_thinking
|
62
78
|
}
|
63
79
|
|
64
|
-
def chat_oai_stream(
|
65
|
-
base_url="http://127.0.0.1:8000/v1",
|
66
|
-
api_key="dummy_key",
|
67
|
-
model="default_model",
|
68
|
-
prompt="Who are you?",
|
69
|
-
*args,
|
70
|
-
**kwargs
|
71
|
-
):
|
72
|
-
"""Chat with OpenAI's GPT-3 model using the specified parameters.
|
73
|
-
|
74
|
-
Args:
|
75
|
-
base_url (str): The base URL for the OpenAI API. Default is "http://127.0.0.1:8000/v1".
|
76
|
-
api_key (str): The API key for accessing the OpenAI API. Default is "dummy_key".
|
77
|
-
model (str): The model ID to use for the chat. Default is "/data/models/Qwen-7B-Chat-Int4".
|
78
|
-
prompt (str): The initial prompt for the chat conversation.
|
79
|
-
|
80
|
-
Yields:
|
81
|
-
str: The generated content from the chat conversation.
|
82
|
-
|
83
|
-
"""
|
84
|
-
client = OpenAI(
|
85
|
-
base_url=base_url,
|
86
|
-
api_key=api_key,
|
87
|
-
)
|
88
|
-
response = client.chat.completions.create(
|
89
|
-
model=model,
|
90
|
-
messages=[{
|
91
|
-
"role": "user",
|
92
|
-
"content": prompt
|
93
|
-
}],
|
94
|
-
stream=True,
|
95
|
-
*args,
|
96
|
-
**kwargs
|
97
|
-
)
|
98
|
-
|
99
|
-
for chunk in response:
|
100
|
-
content = chunk.choices[0].delta.content
|
101
|
-
yield content
|
102
|
-
|
103
|
-
|
104
|
-
def chat_oai_invoke(
|
105
|
-
base_url="http://127.0.0.1:8000/v1",
|
106
|
-
api_key="dummy_key",
|
107
|
-
model="default_model",
|
108
|
-
prompt="Who are you?",
|
109
|
-
*args,
|
110
|
-
**kwargs
|
111
|
-
):
|
112
|
-
"""Invoke OpenAI chat API to generate a response based on the given prompt.
|
113
|
-
|
114
|
-
Args:
|
115
|
-
base_url (str): The base URL of the OpenAI API. Default is "http://127.0.0.1:8000/v1".
|
116
|
-
api_key (str): The API key for accessing the OpenAI API. Default is "dummy_key".
|
117
|
-
model (str): The model to use for generating the response. Default is "/data/models/Qwen-7B-Chat-Int4".
|
118
|
-
prompt (str): The prompt message to start the conversation. Default is "Who are you?".
|
119
|
-
|
120
|
-
Returns:
|
121
|
-
str: The response generated by the OpenAI chat API based on the prompt.
|
122
|
-
"""
|
123
|
-
client = OpenAI(
|
124
|
-
base_url=base_url,
|
125
|
-
api_key=api_key,
|
126
|
-
)
|
127
|
-
response = client.chat.completions.create(
|
128
|
-
model=model,
|
129
|
-
messages=[{
|
130
|
-
"role": "user",
|
131
|
-
"content": prompt
|
132
|
-
}],
|
133
|
-
stream=False,
|
134
|
-
*args,
|
135
|
-
**kwargs
|
136
|
-
)
|
137
|
-
|
138
|
-
return response.choices[0].message.content
|
139
80
|
|
140
81
|
def run_tool_with_kwargs(tool, func_kwargs):
|
141
82
|
"""Run the specified tool with the provided keyword arguments.
|
@@ -1,5 +1,5 @@
|
|
1
1
|
hdl/__init__.py,sha256=GffnD0jLJdhkd-vo989v40N90sQbofkayRBwxc6TVhQ,72
|
2
|
-
hdl/_version.py,sha256=
|
2
|
+
hdl/_version.py,sha256=Bq7VoQXo0kndBONXau_LHpnDFGs-mLCodLWPjZgvFhA,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,7 +128,7 @@ hdl/utils/general/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
|
|
128
128
|
hdl/utils/general/glob.py,sha256=8-RCnt6L297wMIfn34ZAMCsGCZUjHG3MGglGZI1cX0g,491
|
129
129
|
hdl/utils/general/runners.py,sha256=EFTk9PeVnqc51yU4b-HxsLwJyMA7dFMZBsdAa-VZ-sQ,2880
|
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=AeGyN6Fv4SjhvDwjKFpE-GyBlSA5THSbb0rXzUjzQ2A,20437
|
132
132
|
hdl/utils/llm/chatgr.py,sha256=A9SCWAvQulgO2x0ArIqcmgd_iVWVbSi1Oj15Diwb3Ok,3743
|
133
133
|
hdl/utils/llm/embs.py,sha256=Tf0FOYrOFZp7qQpEPiSCXzlgyHH0X9HVTUtsup74a9E,7174
|
134
134
|
hdl/utils/llm/extract.py,sha256=2sK_WJzmYIc8iuWaM9DA6Nw3_6q1O4lJ5pKpcZo-bBA,6512
|
@@ -139,7 +139,7 @@ hdl/utils/schedulers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
|
|
139
139
|
hdl/utils/schedulers/norm_lr.py,sha256=bDwCmdEK-WkgxQMFBiMuchv8Mm7C0-GZJ6usm-PQk14,4461
|
140
140
|
hdl/utils/weather/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
141
141
|
hdl/utils/weather/weather.py,sha256=k11o6wM15kF8b9NMlEfrg68ak-SfSYLN3nOOflFUv-I,4381
|
142
|
-
hjxdl-0.2.
|
143
|
-
hjxdl-0.2.
|
144
|
-
hjxdl-0.2.
|
145
|
-
hjxdl-0.2.
|
142
|
+
hjxdl-0.2.79.dist-info/METADATA,sha256=2JpIP2r7MfUMvX6C9hoBY-XG9ibPP8Ai0Jyg_Gm654o,836
|
143
|
+
hjxdl-0.2.79.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
144
|
+
hjxdl-0.2.79.dist-info/top_level.txt,sha256=-kxwTM5JPhylp06z3zAVO3w6_h7wtBfBo2zgM6YZoTk,4
|
145
|
+
hjxdl-0.2.79.dist-info/RECORD,,
|
File without changes
|
File without changes
|