hjxdl 0.1.94__py3-none-any.whl → 0.2.2__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 CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.1.94'
16
- __version_tuple__ = version_tuple = (0, 1, 94)
15
+ __version__ = version = '0.2.2'
16
+ __version_tuple__ = version_tuple = (0, 2, 2)
hdl/utils/llm/chat.py CHANGED
@@ -454,6 +454,6 @@ class MMChatter():
454
454
  output = result.stdout
455
455
 
456
456
  # Process the model's response by parsing the output
457
- response = output.splitlines()[-1] # Assuming the last line is the model's response
457
+ response = output.splitlines()[-1].strip('<assistant>') # Assuming the last line is the model's response
458
458
 
459
459
  return response
@@ -0,0 +1,56 @@
1
+ import argparse
2
+ import gradio as gr
3
+ from .chat import OpenAI_M
4
+
5
+ # 定义流式输出的生成函数
6
+ def chat_with_llm(user_input, chat_history=[]):
7
+ chat_history.append(("User: " + user_input, "Bot: ")) # 初始先追加用户消息
8
+ yield "", chat_history, chat_history # 返回用户消息
9
+
10
+ bot_message = "" # Bot 消息初始化为空
11
+ resp = llm.stream(
12
+ "你的身份是芯途异构(ICTrek)的人工智能小助手,由芯途异构公司研发,请回答如下问题:\n"
13
+ + user_input
14
+ ) # 获取流式响应
15
+
16
+ for chunk in resp:
17
+ bot_message += chunk # 累加流式输出
18
+ chat_history[-1] = ("User: " + user_input, "Bot: " + bot_message)
19
+ yield "", chat_history, chat_history # 每次输出更新后的聊天记录
20
+
21
+ # 构建 Gradio 界面
22
+ def create_demo():
23
+ with gr.Blocks() as demo:
24
+ chat_history = gr.State([]) # 存储聊天历史
25
+ output = gr.Chatbot(label="Chat History") # 聊天记录在页面顶端
26
+
27
+ with gr.Row(): # 用户输入框在页面底端
28
+ chatbox = gr.Textbox(
29
+ label="Your Message", placeholder="Type your message here...", show_label=False
30
+ )
31
+ send_button = gr.Button("Send")
32
+
33
+ # 绑定发送消息的交互
34
+ send_button.click(chat_with_llm, [chatbox, chat_history], [chatbox, output, chat_history], queue=True)
35
+ chatbox.submit(chat_with_llm, [chatbox, chat_history], [chatbox, output, chat_history], queue=True) # 支持回车发送
36
+
37
+ return demo
38
+
39
+ if __name__ == "__main__":
40
+ # 使用 argparse 处理命令行参数
41
+ parser = argparse.ArgumentParser(description="Gradio LLM Chatbot")
42
+ parser.add_argument("--host", type=str, default="0.0.0.0", help="The host to launch the app on.")
43
+ parser.add_argument("--port", type=int, default=10077, help="The port to launch the app on.")
44
+ parser.add_argument("--llm_host", type=str, default="127.0.0.1", help="The LLM server IP.")
45
+ parser.add_argument("--llm_port", type=int, default=22277, help="The LLM server port.")
46
+ args = parser.parse_args()
47
+
48
+ # 初始化连接到 LLM 服务器的接口,使用传入的 host 和 port
49
+ llm = OpenAI_M(
50
+ server_ip=args.llm_host,
51
+ server_port=args.llm_port
52
+ )
53
+
54
+ # 启动 Gradio 应用
55
+ demo = create_demo()
56
+ demo.launch(server_name=args.host, server_port=args.port)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hjxdl
3
- Version: 0.1.94
3
+ Version: 0.2.2
4
4
  Summary: A collection of functions for Jupyter notebooks
5
5
  Home-page: https://github.com/huluxiaohuowa/hdl
6
6
  Author: Jianxing Hu
@@ -1,5 +1,5 @@
1
1
  hdl/__init__.py,sha256=GffnD0jLJdhkd-vo989v40N90sQbofkayRBwxc6TVhQ,72
2
- hdl/_version.py,sha256=03clbULp3b9RrCR0DpkVeYj6R4aCnFJBab4aegAAlio,413
2
+ hdl/_version.py,sha256=RrHB9KG1O3GPm--rbTedqmZbdDrbgeRLXBmT4OBUqqI,411
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
@@ -127,7 +127,8 @@ hdl/utils/desc/template.py,sha256=a0UAkkKctt_EHY9UECsIIAwVkGPcM1Hr01HSkRMeIuw,12
127
127
  hdl/utils/general/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
128
128
  hdl/utils/general/glob.py,sha256=8-RCnt6L297wMIfn34ZAMCsGCZUjHG3MGglGZI1cX0g,491
129
129
  hdl/utils/llm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
130
- hdl/utils/llm/chat.py,sha256=VFTyXodWse63M4NLFznz6JEz6_5hDFYy47lY8cq4gGA,14870
130
+ hdl/utils/llm/chat.py,sha256=OzyY9xACOOocx9zZigtq9YAPvHtDUo8v2fvf1Tyjg_U,14891
131
+ hdl/utils/llm/chat_uitest.py,sha256=gQjYsQYHHz7xy5_4_Y9g4ODZPjeSYIr48WbkPbVr8tA,2391
131
132
  hdl/utils/llm/embs.py,sha256=Tf0FOYrOFZp7qQpEPiSCXzlgyHH0X9HVTUtsup74a9E,7174
132
133
  hdl/utils/llm/extract.py,sha256=2sK_WJzmYIc8iuWaM9DA6Nw3_6q1O4lJ5pKpcZo-bBA,6512
133
134
  hdl/utils/llm/llama_chat.py,sha256=watcHGOaz-bv3x-yDucYlGk5f8FiqfFhwWogrl334fk,4387
@@ -136,7 +137,7 @@ hdl/utils/schedulers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
136
137
  hdl/utils/schedulers/norm_lr.py,sha256=bDwCmdEK-WkgxQMFBiMuchv8Mm7C0-GZJ6usm-PQk14,4461
137
138
  hdl/utils/weather/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
138
139
  hdl/utils/weather/weather.py,sha256=k11o6wM15kF8b9NMlEfrg68ak-SfSYLN3nOOflFUv-I,4381
139
- hjxdl-0.1.94.dist-info/METADATA,sha256=tH-0-OFejzzH5MiJoLVpWtnlLlpVtLAY5DtDrkk-_dY,866
140
- hjxdl-0.1.94.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
141
- hjxdl-0.1.94.dist-info/top_level.txt,sha256=-kxwTM5JPhylp06z3zAVO3w6_h7wtBfBo2zgM6YZoTk,4
142
- hjxdl-0.1.94.dist-info/RECORD,,
140
+ hjxdl-0.2.2.dist-info/METADATA,sha256=GedPc2BO9NP8NIzbFInbQu5rsMM1rhNW4oPXsJkPD5s,865
141
+ hjxdl-0.2.2.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
142
+ hjxdl-0.2.2.dist-info/top_level.txt,sha256=-kxwTM5JPhylp06z3zAVO3w6_h7wtBfBo2zgM6YZoTk,4
143
+ hjxdl-0.2.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.1.0)
2
+ Generator: setuptools (75.2.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5