hjxdl 0.0.1__tar.gz → 0.0.2__tar.gz

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.
Files changed (114) hide show
  1. {hjxdl-0.0.1/hjxdl.egg-info → hjxdl-0.0.2}/PKG-INFO +1 -1
  2. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/_version.py +2 -2
  3. hjxdl-0.0.2/hdl/utils/llm/chat.py +164 -0
  4. {hjxdl-0.0.1 → hjxdl-0.0.2/hjxdl.egg-info}/PKG-INFO +1 -1
  5. {hjxdl-0.0.1 → hjxdl-0.0.2}/hjxdl.egg-info/SOURCES.txt +1 -0
  6. hjxdl-0.0.2/version.txt +1 -0
  7. hjxdl-0.0.1/version.txt +0 -1
  8. {hjxdl-0.0.1 → hjxdl-0.0.2}/.github/workflows/python-publish.yml +0 -0
  9. {hjxdl-0.0.1 → hjxdl-0.0.2}/.gitignore +0 -0
  10. {hjxdl-0.0.1 → hjxdl-0.0.2}/.gitmodules +0 -0
  11. {hjxdl-0.0.1 → hjxdl-0.0.2}/MANIFEST.in +0 -0
  12. {hjxdl-0.0.1 → hjxdl-0.0.2}/README.md +0 -0
  13. {hjxdl-0.0.1 → hjxdl-0.0.2}/__init__.py +0 -0
  14. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/__init__.py +0 -0
  15. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/args/__init__.py +0 -0
  16. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/args/loss_args.py +0 -0
  17. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/controllers/__init__.py +0 -0
  18. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/controllers/al/__init__.py +0 -0
  19. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/controllers/al/al.py +0 -0
  20. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/controllers/al/dispatcher.py +0 -0
  21. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/controllers/al/feedback.py +0 -0
  22. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/controllers/explain/__init__.py +0 -0
  23. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/controllers/explain/shapley.py +0 -0
  24. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/controllers/explain/subgraphx.py +0 -0
  25. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/controllers/predictors/gin_predictor.py +0 -0
  26. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/controllers/predictors/rxn_predictor.py +0 -0
  27. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/controllers/predictors/torch_predictor.py +0 -0
  28. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/controllers/train/__init__.py +0 -0
  29. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/controllers/train/rxn_train.py +0 -0
  30. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/controllers/train/train.py +0 -0
  31. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/controllers/train/train_ginet.py +0 -0
  32. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/controllers/train/trainer_base.py +0 -0
  33. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/controllers/train/trainer_iterative.py +0 -0
  34. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/__init__.py +0 -0
  35. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/dataset/__init__.py +0 -0
  36. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/dataset/base_dataset.py +0 -0
  37. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/dataset/fp/__init__.py +0 -0
  38. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/dataset/fp/fp_dataset.py +0 -0
  39. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/dataset/graph/__init__.py +0 -0
  40. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/dataset/graph/chiral.py +0 -0
  41. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/dataset/graph/gin.py +0 -0
  42. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/dataset/graph/molnet.py +0 -0
  43. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/dataset/loaders/__init__.py +0 -0
  44. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/dataset/loaders/chiral_graph.py +0 -0
  45. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/dataset/loaders/collate_funcs/__init__.py +0 -0
  46. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/dataset/loaders/collate_funcs/fp.py +0 -0
  47. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/dataset/loaders/collate_funcs/rxn.py +0 -0
  48. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/dataset/loaders/general.py +0 -0
  49. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/dataset/loaders/spliter.py +0 -0
  50. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/dataset/samplers/__init__.py +0 -0
  51. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/dataset/samplers/chiral.py +0 -0
  52. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/dataset/seq/__init__.py +0 -0
  53. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/dataset/seq/rxn_dataset.py +0 -0
  54. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/dataset/utils.py +0 -0
  55. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/data/to_mols.py +0 -0
  56. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/features/__init__.py +0 -0
  57. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/features/fp/__init__.py +0 -0
  58. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/features/fp/features_generators.py +0 -0
  59. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/features/graph/__init__.py +0 -0
  60. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/features/graph/featurization.py +0 -0
  61. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/features/utils/__init__.py +0 -0
  62. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/features/utils/utils.py +0 -0
  63. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/features/vocab.txt +0 -0
  64. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/include/add2.h +0 -0
  65. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/kernel/add2_kernel.cu +0 -0
  66. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/kernel/test +0 -0
  67. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/kernel/test.cu +0 -0
  68. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/layers/__init__.py +0 -0
  69. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/layers/general/__init__.py +0 -0
  70. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/layers/general/gp.py +0 -0
  71. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/layers/general/linear.py +0 -0
  72. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/layers/graph/__init__.py +0 -0
  73. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/layers/graph/chiral_graph.py +0 -0
  74. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/layers/graph/gcn.py +0 -0
  75. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/layers/graph/gin.py +0 -0
  76. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/layers/graph/tetra.py +0 -0
  77. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/layers/graph/transformer.py +0 -0
  78. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/layers/sequential/__init__.py +0 -0
  79. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/metric_loss/__init__.py +0 -0
  80. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/metric_loss/loss.py +0 -0
  81. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/metric_loss/metric.py +0 -0
  82. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/metric_loss/multi_label.py +0 -0
  83. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/metric_loss/nt_xent.py +0 -0
  84. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/models/__init__.py +0 -0
  85. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/models/chiral_gnn.py +0 -0
  86. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/models/fast_transformer.py +0 -0
  87. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/models/ginet.py +0 -0
  88. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/models/linear.py +0 -0
  89. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/models/model_dict.py +0 -0
  90. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/models/norm_flows.py +0 -0
  91. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/models/optim_dict.py +0 -0
  92. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/models/rxn.py +0 -0
  93. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/models/utils.py +0 -0
  94. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/ops/__init__.py +0 -0
  95. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/ops/utils.py +0 -0
  96. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/optims/__init__.py +0 -0
  97. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/optims/nadam.py +0 -0
  98. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/pytorch/add2_ops.cpp +0 -0
  99. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/utils/__init__.py +0 -0
  100. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/utils/chemical_tools/__init__.py +0 -0
  101. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/utils/chemical_tools/query_info.py +0 -0
  102. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/utils/chemical_tools/sdf.py +0 -0
  103. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/utils/database_tools/__init__.py +0 -0
  104. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/utils/database_tools/connect.py +0 -0
  105. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/utils/general/__init__.py +0 -0
  106. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/utils/general/glob.py +0 -0
  107. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/utils/schedulers/__init__.py +0 -0
  108. {hjxdl-0.0.1 → hjxdl-0.0.2}/hdl/utils/schedulers/norm_lr.py +0 -0
  109. {hjxdl-0.0.1 → hjxdl-0.0.2}/hjxdl.egg-info/dependency_links.txt +0 -0
  110. {hjxdl-0.0.1 → hjxdl-0.0.2}/hjxdl.egg-info/top_level.txt +0 -0
  111. {hjxdl-0.0.1 → hjxdl-0.0.2}/pyproject.toml +0 -0
  112. {hjxdl-0.0.1 → hjxdl-0.0.2}/setup.cfg +0 -0
  113. {hjxdl-0.0.1 → hjxdl-0.0.2}/setup.py +0 -0
  114. {hjxdl-0.0.1 → hjxdl-0.0.2}/update_main.sh +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hjxdl
