dhti-elixir-base 0.1.0__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.
- dhti_elixir_base/__init__.py +27 -0
- dhti_elixir_base/agent.py +202 -0
- dhti_elixir_base/chain.py +178 -0
- dhti_elixir_base/graph.py +165 -0
- dhti_elixir_base/llm.py +79 -0
- dhti_elixir_base/mcp.py +15 -0
- dhti_elixir_base/model.py +47 -0
- dhti_elixir_base/mydi.py +16 -0
- dhti_elixir_base/server.py +56 -0
- dhti_elixir_base/space.py +36 -0
- dhti_elixir_base-0.1.0.dist-info/METADATA +104 -0
- dhti_elixir_base-0.1.0.dist-info/RECORD +15 -0
- dhti_elixir_base-0.1.0.dist-info/WHEEL +4 -0
- dhti_elixir_base-0.1.0.dist-info/licenses/AUTHORS.md +3 -0
- dhti_elixir_base-0.1.0.dist-info/licenses/LICENSE +362 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
|
|
3
|
+
from .agent import BaseAgent
|
|
4
|
+
from .chain import BaseChain
|
|
5
|
+
from .graph import BaseGraph
|
|
6
|
+
from .llm import BaseLLM
|
|
7
|
+
from .model import BaseModel
|
|
8
|
+
from .server import BaseServer
|
|
9
|
+
from .space import BaseSpace
|
|
10
|
+
from .mydi import get_di
|
|
11
|
+
|
|
12
|
+
if sys.version_info[:2] >= (3, 8):
|
|
13
|
+
# TODO: Import directly (no need for conditional) when `python_requires = >= 3.8`
|
|
14
|
+
from importlib.metadata import PackageNotFoundError, version # pragma: no cover
|
|
15
|
+
else:
|
|
16
|
+
from importlib_metadata import PackageNotFoundError, version # pragma: no cover
|
|
17
|
+
|
|
18
|
+
try:
|
|
19
|
+
# Change here if project is renamed and does not equal the package name
|
|
20
|
+
dist_name = __name__
|
|
21
|
+
__version__ = version(dist_name)
|
|
22
|
+
except PackageNotFoundError: # pragma: no cover
|
|
23
|
+
__version__ = "unknown"
|
|
24
|
+
finally:
|
|
25
|
+
del version, PackageNotFoundError
|
|
26
|
+
|
|
27
|
+
__all__ = ["chain"]
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright 2023 Bell Eapen
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import re
|
|
18
|
+
from typing import List, Dict
|
|
19
|
+
|
|
20
|
+
from langchain.agents import AgentType, initialize_agent, AgentExecutor, create_tool_calling_agent
|
|
21
|
+
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
|
22
|
+
from pydantic import BaseModel, Field, ConfigDict
|
|
23
|
+
from langchain_mcp_adapters.client import MultiServerMCPClient
|
|
24
|
+
from langgraph.prebuilt import create_react_agent
|
|
25
|
+
|
|
26
|
+
from .mydi import get_di
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# from langchain_core.prompts import MessagesPlaceholder
|
|
30
|
+
# from langchain.memory.buffer import ConversationBufferMemory
|
|
31
|
+
class BaseAgent:
|
|
32
|
+
|
|
33
|
+
class AgentInput(BaseModel):
|
|
34
|
+
"""Chat history with the bot."""
|
|
35
|
+
input: str
|
|
36
|
+
model_config = ConfigDict(extra="ignore", arbitrary_types_allowed=True)
|
|
37
|
+
|
|
38
|
+
def __init__(
|
|
39
|
+
self,
|
|
40
|
+
name=None,
|
|
41
|
+
description=None,
|
|
42
|
+
llm=None,
|
|
43
|
+
input_type: type[BaseModel] | None = None,
|
|
44
|
+
prefix=None,
|
|
45
|
+
suffix=None,
|
|
46
|
+
tools: List = [],
|
|
47
|
+
mcp = None,
|
|
48
|
+
):
|
|
49
|
+
self.llm = llm or get_di("function_llm")
|
|
50
|
+
self.prefix = prefix or get_di("prefix")
|
|
51
|
+
self.suffix = suffix or get_di("suffix")
|
|
52
|
+
self.tools = tools
|
|
53
|
+
self._name = (
|
|
54
|
+
name or re.sub(r"(?<!^)(?=[A-Z])", "_", self.__class__.__name__).lower()
|
|
55
|
+
)
|
|
56
|
+
self._description = description or f"Agent for {self._name}"
|
|
57
|
+
# current_patient_context = MessagesPlaceholder(variable_name="current_patient_context")
|
|
58
|
+
# memory = ConversationBufferMemory(memory_key="current_patient_context", return_messages=True)
|
|
59
|
+
self.agent_kwargs = {
|
|
60
|
+
"prefix": self.prefix,
|
|
61
|
+
"suffix": self.suffix,
|
|
62
|
+
# "memory_prompts": [current_patient_context],
|
|
63
|
+
"input_variables": ["input", "agent_scratchpad", "current_patient_context"],
|
|
64
|
+
}
|
|
65
|
+
if input_type is None:
|
|
66
|
+
self.input_type = self.AgentInput
|
|
67
|
+
else:
|
|
68
|
+
self.input_type = input_type
|
|
69
|
+
if mcp is not None:
|
|
70
|
+
self.client = MultiServerMCPClient(mcp)
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def name(self):
|
|
74
|
+
return self._name
|
|
75
|
+
|
|
76
|
+
@property
|
|
77
|
+
def description(self):
|
|
78
|
+
return self._description
|
|
79
|
+
|
|
80
|
+
@name.setter
|
|
81
|
+
def name(self, value):
|
|
82
|
+
self._name = value
|
|
83
|
+
|
|
84
|
+
@description.setter
|
|
85
|
+
def description(self, value):
|
|
86
|
+
self._description = value
|
|
87
|
+
|
|
88
|
+
def get_agent(self):
|
|
89
|
+
if self.llm is None:
|
|
90
|
+
raise ValueError("llm must not be None when initializing the agent.")
|
|
91
|
+
return initialize_agent(
|
|
92
|
+
tools=self.tools,
|
|
93
|
+
llm=self.llm,
|
|
94
|
+
agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
|
|
95
|
+
stop=["\nObservation:"],
|
|
96
|
+
max_iterations=len(self.tools) + 3,
|
|
97
|
+
handle_parsing_errors=True,
|
|
98
|
+
agent_kwargs=self.agent_kwargs,
|
|
99
|
+
verbose=True,
|
|
100
|
+
).with_types(
|
|
101
|
+
input_type=self.input_type # type: ignore
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
# ! This is currently supported only for models supporting llm.bind_tools. See function return
|
|
105
|
+
def get_agent_prompt(self):
|
|
106
|
+
prompt = ChatPromptTemplate.from_messages(
|
|
107
|
+
[
|
|
108
|
+
(
|
|
109
|
+
"system",
|
|
110
|
+
"{prefix}"
|
|
111
|
+
" You have access to the following tools: {tool_names}.\n{system_message}",
|
|
112
|
+
),
|
|
113
|
+
MessagesPlaceholder(variable_name="messages"),
|
|
114
|
+
]
|
|
115
|
+
)
|
|
116
|
+
prompt = prompt.partial(prefix=self.prefix)
|
|
117
|
+
prompt = prompt.partial(system_message=self.suffix)
|
|
118
|
+
prompt = prompt.partial(
|
|
119
|
+
tool_names=", ".join([tool.name for tool in self.tools])
|
|
120
|
+
)
|
|
121
|
+
return prompt
|
|
122
|
+
|
|
123
|
+
def get_agent_chat_prompt_with_memory(self):
|
|
124
|
+
prompt = ChatPromptTemplate.from_messages(
|
|
125
|
+
[
|
|
126
|
+
("system", "You are a helpful assistant."),
|
|
127
|
+
# First put the history
|
|
128
|
+
("placeholder", "{chat_history}"),
|
|
129
|
+
# Then the new input
|
|
130
|
+
("human", "{input}"),
|
|
131
|
+
# Finally the scratchpad
|
|
132
|
+
("placeholder", "{agent_scratchpad}"),
|
|
133
|
+
]
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
def langgraph_agent(self):
|
|
137
|
+
"""Create an agent."""
|
|
138
|
+
prompt = self.get_agent_prompt()
|
|
139
|
+
if not hasattr(self.llm, "bind_tools"):
|
|
140
|
+
raise ValueError(
|
|
141
|
+
"The LLM does not support binding tools. Please use a compatible LLM."
|
|
142
|
+
)
|
|
143
|
+
return prompt | self.llm.bind_tools(self.tools) # type: ignore
|
|
144
|
+
|
|
145
|
+
def get_langgraph_agent_executor(self):
|
|
146
|
+
"""Get the agent executor."""
|
|
147
|
+
if self.llm is None:
|
|
148
|
+
raise ValueError("llm must not be None when initializing the agent executor.")
|
|
149
|
+
agent = create_tool_calling_agent(
|
|
150
|
+
llm=self.llm,
|
|
151
|
+
tools=self.tools,
|
|
152
|
+
prompt=self.get_agent_prompt(),
|
|
153
|
+
)
|
|
154
|
+
agent_executor = AgentExecutor(agent=agent, tools=self.tools)
|
|
155
|
+
return agent_executor
|
|
156
|
+
|
|
157
|
+
def get_langgraph_agent_executor_with_memory(self):
|
|
158
|
+
from langchain_core.chat_history import InMemoryChatMessageHistory
|
|
159
|
+
from langchain_core.runnables.history import RunnableWithMessageHistory
|
|
160
|
+
if self.llm is None:
|
|
161
|
+
raise ValueError(
|
|
162
|
+
"llm must not be None when initializing the agent executor."
|
|
163
|
+
)
|
|
164
|
+
memory = InMemoryChatMessageHistory()
|
|
165
|
+
prompt = ChatPromptTemplate.from_messages(
|
|
166
|
+
[
|
|
167
|
+
("system", "You are a helpful assistant."),
|
|
168
|
+
# First put the history
|
|
169
|
+
("placeholder", "{chat_history}"),
|
|
170
|
+
# Then the new input
|
|
171
|
+
("human", "{input}"),
|
|
172
|
+
# Finally the scratchpad
|
|
173
|
+
("placeholder", "{agent_scratchpad}"),
|
|
174
|
+
]
|
|
175
|
+
)
|
|
176
|
+
agent = create_tool_calling_agent(
|
|
177
|
+
llm=self.llm,
|
|
178
|
+
tools=self.tools,
|
|
179
|
+
prompt=prompt,
|
|
180
|
+
)
|
|
181
|
+
agent_executor = AgentExecutor(agent=agent, tools=self.tools)
|
|
182
|
+
return RunnableWithMessageHistory(
|
|
183
|
+
agent_executor, # type: ignore
|
|
184
|
+
# This is needed because in most real world scenarios, a session id is needed
|
|
185
|
+
# It isn't really used here because we are using a simple in memory ChatMessageHistory
|
|
186
|
+
lambda session_id: memory,
|
|
187
|
+
input_messages_key="input",
|
|
188
|
+
history_messages_key="chat_history",
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
async def get_langgraph_mcp_agent(self):
|
|
192
|
+
"""Get the agent executor for async execution."""
|
|
193
|
+
if self.llm is None:
|
|
194
|
+
raise ValueError("llm must not be None when initializing the agent executor.")
|
|
195
|
+
if self.client is None:
|
|
196
|
+
raise ValueError("MCP client must not be None when initializing the agent.")
|
|
197
|
+
tools = await self.client.get_tools()
|
|
198
|
+
agent = create_react_agent(
|
|
199
|
+
model=self.llm,
|
|
200
|
+
tools=tools,
|
|
201
|
+
)
|
|
202
|
+
return agent
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
from kink import inject
|
|
4
|
+
from langchain.schema.output_parser import StrOutputParser
|
|
5
|
+
from langchain.schema.runnable import RunnablePassthrough
|
|
6
|
+
from pydantic import BaseModel, ConfigDict
|
|
7
|
+
|
|
8
|
+
from .mydi import get_di
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@inject
|
|
12
|
+
class BaseChain:
|
|
13
|
+
|
|
14
|
+
class ChainInput(BaseModel):
|
|
15
|
+
question: str
|
|
16
|
+
model_config = ConfigDict(extra="ignore", arbitrary_types_allowed=True)
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
chain=None,
|
|
21
|
+
prompt={},
|
|
22
|
+
name=None,
|
|
23
|
+
description=None,
|
|
24
|
+
main_llm=None,
|
|
25
|
+
clinical_llm=None,
|
|
26
|
+
grounding_llm=None,
|
|
27
|
+
input_type=None,
|
|
28
|
+
output_type=None,
|
|
29
|
+
):
|
|
30
|
+
self._chain = chain
|
|
31
|
+
self._prompt = prompt or get_di("main_prompt")
|
|
32
|
+
self._main_llm = main_llm or get_di("base_main_llm")
|
|
33
|
+
self._clinical_llm = clinical_llm or get_di("base_clinical_llm")
|
|
34
|
+
self._grounding_llm = grounding_llm or get_di("base_grounding_llm")
|
|
35
|
+
self._input_type = input_type or self.ChainInput
|
|
36
|
+
self._output_type = output_type
|
|
37
|
+
self._name = name
|
|
38
|
+
self._description = description
|
|
39
|
+
self.init_prompt()
|
|
40
|
+
|
|
41
|
+
@property
|
|
42
|
+
def chain(self):
|
|
43
|
+
if self._chain is None:
|
|
44
|
+
"""Get the runnable chain."""
|
|
45
|
+
""" RunnableParallel / RunnablePassthrough / RunnableSequential / RunnableLambda / RunnableMap / RunnableBranch """
|
|
46
|
+
if self.prompt is None:
|
|
47
|
+
raise ValueError("Prompt must not be None when building the chain.")
|
|
48
|
+
_sequential = (
|
|
49
|
+
RunnablePassthrough()
|
|
50
|
+
| self.prompt # "{input}""
|
|
51
|
+
| self.main_llm
|
|
52
|
+
| StrOutputParser()
|
|
53
|
+
)
|
|
54
|
+
chain = _sequential.with_types(input_type=self.input_type)
|
|
55
|
+
return chain
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
def prompt(self):
|
|
59
|
+
return self._prompt
|
|
60
|
+
|
|
61
|
+
@property
|
|
62
|
+
def main_llm(self):
|
|
63
|
+
if self._main_llm is None:
|
|
64
|
+
self._main_llm = get_di("base_main_llm")
|
|
65
|
+
return self._main_llm
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def clinical_llm(self):
|
|
69
|
+
if self._clinical_llm is None:
|
|
70
|
+
self._clinical_llm = get_di("base_clinical_llm")
|
|
71
|
+
return self._clinical_llm
|
|
72
|
+
|
|
73
|
+
@property
|
|
74
|
+
def grounding_llm(self):
|
|
75
|
+
if self._grounding_llm is None:
|
|
76
|
+
self._grounding_llm = get_di("base_grounding_llm")
|
|
77
|
+
return self._grounding_llm
|
|
78
|
+
|
|
79
|
+
@property
|
|
80
|
+
def input_type(self):
|
|
81
|
+
if self._input_type is None:
|
|
82
|
+
self._input_type = self.ChainInput
|
|
83
|
+
return self._input_type
|
|
84
|
+
|
|
85
|
+
@property
|
|
86
|
+
def output_type(self):
|
|
87
|
+
return self._output_type
|
|
88
|
+
|
|
89
|
+
@property
|
|
90
|
+
def name(self):
|
|
91
|
+
if self._name is None:
|
|
92
|
+
return re.sub(r"(?<!^)(?=[A-Z])", "_", self.__class__.__name__).lower()
|
|
93
|
+
|
|
94
|
+
@property
|
|
95
|
+
def description(self):
|
|
96
|
+
if self._description is None:
|
|
97
|
+
self._description = f"Chain for {self.name}"
|
|
98
|
+
return self._description
|
|
99
|
+
|
|
100
|
+
@chain.setter
|
|
101
|
+
def chain(self, value):
|
|
102
|
+
self._chain = value
|
|
103
|
+
|
|
104
|
+
@prompt.setter
|
|
105
|
+
def prompt(self, value):
|
|
106
|
+
self._prompt = value
|
|
107
|
+
self.init_prompt()
|
|
108
|
+
|
|
109
|
+
@main_llm.setter
|
|
110
|
+
def main_llm(self, value):
|
|
111
|
+
self._main_llm = value
|
|
112
|
+
|
|
113
|
+
@clinical_llm.setter
|
|
114
|
+
def clinical_llm(self, value):
|
|
115
|
+
self._clinical_llm = value
|
|
116
|
+
|
|
117
|
+
@grounding_llm.setter
|
|
118
|
+
def grounding_llm(self, value):
|
|
119
|
+
self._grounding_llm = value
|
|
120
|
+
|
|
121
|
+
@input_type.setter
|
|
122
|
+
def input_type(self, value):
|
|
123
|
+
self._input_type = value
|
|
124
|
+
|
|
125
|
+
@output_type.setter
|
|
126
|
+
def output_type(self, value):
|
|
127
|
+
self._output_type = value
|
|
128
|
+
|
|
129
|
+
@name.setter
|
|
130
|
+
def name(self, value):
|
|
131
|
+
self._name = value
|
|
132
|
+
|
|
133
|
+
@description.setter
|
|
134
|
+
def description(self, value):
|
|
135
|
+
self._description = value
|
|
136
|
+
|
|
137
|
+
def invoke(self, **kwargs):
|
|
138
|
+
if self.chain is None:
|
|
139
|
+
raise ValueError("Chain is not initialized.")
|
|
140
|
+
return self.chain.invoke(kwargs)
|
|
141
|
+
|
|
142
|
+
def __call__(self, **kwargs):
|
|
143
|
+
return self.invoke(**kwargs)
|
|
144
|
+
|
|
145
|
+
@DeprecationWarning
|
|
146
|
+
def get_runnable(self, **kwargs):
|
|
147
|
+
return self.chain
|
|
148
|
+
|
|
149
|
+
# * Override these methods in subclasses
|
|
150
|
+
def init_prompt(self):
|
|
151
|
+
pass
|
|
152
|
+
|
|
153
|
+
def generate_llm_config(self):
|
|
154
|
+
_input_schema = self.input_type.schema()
|
|
155
|
+
function_schema = {
|
|
156
|
+
"name": (self.name or self.__class__.__name__).lower().replace(" ", "_"),
|
|
157
|
+
"description": self.description,
|
|
158
|
+
"parameters": {
|
|
159
|
+
"type": _input_schema["type"],
|
|
160
|
+
"properties": _input_schema["properties"],
|
|
161
|
+
"required": _input_schema["required"],
|
|
162
|
+
},
|
|
163
|
+
}
|
|
164
|
+
return function_schema
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
# # Named chain according to the langchain template convention
|
|
168
|
+
# # The description is used by the agents
|
|
169
|
+
#! This is only in the inherited class, not in the base class here.
|
|
170
|
+
# @tool(BaseChain().name or "test_chain", args_schema=BaseChain().input_type)
|
|
171
|
+
# def chain(**kwargs):
|
|
172
|
+
# """
|
|
173
|
+
# This is a template chain that takes a text input and returns a summary of the text.
|
|
174
|
+
|
|
175
|
+
# The input is a dict with the following mandatory keys:
|
|
176
|
+
# input (str): The text to summarize.
|
|
177
|
+
# """
|
|
178
|
+
# return BaseChain().chain.invoke(kwargs)
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright 2024 Bell Eapen
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import functools
|
|
18
|
+
import operator
|
|
19
|
+
import re
|
|
20
|
+
from typing import Annotated, Literal, Sequence, TypedDict
|
|
21
|
+
from kink import inject, di
|
|
22
|
+
from langchain_core.messages import AIMessage, BaseMessage, HumanMessage, ToolMessage
|
|
23
|
+
from langgraph.graph import END, StateGraph
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
"""_summary_
|
|
27
|
+
|
|
28
|
+
Helper class to add multi-agent support with langgraph.
|
|
29
|
+
The agents can be BaseAgent derived classes and support VertexAI.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@inject
|
|
34
|
+
class BaseGraph:
|
|
35
|
+
# Ref 1: https://github.com/langchain-ai/langgraph/blob/main/examples/multi_agent/multi-agent-collaboration.ipynb
|
|
36
|
+
# Ref 2: https://medium.com/@cplog/introduction-to-langgraph-a-beginners-guide-14f9be027141
|
|
37
|
+
# * call_tools = tool_node [ToolNode is currently not supported by VertexAI because of the lack of llm.bind_tools()]
|
|
38
|
+
# ! Tools are handled by the respective agents
|
|
39
|
+
class AgentState(TypedDict):
|
|
40
|
+
messages: Annotated[Sequence[BaseMessage], operator.add]
|
|
41
|
+
sender: str
|
|
42
|
+
|
|
43
|
+
def __init__(
|
|
44
|
+
self,
|
|
45
|
+
agents=[], # required
|
|
46
|
+
edges=[], # [{"from": "agent1", "to": "agent2", "conditional": True, "router": "default"}, {"from": "agent2", "to": "agent1", "conditional": True, "router": "default"}] #required
|
|
47
|
+
entry_point="", # required agent_1
|
|
48
|
+
ends=[], # optional
|
|
49
|
+
end_words=[], # optional ["exit", "quit", "bye", "sorry", "final"] The words that will trigger the end of the conversation
|
|
50
|
+
agent_state=None, # optional default AgentState above
|
|
51
|
+
nodes=None, # optional, generated
|
|
52
|
+
workflow=None, # optional, generated
|
|
53
|
+
name=None, # optional, generated
|
|
54
|
+
recursion_limit=15, # optional, default
|
|
55
|
+
):
|
|
56
|
+
self.agents = agents
|
|
57
|
+
self.edges = edges
|
|
58
|
+
self.end_words = end_words
|
|
59
|
+
self.nodes = nodes
|
|
60
|
+
self.workflow = workflow
|
|
61
|
+
self.entry_point = entry_point
|
|
62
|
+
self.agent_state = agent_state or self.AgentState
|
|
63
|
+
self.ends = ends
|
|
64
|
+
self.recursion_limit = recursion_limit
|
|
65
|
+
self._name = name
|
|
66
|
+
|
|
67
|
+
def init_graph(self):
|
|
68
|
+
# We create a workflow that will be used to manage the state of the agents
|
|
69
|
+
if self.workflow is None:
|
|
70
|
+
self.workflow = StateGraph(self.agent_state)
|
|
71
|
+
# We create the nodes for each agent
|
|
72
|
+
if self.nodes is None:
|
|
73
|
+
self.nodes = []
|
|
74
|
+
for agent in self.agents:
|
|
75
|
+
self.nodes.append(self.agent_node(agent))
|
|
76
|
+
# We add the nodes to the workflow
|
|
77
|
+
for node, agent in zip(self.nodes, self.agents):
|
|
78
|
+
self.workflow.add_node(agent.name, node)
|
|
79
|
+
# We set the entry point of the workflow
|
|
80
|
+
self.workflow.set_entry_point(self.entry_point)
|
|
81
|
+
# We set the end points of the workflow
|
|
82
|
+
for end in self.ends:
|
|
83
|
+
self.workflow.add_edge(end, END)
|
|
84
|
+
# Add edges
|
|
85
|
+
for edge in self.edges:
|
|
86
|
+
if edge["conditional"]:
|
|
87
|
+
if edge["router"] == "default":
|
|
88
|
+
_router = self.router
|
|
89
|
+
else:
|
|
90
|
+
_router = di[
|
|
91
|
+
edge["router"]
|
|
92
|
+
] # This is a dependency injection of router if needed
|
|
93
|
+
self.workflow.add_conditional_edges(
|
|
94
|
+
edge["from"],
|
|
95
|
+
_router,
|
|
96
|
+
{"continue": edge["to"], "__end__": END},
|
|
97
|
+
)
|
|
98
|
+
else:
|
|
99
|
+
self.workflow.add_edge(edge["from"], edge["to"])
|
|
100
|
+
self.graph = self.workflow.compile()
|
|
101
|
+
|
|
102
|
+
@property
|
|
103
|
+
def name(self):
|
|
104
|
+
if self._name:
|
|
105
|
+
return self._name
|
|
106
|
+
return re.sub(r"(?<!^)(?=[A-Z])", "_", self.__class__.__name__).lower()
|
|
107
|
+
|
|
108
|
+
@name.setter
|
|
109
|
+
def name(self, value):
|
|
110
|
+
self._name = value
|
|
111
|
+
|
|
112
|
+
# Helper function to create a node for a given agent
|
|
113
|
+
@staticmethod
|
|
114
|
+
def create_agent_node(state, agent):
|
|
115
|
+
_result = None
|
|
116
|
+
try:
|
|
117
|
+
result = agent.invoke(state)
|
|
118
|
+
except ValueError as e:
|
|
119
|
+
_result = agent.invoke({"input": state})
|
|
120
|
+
result = _result["input"]["messages"][0]
|
|
121
|
+
|
|
122
|
+
if _result is not None and "output" in _result:
|
|
123
|
+
result = ToolMessage(content=_result["output"], tool_call_id="myTool")
|
|
124
|
+
# We convert the agent output into a format that is suitable to append to the global state
|
|
125
|
+
if isinstance(result, ToolMessage):
|
|
126
|
+
pass
|
|
127
|
+
else:
|
|
128
|
+
try:
|
|
129
|
+
result = AIMessage(
|
|
130
|
+
**result.dict(exclude={"type", "name"}), name=agent.name
|
|
131
|
+
)
|
|
132
|
+
except Exception as e:
|
|
133
|
+
result = AIMessage(content=result.content, name=agent.name)
|
|
134
|
+
return {
|
|
135
|
+
"messages": [result], # Yes, this should be an array!
|
|
136
|
+
"sender": agent.name,
|
|
137
|
+
# * Return other state variables if any
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
def agent_node(self, agent):
|
|
141
|
+
return functools.partial(self.create_agent_node, agent=agent)
|
|
142
|
+
|
|
143
|
+
def router(self, state) -> Literal["__end__", "continue"]:
|
|
144
|
+
# This is the default router
|
|
145
|
+
messages = state["messages"]
|
|
146
|
+
last_message = messages[-1]
|
|
147
|
+
if any(
|
|
148
|
+
[exit.lower() in last_message.content.lower() for exit in self.end_words]
|
|
149
|
+
):
|
|
150
|
+
return "__end__"
|
|
151
|
+
return "continue"
|
|
152
|
+
|
|
153
|
+
def invoke(self, message):
|
|
154
|
+
events = self.graph.stream(
|
|
155
|
+
{
|
|
156
|
+
"messages": [
|
|
157
|
+
HumanMessage(
|
|
158
|
+
content=message,
|
|
159
|
+
)
|
|
160
|
+
],
|
|
161
|
+
},
|
|
162
|
+
# Maximum number of steps to take in the graph
|
|
163
|
+
{"recursion_limit": self.recursion_limit},
|
|
164
|
+
)
|
|
165
|
+
return events
|
dhti_elixir_base/llm.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
from typing import Any, List, Mapping, Optional
|
|
3
|
+
|
|
4
|
+
from langchain.llms.base import LLM
|
|
5
|
+
from pydantic import Field
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class BaseLLM(LLM):
|
|
9
|
+
|
|
10
|
+
hosted_url: Optional[str] = Field(
|
|
11
|
+
None, alias="hosted_url"
|
|
12
|
+
) #! Alias is important when inheriting from LLM
|
|
13
|
+
model_name: Optional[str] = Field(None, alias="model_name")
|
|
14
|
+
params: Mapping[str, Any] = Field(default_factory=dict, alias="params")
|
|
15
|
+
|
|
16
|
+
backend: Optional[str] = "dhti"
|
|
17
|
+
temperature: Optional[float] = 0.1
|
|
18
|
+
top_p: Optional[float] = 0.8
|
|
19
|
+
top_k: Optional[int] = 40
|
|
20
|
+
n_batch: Optional[int] = 8
|
|
21
|
+
n_threads: Optional[int] = 4
|
|
22
|
+
n_predict: Optional[int] = 256
|
|
23
|
+
max_output_tokens: Optional[int] = 512
|
|
24
|
+
repeat_last_n: Optional[int] = 64
|
|
25
|
+
repeat_penalty: Optional[float] = 1.18
|
|
26
|
+
|
|
27
|
+
def __init__(self, hosted_url: str, model_name: str, **kwargs):
|
|
28
|
+
super().__init__(**kwargs)
|
|
29
|
+
self.hosted_url = hosted_url
|
|
30
|
+
self.model_name = model_name
|
|
31
|
+
self.params = {**self._get_model_default_parameters, **kwargs}
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def _get_model_default_parameters(self):
|
|
35
|
+
return {
|
|
36
|
+
"max_output_tokens": self.max_output_tokens,
|
|
37
|
+
"n_predict": self.n_predict,
|
|
38
|
+
"top_k": self.top_k,
|
|
39
|
+
"top_p": self.top_p,
|
|
40
|
+
"temperature": self.temperature,
|
|
41
|
+
"n_batch": self.n_batch,
|
|
42
|
+
"repeat_penalty": self.repeat_penalty,
|
|
43
|
+
"repeat_last_n": self.repeat_last_n,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def _identifying_params(self) -> Mapping[str, Any]:
|
|
48
|
+
"""
|
|
49
|
+
Get all the identifying parameters
|
|
50
|
+
"""
|
|
51
|
+
return {
|
|
52
|
+
"model_name": self.model_name,
|
|
53
|
+
"hosted_url": self.hosted_url,
|
|
54
|
+
"model_parameters": self._get_model_default_parameters,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
def _llm_type(self) -> str:
|
|
59
|
+
return "dhti"
|
|
60
|
+
|
|
61
|
+
@abstractmethod
|
|
62
|
+
def _call(
|
|
63
|
+
self,
|
|
64
|
+
prompt: str,
|
|
65
|
+
stop: Optional[List[str]] = None,
|
|
66
|
+
run_manager: Optional[Any] = None,
|
|
67
|
+
**kwargs
|
|
68
|
+
) -> str:
|
|
69
|
+
"""
|
|
70
|
+
Args:
|
|
71
|
+
prompt: The prompt to pass into the model.
|
|
72
|
+
stop: A list of strings to stop generation when encountered
|
|
73
|
+
run_manager: Optional run manager for callbacks and tracing
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
The string generated by the model
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
pass
|
dhti_elixir_base/mcp.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from mcp.server.fastmcp import FastMCP
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class BaseMCPServer(FastMCP):
|
|
5
|
+
"""Base class for MCP servers, extending FastMCP for custom functionality."""
|
|
6
|
+
|
|
7
|
+
def __init__(self, name: str | None = None):
|
|
8
|
+
self._name = name or "BaseMCPServer"
|
|
9
|
+
super().__init__(name=self._name)
|
|
10
|
+
|
|
11
|
+
@property
|
|
12
|
+
def name(self):
|
|
13
|
+
"""Return the name of this MCP server instance."""
|
|
14
|
+
return self._name
|
|
15
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import logging
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from typing import Any
|
|
5
|
+
from time import perf_counter
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# Set up logger
|
|
9
|
+
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
|
|
10
|
+
log = logging.getLogger(__name__)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class BaseModel(ABC):
|
|
14
|
+
"""A model class to lead the model and tokenizer"""
|
|
15
|
+
|
|
16
|
+
model: Any = None
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
model: Any,
|
|
21
|
+
) -> None:
|
|
22
|
+
self.model = model
|
|
23
|
+
|
|
24
|
+
@classmethod
|
|
25
|
+
@abstractmethod
|
|
26
|
+
def load(cls) -> None:
|
|
27
|
+
if cls.model is None:
|
|
28
|
+
log.info("Loading model")
|
|
29
|
+
t0 = perf_counter()
|
|
30
|
+
# Load the model here
|
|
31
|
+
elapsed = 1000 * (perf_counter() - t0)
|
|
32
|
+
log.info("Model warm-up time: %d ms.", elapsed)
|
|
33
|
+
else:
|
|
34
|
+
log.info("Model is already loaded")
|
|
35
|
+
|
|
36
|
+
@classmethod
|
|
37
|
+
@abstractmethod
|
|
38
|
+
def predict(cls, input: Any, **kwargs) -> Any:
|
|
39
|
+
assert input is not None and cls.model is not None # Sanity check
|
|
40
|
+
|
|
41
|
+
# Make sure the model is loaded.
|
|
42
|
+
cls.load()
|
|
43
|
+
t0 = perf_counter()
|
|
44
|
+
# Predict here
|
|
45
|
+
elapsed = 1000 * (perf_counter() - t0)
|
|
46
|
+
log.info("Model prediction time: %d ms.", elapsed)
|
|
47
|
+
return None
|
dhti_elixir_base/mydi.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from kink import di
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def get_di(mydi: str, default=None):
|
|
5
|
+
try:
|
|
6
|
+
_module = mydi.split("_", 1)[0]
|
|
7
|
+
_mydi = mydi.split("_", 1)[1]
|
|
8
|
+
except IndexError:
|
|
9
|
+
return di[mydi]
|
|
10
|
+
try:
|
|
11
|
+
return di[_module + "_" + _mydi]
|
|
12
|
+
except KeyError:
|
|
13
|
+
try:
|
|
14
|
+
return di[_mydi]
|
|
15
|
+
except KeyError:
|
|
16
|
+
return default
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import re
|
|
3
|
+
import sys
|
|
4
|
+
from abc import ABC
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from pydantic import BaseModel, Field
|
|
8
|
+
|
|
9
|
+
from . import BaseModel
|
|
10
|
+
|
|
11
|
+
# Set up logger
|
|
12
|
+
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
|
|
13
|
+
log = logging.getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class BaseServer(ABC):
|
|
17
|
+
"""A server class to load the model and tokenizer"""
|
|
18
|
+
|
|
19
|
+
class RequestSchema(BaseModel):
|
|
20
|
+
text: str = Field()
|
|
21
|
+
labels: list = Field()
|
|
22
|
+
required: list = Field()
|
|
23
|
+
|
|
24
|
+
class ResponseSchema(BaseModel):
|
|
25
|
+
text: str = Field()
|
|
26
|
+
|
|
27
|
+
request_schema = RequestSchema
|
|
28
|
+
response_schema = ResponseSchema
|
|
29
|
+
|
|
30
|
+
def __init__(
|
|
31
|
+
self, model: BaseModel, request_schema: Any = None, response_schema: Any = None
|
|
32
|
+
) -> None:
|
|
33
|
+
self.model = model
|
|
34
|
+
if request_schema is not None:
|
|
35
|
+
self.request_schema = request_schema
|
|
36
|
+
if response_schema is not None:
|
|
37
|
+
self.response_schema = response_schema
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def name(self):
|
|
41
|
+
return re.sub(r"(?<!^)(?=[A-Z])", "_", self.__class__.__name__).lower()
|
|
42
|
+
|
|
43
|
+
def health_check(self) -> Any:
|
|
44
|
+
"""Health check endpoint"""
|
|
45
|
+
self.model.load()
|
|
46
|
+
return {"status": "ok"}
|
|
47
|
+
|
|
48
|
+
def get_schema(self) -> Any:
|
|
49
|
+
"""Get the request schema"""
|
|
50
|
+
return self.request_schema
|
|
51
|
+
|
|
52
|
+
def predict(self, input: Any, **kwargs) -> Any:
|
|
53
|
+
_input = self.request_schema(**input) # type: ignore
|
|
54
|
+
_result = self.model.predict(_input, **kwargs)
|
|
55
|
+
result = self.response_schema(**_result) # type: ignore
|
|
56
|
+
return result
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from agency.agent import Agent, action
|
|
2
|
+
|
|
3
|
+
from . import BaseAgent
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class BaseSpace(Agent):
|
|
7
|
+
|
|
8
|
+
from typing import Optional
|
|
9
|
+
|
|
10
|
+
def __init__(self, agent: Optional[BaseAgent] = None, *args, **kwargs):
|
|
11
|
+
if agent:
|
|
12
|
+
self.agent = agent.get_agent()
|
|
13
|
+
super().__init__(id=agent.name, *args, **kwargs)
|
|
14
|
+
|
|
15
|
+
@action
|
|
16
|
+
def say(self, content: str, current_patient_context: str = ""):
|
|
17
|
+
"""Search for a patient in the FHIR database."""
|
|
18
|
+
#! TODO: Needs bootstrapping here.
|
|
19
|
+
|
|
20
|
+
message = {
|
|
21
|
+
"input": content,
|
|
22
|
+
"current_patient_context": current_patient_context,
|
|
23
|
+
}
|
|
24
|
+
response_content = self.agent.invoke(message)
|
|
25
|
+
self.send(
|
|
26
|
+
{
|
|
27
|
+
"to": self.current_message()["from"], # type: ignore
|
|
28
|
+
"action": {
|
|
29
|
+
"name": "say",
|
|
30
|
+
"args": {
|
|
31
|
+
"content": response_content["output"],
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
)
|
|
36
|
+
return True
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dhti-elixir-base
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: DHTI Elixir Base
|
|
5
|
+
Project-URL: Documentation, https://github.com/dermatologist/dhti
|
|
6
|
+
Project-URL: Homepage, https://nuchange.ca
|
|
7
|
+
Project-URL: Repository, https://github.com/dermatologist/dhti-elixir-base
|
|
8
|
+
Author-email: Bell Eapen <github_public@gulfdoctor.net>
|
|
9
|
+
License-Expression: MPL-2.0
|
|
10
|
+
License-File: AUTHORS.md
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: Gen AI,dhti,python
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Healthcare Industry
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Requires-Python: <4.0,>=3.10
|
|
26
|
+
Requires-Dist: agency
|
|
27
|
+
Requires-Dist: fhiry
|
|
28
|
+
Requires-Dist: httpx
|
|
29
|
+
Requires-Dist: kink
|
|
30
|
+
Requires-Dist: langchain-community
|
|
31
|
+
Requires-Dist: langchain-core
|
|
32
|
+
Requires-Dist: langchain-mcp-adapters
|
|
33
|
+
Requires-Dist: langgraph
|
|
34
|
+
Requires-Dist: mcp
|
|
35
|
+
Requires-Dist: overrides
|
|
36
|
+
Requires-Dist: pytest
|
|
37
|
+
Requires-Dist: python-dotenv
|
|
38
|
+
Provides-Extra: testing
|
|
39
|
+
Requires-Dist: pytest; extra == 'testing'
|
|
40
|
+
Requires-Dist: pytest-cov; extra == 'testing'
|
|
41
|
+
Description-Content-Type: text/markdown
|
|
42
|
+
|
|
43
|
+
# dhti-elixir-base
|
|
44
|
+
|
|
45
|
+
* [DHTI](https://github.com/dermatologist/dhti) Elixir Template
|
|
46
|
+
* WIP
|
|
47
|
+
|
|
48
|
+
## Using the template
|
|
49
|
+
* Use the template to create a new repository on GitHub with the default branch set to develop
|
|
50
|
+
* Clone the repository to your local machine
|
|
51
|
+
* rename `elixir-template` to your elixir-packagename
|
|
52
|
+
* rename `elixir_template` to your elixir_packagename
|
|
53
|
+
* rename the directory `dhti_elixir_base` to your dhti_elixir_packagename
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
* poetry install
|
|
57
|
+
* poetry install dhti-elixir-packagename --extras docs
|
|
58
|
+
|
|
59
|
+
## Environment Setup
|
|
60
|
+
|
|
61
|
+
Override [`dhti_elixir_base/bootstrap.py`](dhti_elixir_base/bootstrap.py) with your own configuration.
|
|
62
|
+
|
|
63
|
+
## Usage
|
|
64
|
+
|
|
65
|
+
To use this package, you should first have the LangChain CLI installed:
|
|
66
|
+
|
|
67
|
+
```shell
|
|
68
|
+
pip install -U langchain-cli
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
If you want to add this to an existing project, you can just run:
|
|
72
|
+
|
|
73
|
+
```shell
|
|
74
|
+
langchain app add --repo https://github.com/dermatologist/dhti-elixir-base --branch develop
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
And add the following code to your `server.py` file:
|
|
78
|
+
```python
|
|
79
|
+
from dhti_elixir_base.bootstrap import bootstrap
|
|
80
|
+
bootstrap()
|
|
81
|
+
from dhti_elixir_base.chain import chain as dhti_elixir_base_chain
|
|
82
|
+
|
|
83
|
+
add_routes(app, dhti_elixir_base_chain, path="/dhti-elixir-base")
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
If you are inside this directory, then you can spin up a LangServe instance directly by:
|
|
87
|
+
|
|
88
|
+
```shell
|
|
89
|
+
langchain serve
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
This will start the FastAPI app with a server is running locally at
|
|
93
|
+
[http://localhost:8000](http://localhost:8000)
|
|
94
|
+
|
|
95
|
+
We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs)
|
|
96
|
+
We can access the playground at [http://127.0.0.1:8000/dhti-elixir-base/playground](http://127.0.0.1:8000/dhti-elixir-base/playground)
|
|
97
|
+
|
|
98
|
+
We can access the template from code with:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from langserve.client import RemoteRunnable
|
|
102
|
+
|
|
103
|
+
runnable = RemoteRunnable("http://localhost:8000/dhti-elixir-base")
|
|
104
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
dhti_elixir_base/__init__.py,sha256=pVXd9FJLbqlqr3bEbiXoVOoQd9NAu-ZWEl3Gc4IyvHo,825
|
|
2
|
+
dhti_elixir_base/agent.py,sha256=71lyRCidYLEEInFzjxXIP4Qpqq-LDjEDvin-F-IoVgM,7377
|
|
3
|
+
dhti_elixir_base/chain.py,sha256=llMpJcGnDAVH6gPzUV3IsOSboE5gGlqOX3mnbkC4rjY,5145
|
|
4
|
+
dhti_elixir_base/graph.py,sha256=XLCzsDhXW7FC3QlkuJjSyvfOWykjO81eiKfbgagdWAo,6171
|
|
5
|
+
dhti_elixir_base/llm.py,sha256=HwTrXwsjOJTNNLNUw6uukhjqYfvgYsmREdVqPRBW55A,2366
|
|
6
|
+
dhti_elixir_base/mcp.py,sha256=vRzYHLa9ULL1TbTWqGB05O3GwCSFnyChozxn0TbLakc,411
|
|
7
|
+
dhti_elixir_base/model.py,sha256=HCWw755iAgHd1bOZ9BtpX2u574Vc1pmK4PZHDVgZUk8,1198
|
|
8
|
+
dhti_elixir_base/mydi.py,sha256=bJBWmW94ynra_dp8aApOA-gKFmyjHcbZ7iWdrZFHtsI,358
|
|
9
|
+
dhti_elixir_base/server.py,sha256=AjRYe2e8e4SzGJjMIxAcbOgNNkoCzf2-o8C_e5yVvPQ,1539
|
|
10
|
+
dhti_elixir_base/space.py,sha256=3BKB-5N9IVZNsPmoaqythxDPr9zui0F6ntmCqn8u_K0,1026
|
|
11
|
+
dhti_elixir_base-0.1.0.dist-info/METADATA,sha256=QzZ9RvGL57YPQxM0PIv7KYV4Ad3GX4oY0CJG6bxpnbQ,3420
|
|
12
|
+
dhti_elixir_base-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
13
|
+
dhti_elixir_base-0.1.0.dist-info/licenses/AUTHORS.md,sha256=cTqmVu4I7k4HyaZkdJgV2LQVppFPlRDC_w9iQi40P_I,86
|
|
14
|
+
dhti_elixir_base-0.1.0.dist-info/licenses/LICENSE,sha256=09btKnCai4LASlVvyTZUp9T0DVNyTY_awOppr_cIfB4,15922
|
|
15
|
+
dhti_elixir_base-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
Mozilla Public License, version 2.0
|
|
2
|
+
|
|
3
|
+
1. Definitions
|
|
4
|
+
|
|
5
|
+
1.1. "Contributor"
|
|
6
|
+
|
|
7
|
+
means each individual or legal entity that creates, contributes to the
|
|
8
|
+
creation of, or owns Covered Software.
|
|
9
|
+
|
|
10
|
+
1.2. "Contributor Version"
|
|
11
|
+
|
|
12
|
+
means the combination of the Contributions of others (if any) used by a
|
|
13
|
+
Contributor and that particular Contributor's Contribution.
|
|
14
|
+
|
|
15
|
+
1.3. "Contribution"
|
|
16
|
+
|
|
17
|
+
means Covered Software of a particular Contributor.
|
|
18
|
+
|
|
19
|
+
1.4. "Covered Software"
|
|
20
|
+
|
|
21
|
+
means Source Code Form to which the initial Contributor has attached the
|
|
22
|
+
notice in Exhibit A, the Executable Form of such Source Code Form, and
|
|
23
|
+
Modifications of such Source Code Form, in each case including portions
|
|
24
|
+
thereof.
|
|
25
|
+
|
|
26
|
+
1.5. "Incompatible With Secondary Licenses"
|
|
27
|
+
means
|
|
28
|
+
|
|
29
|
+
a. that the initial Contributor has attached the notice described in
|
|
30
|
+
Exhibit B to the Covered Software; or
|
|
31
|
+
|
|
32
|
+
b. that the Covered Software was made available under the terms of
|
|
33
|
+
version 1.1 or earlier of the License, but not also under the terms of
|
|
34
|
+
a Secondary License.
|
|
35
|
+
|
|
36
|
+
1.6. "Executable Form"
|
|
37
|
+
|
|
38
|
+
means any form of the work other than Source Code Form.
|
|
39
|
+
|
|
40
|
+
1.7. "Larger Work"
|
|
41
|
+
|
|
42
|
+
means a work that combines Covered Software with other material, in a
|
|
43
|
+
separate file or files, that is not Covered Software.
|
|
44
|
+
|
|
45
|
+
1.8. "License"
|
|
46
|
+
|
|
47
|
+
means this document.
|
|
48
|
+
|
|
49
|
+
1.9. "Licensable"
|
|
50
|
+
|
|
51
|
+
means having the right to grant, to the maximum extent possible, whether
|
|
52
|
+
at the time of the initial grant or subsequently, any and all of the
|
|
53
|
+
rights conveyed by this License.
|
|
54
|
+
|
|
55
|
+
1.10. "Modifications"
|
|
56
|
+
|
|
57
|
+
means any of the following:
|
|
58
|
+
|
|
59
|
+
a. any file in Source Code Form that results from an addition to,
|
|
60
|
+
deletion from, or modification of the contents of Covered Software; or
|
|
61
|
+
|
|
62
|
+
b. any new file in Source Code Form that contains any Covered Software.
|
|
63
|
+
|
|
64
|
+
1.11. "Patent Claims" of a Contributor
|
|
65
|
+
|
|
66
|
+
means any patent claim(s), including without limitation, method,
|
|
67
|
+
process, and apparatus claims, in any patent Licensable by such
|
|
68
|
+
Contributor that would be infringed, but for the grant of the License,
|
|
69
|
+
by the making, using, selling, offering for sale, having made, import,
|
|
70
|
+
or transfer of either its Contributions or its Contributor Version.
|
|
71
|
+
|
|
72
|
+
1.12. "Secondary License"
|
|
73
|
+
|
|
74
|
+
means either the GNU General Public License, Version 2.0, the GNU Lesser
|
|
75
|
+
General Public License, Version 2.1, the GNU Affero General Public
|
|
76
|
+
License, Version 3.0, or any later versions of those licenses.
|
|
77
|
+
|
|
78
|
+
1.13. "Source Code Form"
|
|
79
|
+
|
|
80
|
+
means the form of the work preferred for making modifications.
|
|
81
|
+
|
|
82
|
+
1.14. "You" (or "Your")
|
|
83
|
+
|
|
84
|
+
means an individual or a legal entity exercising rights under this
|
|
85
|
+
License. For legal entities, "You" includes any entity that controls, is
|
|
86
|
+
controlled by, or is under common control with You. For purposes of this
|
|
87
|
+
definition, "control" means (a) the power, direct or indirect, to cause
|
|
88
|
+
the direction or management of such entity, whether by contract or
|
|
89
|
+
otherwise, or (b) ownership of more than fifty percent (50%) of the
|
|
90
|
+
outstanding shares or beneficial ownership of such entity.
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
2. License Grants and Conditions
|
|
94
|
+
|
|
95
|
+
2.1. Grants
|
|
96
|
+
|
|
97
|
+
Each Contributor hereby grants You a world-wide, royalty-free,
|
|
98
|
+
non-exclusive license:
|
|
99
|
+
|
|
100
|
+
a. under intellectual property rights (other than patent or trademark)
|
|
101
|
+
Licensable by such Contributor to use, reproduce, make available,
|
|
102
|
+
modify, display, perform, distribute, and otherwise exploit its
|
|
103
|
+
Contributions, either on an unmodified basis, with Modifications, or
|
|
104
|
+
as part of a Larger Work; and
|
|
105
|
+
|
|
106
|
+
b. under Patent Claims of such Contributor to make, use, sell, offer for
|
|
107
|
+
sale, have made, import, and otherwise transfer either its
|
|
108
|
+
Contributions or its Contributor Version.
|
|
109
|
+
|
|
110
|
+
2.2. Effective Date
|
|
111
|
+
|
|
112
|
+
The licenses granted in Section 2.1 with respect to any Contribution
|
|
113
|
+
become effective for each Contribution on the date the Contributor first
|
|
114
|
+
distributes such Contribution.
|
|
115
|
+
|
|
116
|
+
2.3. Limitations on Grant Scope
|
|
117
|
+
|
|
118
|
+
The licenses granted in this Section 2 are the only rights granted under
|
|
119
|
+
this License. No additional rights or licenses will be implied from the
|
|
120
|
+
distribution or licensing of Covered Software under this License.
|
|
121
|
+
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
|
122
|
+
Contributor:
|
|
123
|
+
|
|
124
|
+
a. for any code that a Contributor has removed from Covered Software; or
|
|
125
|
+
|
|
126
|
+
b. for infringements caused by: (i) Your and any other third party's
|
|
127
|
+
modifications of Covered Software, or (ii) the combination of its
|
|
128
|
+
Contributions with other software (except as part of its Contributor
|
|
129
|
+
Version); or
|
|
130
|
+
|
|
131
|
+
c. under Patent Claims infringed by Covered Software in the absence of
|
|
132
|
+
its Contributions.
|
|
133
|
+
|
|
134
|
+
This License does not grant any rights in the trademarks, service marks,
|
|
135
|
+
or logos of any Contributor (except as may be necessary to comply with
|
|
136
|
+
the notice requirements in Section 3.4).
|
|
137
|
+
|
|
138
|
+
2.4. Subsequent Licenses
|
|
139
|
+
|
|
140
|
+
No Contributor makes additional grants as a result of Your choice to
|
|
141
|
+
distribute the Covered Software under a subsequent version of this
|
|
142
|
+
License (see Section 10.2) or under the terms of a Secondary License (if
|
|
143
|
+
permitted under the terms of Section 3.3).
|
|
144
|
+
|
|
145
|
+
2.5. Representation
|
|
146
|
+
|
|
147
|
+
Each Contributor represents that the Contributor believes its
|
|
148
|
+
Contributions are its original creation(s) or it has sufficient rights to
|
|
149
|
+
grant the rights to its Contributions conveyed by this License.
|
|
150
|
+
|
|
151
|
+
2.6. Fair Use
|
|
152
|
+
|
|
153
|
+
This License is not intended to limit any rights You have under
|
|
154
|
+
applicable copyright doctrines of fair use, fair dealing, or other
|
|
155
|
+
equivalents.
|
|
156
|
+
|
|
157
|
+
2.7. Conditions
|
|
158
|
+
|
|
159
|
+
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
|
|
160
|
+
Section 2.1.
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
3. Responsibilities
|
|
164
|
+
|
|
165
|
+
3.1. Distribution of Source Form
|
|
166
|
+
|
|
167
|
+
All distribution of Covered Software in Source Code Form, including any
|
|
168
|
+
Modifications that You create or to which You contribute, must be under
|
|
169
|
+
the terms of this License. You must inform recipients that the Source
|
|
170
|
+
Code Form of the Covered Software is governed by the terms of this
|
|
171
|
+
License, and how they can obtain a copy of this License. You may not
|
|
172
|
+
attempt to alter or restrict the recipients' rights in the Source Code
|
|
173
|
+
Form.
|
|
174
|
+
|
|
175
|
+
3.2. Distribution of Executable Form
|
|
176
|
+
|
|
177
|
+
If You distribute Covered Software in Executable Form then:
|
|
178
|
+
|
|
179
|
+
a. such Covered Software must also be made available in Source Code Form,
|
|
180
|
+
as described in Section 3.1, and You must inform recipients of the
|
|
181
|
+
Executable Form how they can obtain a copy of such Source Code Form by
|
|
182
|
+
reasonable means in a timely manner, at a charge no more than the cost
|
|
183
|
+
of distribution to the recipient; and
|
|
184
|
+
|
|
185
|
+
b. You may distribute such Executable Form under the terms of this
|
|
186
|
+
License, or sublicense it under different terms, provided that the
|
|
187
|
+
license for the Executable Form does not attempt to limit or alter the
|
|
188
|
+
recipients' rights in the Source Code Form under this License.
|
|
189
|
+
|
|
190
|
+
3.3. Distribution of a Larger Work
|
|
191
|
+
|
|
192
|
+
You may create and distribute a Larger Work under terms of Your choice,
|
|
193
|
+
provided that You also comply with the requirements of this License for
|
|
194
|
+
the Covered Software. If the Larger Work is a combination of Covered
|
|
195
|
+
Software with a work governed by one or more Secondary Licenses, and the
|
|
196
|
+
Covered Software is not Incompatible With Secondary Licenses, this
|
|
197
|
+
License permits You to additionally distribute such Covered Software
|
|
198
|
+
under the terms of such Secondary License(s), so that the recipient of
|
|
199
|
+
the Larger Work may, at their option, further distribute the Covered
|
|
200
|
+
Software under the terms of either this License or such Secondary
|
|
201
|
+
License(s).
|
|
202
|
+
|
|
203
|
+
3.4. Notices
|
|
204
|
+
|
|
205
|
+
You may not remove or alter the substance of any license notices
|
|
206
|
+
(including copyright notices, patent notices, disclaimers of warranty, or
|
|
207
|
+
limitations of liability) contained within the Source Code Form of the
|
|
208
|
+
Covered Software, except that You may alter any license notices to the
|
|
209
|
+
extent required to remedy known factual inaccuracies.
|
|
210
|
+
|
|
211
|
+
3.5. Application of Additional Terms
|
|
212
|
+
|
|
213
|
+
You may choose to offer, and to charge a fee for, warranty, support,
|
|
214
|
+
indemnity or liability obligations to one or more recipients of Covered
|
|
215
|
+
Software. However, You may do so only on Your own behalf, and not on
|
|
216
|
+
behalf of any Contributor. You must make it absolutely clear that any
|
|
217
|
+
such warranty, support, indemnity, or liability obligation is offered by
|
|
218
|
+
You alone, and You hereby agree to indemnify every Contributor for any
|
|
219
|
+
liability incurred by such Contributor as a result of warranty, support,
|
|
220
|
+
indemnity or liability terms You offer. You may include additional
|
|
221
|
+
disclaimers of warranty and limitations of liability specific to any
|
|
222
|
+
jurisdiction.
|
|
223
|
+
|
|
224
|
+
4. Inability to Comply Due to Statute or Regulation
|
|
225
|
+
|
|
226
|
+
If it is impossible for You to comply with any of the terms of this License
|
|
227
|
+
with respect to some or all of the Covered Software due to statute,
|
|
228
|
+
judicial order, or regulation then You must: (a) comply with the terms of
|
|
229
|
+
this License to the maximum extent possible; and (b) describe the
|
|
230
|
+
limitations and the code they affect. Such description must be placed in a
|
|
231
|
+
text file included with all distributions of the Covered Software under
|
|
232
|
+
this License. Except to the extent prohibited by statute or regulation,
|
|
233
|
+
such description must be sufficiently detailed for a recipient of ordinary
|
|
234
|
+
skill to be able to understand it.
|
|
235
|
+
|
|
236
|
+
5. Termination
|
|
237
|
+
|
|
238
|
+
5.1. The rights granted under this License will terminate automatically if You
|
|
239
|
+
fail to comply with any of its terms. However, if You become compliant,
|
|
240
|
+
then the rights granted under this License from a particular Contributor
|
|
241
|
+
are reinstated (a) provisionally, unless and until such Contributor
|
|
242
|
+
explicitly and finally terminates Your grants, and (b) on an ongoing
|
|
243
|
+
basis, if such Contributor fails to notify You of the non-compliance by
|
|
244
|
+
some reasonable means prior to 60 days after You have come back into
|
|
245
|
+
compliance. Moreover, Your grants from a particular Contributor are
|
|
246
|
+
reinstated on an ongoing basis if such Contributor notifies You of the
|
|
247
|
+
non-compliance by some reasonable means, this is the first time You have
|
|
248
|
+
received notice of non-compliance with this License from such
|
|
249
|
+
Contributor, and You become compliant prior to 30 days after Your receipt
|
|
250
|
+
of the notice.
|
|
251
|
+
|
|
252
|
+
5.2. If You initiate litigation against any entity by asserting a patent
|
|
253
|
+
infringement claim (excluding declaratory judgment actions,
|
|
254
|
+
counter-claims, and cross-claims) alleging that a Contributor Version
|
|
255
|
+
directly or indirectly infringes any patent, then the rights granted to
|
|
256
|
+
You by any and all Contributors for the Covered Software under Section
|
|
257
|
+
2.1 of this License shall terminate.
|
|
258
|
+
|
|
259
|
+
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
|
|
260
|
+
license agreements (excluding distributors and resellers) which have been
|
|
261
|
+
validly granted by You or Your distributors under this License prior to
|
|
262
|
+
termination shall survive termination.
|
|
263
|
+
|
|
264
|
+
6. Disclaimer of Warranty
|
|
265
|
+
|
|
266
|
+
Covered Software is provided under this License on an "as is" basis,
|
|
267
|
+
without warranty of any kind, either expressed, implied, or statutory,
|
|
268
|
+
including, without limitation, warranties that the Covered Software is free
|
|
269
|
+
of defects, merchantable, fit for a particular purpose or non-infringing.
|
|
270
|
+
The entire risk as to the quality and performance of the Covered Software
|
|
271
|
+
is with You. Should any Covered Software prove defective in any respect,
|
|
272
|
+
You (not any Contributor) assume the cost of any necessary servicing,
|
|
273
|
+
repair, or correction. This disclaimer of warranty constitutes an essential
|
|
274
|
+
part of this License. No use of any Covered Software is authorized under
|
|
275
|
+
this License except under this disclaimer.
|
|
276
|
+
|
|
277
|
+
7. Limitation of Liability
|
|
278
|
+
|
|
279
|
+
Under no circumstances and under no legal theory, whether tort (including
|
|
280
|
+
negligence), contract, or otherwise, shall any Contributor, or anyone who
|
|
281
|
+
distributes Covered Software as permitted above, be liable to You for any
|
|
282
|
+
direct, indirect, special, incidental, or consequential damages of any
|
|
283
|
+
character including, without limitation, damages for lost profits, loss of
|
|
284
|
+
goodwill, work stoppage, computer failure or malfunction, or any and all
|
|
285
|
+
other commercial damages or losses, even if such party shall have been
|
|
286
|
+
informed of the possibility of such damages. This limitation of liability
|
|
287
|
+
shall not apply to liability for death or personal injury resulting from
|
|
288
|
+
such party's negligence to the extent applicable law prohibits such
|
|
289
|
+
limitation. Some jurisdictions do not allow the exclusion or limitation of
|
|
290
|
+
incidental or consequential damages, so this exclusion and limitation may
|
|
291
|
+
not apply to You.
|
|
292
|
+
|
|
293
|
+
8. Litigation
|
|
294
|
+
|
|
295
|
+
Any litigation relating to this License may be brought only in the courts
|
|
296
|
+
of a jurisdiction where the defendant maintains its principal place of
|
|
297
|
+
business and such litigation shall be governed by laws of that
|
|
298
|
+
jurisdiction, without reference to its conflict-of-law provisions. Nothing
|
|
299
|
+
in this Section shall prevent a party's ability to bring cross-claims or
|
|
300
|
+
counter-claims.
|
|
301
|
+
|
|
302
|
+
9. Miscellaneous
|
|
303
|
+
|
|
304
|
+
This License represents the complete agreement concerning the subject
|
|
305
|
+
matter hereof. If any provision of this License is held to be
|
|
306
|
+
unenforceable, such provision shall be reformed only to the extent
|
|
307
|
+
necessary to make it enforceable. Any law or regulation which provides that
|
|
308
|
+
the language of a contract shall be construed against the drafter shall not
|
|
309
|
+
be used to construe this License against a Contributor.
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
10. Versions of the License
|
|
313
|
+
|
|
314
|
+
10.1. New Versions
|
|
315
|
+
|
|
316
|
+
Mozilla Foundation is the license steward. Except as provided in Section
|
|
317
|
+
10.3, no one other than the license steward has the right to modify or
|
|
318
|
+
publish new versions of this License. Each version will be given a
|
|
319
|
+
distinguishing version number.
|
|
320
|
+
|
|
321
|
+
10.2. Effect of New Versions
|
|
322
|
+
|
|
323
|
+
You may distribute the Covered Software under the terms of the version
|
|
324
|
+
of the License under which You originally received the Covered Software,
|
|
325
|
+
or under the terms of any subsequent version published by the license
|
|
326
|
+
steward.
|
|
327
|
+
|
|
328
|
+
10.3. Modified Versions
|
|
329
|
+
|
|
330
|
+
If you create software not governed by this License, and you want to
|
|
331
|
+
create a new license for such software, you may create and use a
|
|
332
|
+
modified version of this License if you rename the license and remove
|
|
333
|
+
any references to the name of the license steward (except to note that
|
|
334
|
+
such modified license differs from this License).
|
|
335
|
+
|
|
336
|
+
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
|
337
|
+
Licenses If You choose to distribute Source Code Form that is
|
|
338
|
+
Incompatible With Secondary Licenses under the terms of this version of
|
|
339
|
+
the License, the notice described in Exhibit B of this License must be
|
|
340
|
+
attached.
|
|
341
|
+
|
|
342
|
+
Exhibit A - Source Code Form License Notice
|
|
343
|
+
|
|
344
|
+
This Source Code Form is subject to the
|
|
345
|
+
terms of the Mozilla Public License, v.
|
|
346
|
+
2.0. If a copy of the MPL was not
|
|
347
|
+
distributed with this file, You can
|
|
348
|
+
obtain one at
|
|
349
|
+
https://mozilla.org/MPL/2.0/.
|
|
350
|
+
|
|
351
|
+
If it is not possible or desirable to put the notice in a particular file,
|
|
352
|
+
then You may include the notice in a location (such as a LICENSE file in a
|
|
353
|
+
relevant directory) where a recipient would be likely to look for such a
|
|
354
|
+
notice.
|
|
355
|
+
|
|
356
|
+
You may add additional accurate notices of copyright ownership.
|
|
357
|
+
|
|
358
|
+
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
|
359
|
+
|
|
360
|
+
This Source Code Form is "Incompatible
|
|
361
|
+
With Secondary Licenses", as defined by
|
|
362
|
+
the Mozilla Public License, v. 2.0.
|