3
- Version: 0.0.1
3
+ Version: 0.0.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
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.0.1'
16
- __version_tuple__ = version_tuple = (0, 0, 1)
15
+ __version__ = version = '0.0.2'
16
+ __version_tuple__ = version_tuple = (0, 0, 2)
@@ -0,0 +1,164 @@
1
+ import typing as t
2
+
3
+ from llama_cpp import Llama
4
+ from jupyfuncs.llm.openapi import (
5
+ chat_oai_invoke,
6
+ chat_oai_stream
7
+ )
8
+
9
+
10
+ class GGUF_M():
11
+ def __init__(
12
+ self,
13
+ model_path :str,
14
+ device: str='gpu',
15
+ generation_kwargs: dict = {},
16
+ server_ip: str = "127.0.0.1",
17
+ server_port: int = 8000,
18
+ ):
19
+ """Initialize the model from a local path.
20
+ Here it does not manage chat histories.
21
+
22
+ Args:
23
+ model_path (str): The path to the model.
24
+ device (str, optional): The device to use for model initialization. Defaults to 'gpu'.
25
+ generation_kwargs (dict, optional): Additional keyword arguments for model generation. Defaults to {}.
26
+ """
27
+ # 从本地初始化模型
28
+ super().__init__()
29
+ self.generation_kwargs = generation_kwargs
30
+ self.questions = []
31
+ self.resps = []
32
+ print("正在从本地加载模型...")
33
+ if device == 'cpu':
34
+ self.model = Llama(
35
+ model_path=model_path,
36
+ n_threads=self.generation_kwargs['num_threads'],
37
+ n_ctx=self.generation_kwargs['max_context_length'],
38
+ )
39
+ else:
40
+ self.model = Llama(
41
+ model_path=model_path,
42
+ n_threads=self.generation_kwargs['num_threads'],
43
+ n_ctx=self.generation_kwargs['max_context_length'],
44
+ n_gpu_layers=-1
45
+ )
46
+
47
+ print("完成本地模型的加载")
48
+
49
+ def invoke(
50
+ self,
51
+ prompt : str,
52
+ stop: list[str] | None = ["USER:", "ASSISTANT:"],
53
+ # history: list = [],
54
+ **kwargs: t.Any,
55
+ ) -> str:
56
+ """Invoke the model to generate a response based on the given prompt.
57
+
58
+ Args:
59
+ prompt (str): The prompt to be used for generating the response.
60
+ stop (list[str], optional): List of strings that indicate when the model should stop generating the response. Defaults to ["USER:", "ASSISTANT:"].
61
+ **kwargs: Additional keyword arguments to be passed to the model.
62
+
63
+ Returns:
64
+ str: The generated response based on the prompt.
65
+ """
66
+ prompt_final = f"USER:\n{prompt}\nASSISTANT:\n"
67
+
68
+ result = self.model.create_completion(
69
+ prompt_final,
70
+ repeat_penalty=self.generation_kwargs["repetition_penalty"],
71
+ max_tokens=self.generation_kwargs["max_new_tokens"],
72
+ stop=stop,
73
+ echo=False,
74
+ temperature=self.generation_kwargs["temperature"],
75
+ mirostat_mode = 2,
76
+ mirostat_tau=4.0,
77
+ mirostat_eta=1.1
78
+ )
79
+ resp = result['choices'][0]['text']
80
+ # history.append(
81
+ # [prompt, resp]
82
+ # )
83
+ return resp
84
+
85
+ def stream(
86
+ self,
87
+ prompt: str,
88
+ stop: list[str] | None = ["USER:", "ASSISTANT:"],
89
+ # history: list = [],
90
+ **kwargs: t.Any,
91
+ ):
92
+ """Generate text responses based on the given prompt using the model.
93
+
94
+ Args:
95
+ prompt (str): The prompt to generate text responses.
96
+ stop (list[str], optional): List of strings to stop the generation. Defaults to ["USER:", "ASSISTANT:"].
97
+ **kwargs: Additional keyword arguments for the model.
98
+
99
+ Yields:
100
+ str: Text responses generated by the model based on the prompt.
101
+ """
102
+ self.questions.append(prompt)
103
+ prompt = f"USER:\n{prompt}\nASSISTANT:\n"
104
+ output = self.model.create_completion(
105
+ prompt,
106
+ stream=True,
107
+ repeat_penalty=self.generation_kwargs["repetition_penalty"],
108
+ max_tokens=self.generation_kwargs["max_new_tokens"],
109
+ stop=stop,
110
+ echo=False,
111
+ temperature=self.generation_kwargs["temperature"],
112
+ mirostat_mode = 2,
113
+ mirostat_tau=4.0,
114
+ mirostat_eta=1.1
115
+ )
116
+ # history.append([])
117
+ for chunk in output:
118
+ item = chunk['choices'][0]['text']
119
+ # self.resps[-1].append(item)
120
+ yield chunk['choices'][0]['text']
121
+ # self.resps[-1] = "".join(self.resps[-1])
122
+
123
+
124
+ class OpenAI_M():
125
+ def __init__(
126
+ self,
127
+ model_path: str = None,
128
+ device: str='gpu',
129
+ generation_kwargs: dict = {},
130
+ server_ip: str = "172.28.1.2",
131
+ server_port: int = 8000,
132
+ ):
133
+ self.model_path = model_path
134
+ self.server_ip = server_ip
135
+ self.server_port = server_port
136
+ self.base_url = "http://{self.server_ip}:{str(self.server_port)}/v1"
137
+
138
+ def invoke(
139
+ self,
140
+ prompt : str,
141
+ stop: list[str] | None = ["USER:", "ASSISTANT:"],
142
+ # history: list = [],
143
+ **kwargs: t.Any,
144
+ ) -> str:
145
+ resp = chat_oai_invoke(
146
+ base_url=self.base_url,
147
+ model=self.model_path,
148
+ prompt=prompt
149
+ )
150
+ return resp
151
+
152
+ def stream(
153
+ self,
154
+ prompt : str,
155
+ stop: list[str] | None = ["USER:", "ASSISTANT:"],
156
+ # history: list = [],
157
+ **kwargs: t.Any,
158
+ ) -> str:
159
+ resp = chat_oai_stream(
160
+ base_url=self.base_url,
161
+ model=self.model_path,
162
+ prompt=prompt
163
+ )
164
+ return resp
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hjxdl
3
- Version: 0.0.1
3
+ Version: 0.0.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
@@ -102,6 +102,7 @@ hdl/utils/database_tools/__init__.py
102
102
  hdl/utils/database_tools/connect.py
103
103
  hdl/utils/general/__init__.py
104
104
  hdl/utils/general/glob.py
105
+ hdl/utils/llm/chat.py
105
106
  hdl/utils/schedulers/__init__.py
106
107
  hdl/utils/schedulers/norm_lr.py
107
108
  hjxdl.egg-info/PKG-INFO
@@ -0,0 +1 @@
1
+ 0.0.2
hjxdl-0.0.1/version.txt DELETED
@@ -1 +0,0 @@
1
- 0.0.1
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes