Modules
Copyright 2023 Bell Eapen
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
BaseAgent
¶
Source code in src/dhti_elixir_base/agent.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
AgentInput
¶
Bases: BaseModel
Chat history with the bot.
Source code in src/dhti_elixir_base/agent.py
31 32 33 34 | |
get_langgraph_mcp_agent()
async
¶
Get the agent executor for async execution.
Source code in src/dhti_elixir_base/agent.py
108 109 110 111 112 113 114 115 116 117 118 119 120 | |
get_langgraph_mcp_tools(session_name='dhti')
async
¶
Get the agent executor for async execution with session.
Source code in src/dhti_elixir_base/agent.py
122 123 124 125 126 127 128 | |
has_tool()
¶
Check if the agent has any tools.
Source code in src/dhti_elixir_base/agent.py
78 79 80 81 82 83 84 85 | |
Copyright 2025 Bell Eapen
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
BaseChain
¶
Source code in src/dhti_elixir_base/chain.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
chain
property
¶
Get the runnable chain.
Example usage of an agent in the chain: BaseAgent takes llm, prompt, tools as input. If tools is not provided, it loads tools from MCP. default llm is function_llm from DI. Default prompt is "You are a helpful assistant." self.my_agent = BaseAgent().get_agent_response # in init _chain = ( RunnablePassthrough() | get_string_message_to_agent | self.my_agent | StrOutputParser() )
RunnableParallel / RunnablePassthrough / RunnableSequential / RunnableLambda / RunnableMap / RunnableBranch
ChainInput
¶
Bases: BaseModel
Input model for BaseChain.
Attributes:
| Name | Type | Description |
|---|---|---|
input |
Any
|
The input string or CDSHookRequest object for the chain. |
Source code in src/dhti_elixir_base/chain.py
36 37 38 39 40 41 42 43 44 45 | |
generate_llm_config()
¶
Generate the configuration schema for the LLM function call.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
A dictionary containing the function schema for the LLM, including name, description, and parameters. |
Source code in src/dhti_elixir_base/chain.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
get_chain_as_langchain_tool()
¶
Convert the chain to a LangChain StructuredTool.
Returns:
| Name | Type | Description |
|---|---|---|
StructuredTool |
An instance of LangChain StructuredTool wrapping the chain. |
Source code in src/dhti_elixir_base/chain.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
get_chain_as_mcp_tool()
¶
Convert the chain to an MCP tool using the FastMCP adapter.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
An MCP tool instance wrapping the chain. |
Source code in src/dhti_elixir_base/chain.py
229 230 231 232 233 234 235 236 237 238 239 240 | |
Copyright 2024 Bell Eapen
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
BaseLLM
¶
Bases: LLM
Source code in src/dhti_elixir_base/llm.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
BaseMCPServer
¶
Bases: FastMCP
Base class for MCP servers, extending FastMCP for custom functionality.
Source code in src/dhti_elixir_base/mcp.py
4 5 6 7 8 9 10 11 12 13 14 | |
name
property
¶
Return the name of this MCP server instance.
BaseDhtiModel
¶
Bases: ABC
A model class to lead the model and tokenizer
Source code in src/dhti_elixir_base/model.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
camel_to_snake(name)
¶
Convert CamelCase to snake_case using pre-compiled regex for efficiency.
Source code in src/dhti_elixir_base/mydi.py
9 10 11 | |
BaseServer
¶
Bases: ABC
A server class to load the model and tokenizer
Source code in src/dhti_elixir_base/server.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
get_schema()
¶
Get the request schema
Source code in src/dhti_elixir_base/server.py
48 49 50 | |
health_check()
¶
Health check endpoint
Source code in src/dhti_elixir_base/server.py
43 44 45 46 | |
Pydantic Model for CDS Hook Card
Example:
{ "summary": "Patient is at high risk for opioid overdose.", "detail": "According to CDC guidelines, the patient's opioid dosage should be tapered to less than 50 MME. Link to CDC Guideline", "indicator": "warning", "source": { "label": "CDC Opioid Prescribing Guidelines", "url": "https://www.cdc.gov/drugoverdose/prescribing/guidelines.html", "icon": "https://example.org/img/cdc-icon.png" }, "links": [ { "label": "View MME Conversion Table", "url": "https://www.cdc.gov/drugoverdose/prescribing/mme.html" } ] }
CDSHookCard
¶
Bases: BaseModel
CDS Hook Card Model
Source code in src/dhti_elixir_base/cds_hook/card.py
40 41 42 43 44 45 46 | |
CDSHookCardLink
¶
Bases: BaseModel
Link associated with the CDS Hook Card
Source code in src/dhti_elixir_base/cds_hook/card.py
35 36 37 38 | |
CDSHookCardSource
¶
Bases: BaseModel
Source of the CDS Hook Card
Source code in src/dhti_elixir_base/cds_hook/card.py
29 30 31 32 33 | |
Copyright 2025 Bell Eapen
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
add_card(output, cards=None)
¶
Add a CDSHookCard to the output list.
Source code in src/dhti_elixir_base/cds_hook/generate_cards.py
20 21 22 23 24 25 26 27 28 29 30 | |
get_card(output)
¶
Get a CDSHookCard as a dictionary.
Source code in src/dhti_elixir_base/cds_hook/generate_cards.py
32 33 34 35 36 37 38 39 | |
Copyright 2025 Bell Eapen
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
CDS Hook Request Model
Pydantic Model for CDS Hook Request. Typically context has "patientId" and "input" keys.
Example: { "hookInstance": "d1577c69-dfbe-44ad-ba6d-3e05e953b2ea", "fhirServer": "https://example.com/fhir", "fhirAuthorization": { ... }, "hook": "patient-view", "context": { ... }, "prefetch": { ... } }
CDSHookRequest
¶
Bases: BaseModel
CDS Hook Request Model
Source code in src/dhti_elixir_base/cds_hook/request.py
22 23 24 25 26 27 28 29 | |
Pydantic models for CDS Hook Service
Example: { "services": [ { "hook": "patient-view", "name": "Static CDS Service Example", "description": "An example of a CDS Service that returns a card with SMART app recommendations.", "id": "static-patient-view", "prefetch": { "patientToGreet": "Patient/{{context.patientId}}" } } ] }
CDSHookService
¶
Bases: BaseModel
CDS Hook Service Model
Source code in src/dhti_elixir_base/cds_hook/service.py
24 25 26 27 28 29 30 | |
CDSHookServicesResponse
¶
Bases: BaseModel
Response model containing a list of CDS Hook Services
Source code in src/dhti_elixir_base/cds_hook/service.py
32 33 34 | |
DhtiFhirSearch
¶
Source code in src/dhti_elixir_base/fhir/fhir_search.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
get_allergy_intolerances_for_patient(input_data=None, fhirpath=None)
¶
Fetch all AllergyIntolerance resources related to a specific patient. Args: input_data (dict or str): Input containing patient ID or the patient ID itself. fhirpath (str, optional): FHIRPath expression to apply to the results. Returns: dict: Combined AllergyIntolerance resources related to the patient.
Source code in src/dhti_elixir_base/fhir/fhir_search.py
131 132 133 134 135 136 137 138 139 | |
get_conditions_for_patient(input_data=None, fhirpath=None)
¶
Fetch all Condition resources related to a specific patient. Args: input_data (dict or str): Input containing patient ID or the patient ID itself. fhirpath (str, optional): FHIRPath expression to apply to the results. Returns: dict: Combined Condition resources related to the patient.
Source code in src/dhti_elixir_base/fhir/fhir_search.py
91 92 93 94 95 96 97 98 99 | |
get_everything_for_patient(input_data=None, fhirpath=None)
¶
Fetch all resources related to a specific patient using the $everything operation. Args: input_data (dict or str): Input containing patient ID or the patient ID itself. fhirpath (str, optional): FHIRPath expression to apply to the results. Returns: dict: Combined resources related to the patient.
Source code in src/dhti_elixir_base/fhir/fhir_search.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
get_medication_requests_for_patient(input_data=None, fhirpath=None)
¶
Fetch all MedicationRequest resources related to a specific patient. Args: input_data (dict or str): Input containing patient ID or the patient ID itself. fhirpath (str, optional): FHIRPath expression to apply to the results. Returns: dict: Combined MedicationRequest resources related to the patient.
Source code in src/dhti_elixir_base/fhir/fhir_search.py
121 122 123 124 125 126 127 128 129 | |
get_observations_for_patient(input_data=None, fhirpath=None)
¶
Fetch all Observation resources related to a specific patient. Args: input_data (dict or str): Input containing patient ID or the patient ID itself. fhirpath (str, optional): FHIRPath expression to apply to the results. Returns: dict: Combined Observation resources related to the patient.
Source code in src/dhti_elixir_base/fhir/fhir_search.py
101 102 103 104 105 106 107 108 109 | |
get_procedures_for_patient(input_data=None, fhirpath=None)
¶
Fetch all Procedure resources related to a specific patient. Args: input_data (dict or str): Input containing patient ID or the patient ID itself. fhirpath (str, optional): FHIRPath expression to apply to the results. Returns: dict: Combined Procedure resources related to the patient.
Source code in src/dhti_elixir_base/fhir/fhir_search.py
111 112 113 114 115 116 117 118 119 | |
search(resource_type='Patient', search_parameters=None, fhirpath=None)
¶
Search the FHIR server and return the combined results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource_type
|
str
|
FHIR resource type to search (e.g., "Patient"). |
'Patient'
|
search_parameters
|
dict
|
Query parameters per FHIR spec; _count is auto-set to the configured page size if absent. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Combined search results from the FHIR server. |
Source code in src/dhti_elixir_base/fhir/fhir_search.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
SmartOnFhirSearch
¶
SMART-on-FHIR backed search helper mirroring DhtiFhirSearch API.
Uses fhirclient's resource model search pattern, e.g.:
settings = { 'app_id': 'my_web_app', 'api_base': 'https://r4.smarthealthit.org' }
smart = client.FHIRClient(settings=settings)
patient = Patient.read('<id>', smart.server)
Each method returns raw JSON like DhtiFhirSearch and optionally applies a FHIRPath expression via fhirpathpy.evaluate.
Source code in src/dhti_elixir_base/fhir/smart_on_fhir.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
get_everything_for_patient(input_data=None, fhirpath=None)
¶
Fetch resources related to a patient using $everything operation.
Returns JSON Bundle like DhtiFhirSearch.
Source code in src/dhti_elixir_base/fhir/smart_on_fhir.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
search(resource_type='Patient', search_parameters=None, fhirpath=None)
¶
Generic search for any resource type.
Tries to resolve the appropriate fhirclient model class and perform a model-based search; if not possible, falls back to an HTTP GET.
Source code in src/dhti_elixir_base/fhir/smart_on_fhir.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
Copyright 2025 Bell Eapen
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
CrewAIAgentWrapper
¶
Bases: Agent
Wrapper class to make BaseAgent compatible with CrewAI.
This wrapper allows the use of DHTI's BaseAgent within the CrewAI framework by adapting its interface to CrewAI's requirements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
BaseAgent
|
An instance of BaseAgent from dhti_elixir_base |
required |
role
|
str | None
|
The role of the agent (optional, uses agent's description if not provided) |
None
|
goal
|
str | None
|
The goal of the agent (optional, uses agent's name if not provided) |
None
|
backstory
|
str | None
|
The backstory of the agent (optional) |
None
|
**kwargs
|
Any
|
Additional keyword arguments passed to the CrewAI Agent |
{}
|
Example
from dhti_elixir_base import BaseAgent
from dhti_elixir_base.crewai import CrewAIAgentWrapper
# Create a DHTI agent instance
dhti_agent = BaseAgent(
name="medical_assistant",
description="A medical assistant agent",
llm=my_llm,
prompt="You are a helpful medical assistant."
)
# Wrap it for use with CrewAI
crewai_agent = CrewAIAgentWrapper(
agent=dhti_agent,
role="Medical Assistant",
goal="Assist with medical queries"
)
Source code in src/dhti_elixir_base/crewai/agent_wrapper.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
__init__(agent, role=None, goal=None, backstory=None, **kwargs)
¶
Initialize the CrewAI Agent wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
BaseAgent
|
An instance of BaseAgent |
required |
role
|
str | None
|
The role of the agent |
None
|
goal
|
str | None
|
The goal of the agent |
None
|
backstory
|
str | None
|
The backstory of the agent |
None
|
**kwargs
|
Any
|
Additional keyword arguments |
{}
|
Source code in src/dhti_elixir_base/crewai/agent_wrapper.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
__repr__()
¶
Return detailed string representation of the wrapper.
Source code in src/dhti_elixir_base/crewai/agent_wrapper.py
160 161 162 | |
__str__()
¶
Return string representation of the wrapper.
Source code in src/dhti_elixir_base/crewai/agent_wrapper.py
156 157 158 | |
execute_task(task, *args, **kwargs)
¶
Execute a task using the underlying DHTI agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Any
|
The task to execute |
required |
*args
|
Any
|
Additional positional arguments |
()
|
**kwargs
|
Any
|
Additional keyword arguments |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The result of the task execution |
Source code in src/dhti_elixir_base/crewai/agent_wrapper.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
Copyright 2025 Bell Eapen
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
CrewAIChainToolWrapper
¶
Bases: BaseTool
Wrapper class to make BaseChain usable as a Tool within CrewAI.
This wrapper allows the use of DHTI's BaseChain as a tool within the CrewAI framework by adapting its interface to CrewAI's tool requirements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chain
|
BaseChain
|
An instance of BaseChain from dhti_elixir_base |
required |
name
|
str | None
|
Name of the tool (optional, uses chain's name if not provided) |
None
|
description
|
str | None
|
Description of the tool (optional, uses chain's description if not provided) |
None
|
**kwargs
|
Any
|
Additional keyword arguments |
{}
|
Example
from dhti_elixir_base import BaseChain
from dhti_elixir_base.crewai import CrewAIChainToolWrapper
# Create a DHTI chain instance
dhti_chain = BaseChain(
name="medical_analyzer",
description="Analyzes medical records"
)
# Wrap it as a CrewAI tool
crewai_tool = CrewAIChainToolWrapper(
chain=dhti_chain,
name="Medical Analyzer",
description="Analyzes medical records and provides insights"
)
Source code in src/dhti_elixir_base/crewai/chain_tool_wrapper.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
__init__(chain, name=None, description=None, **kwargs)
¶
Initialize the CrewAI Chain Tool wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chain
|
BaseChain
|
An instance of BaseChain |
required |
name
|
str | None
|
Name of the tool |
None
|
description
|
str | None
|
Description of the tool |
None
|
**kwargs
|
Any
|
Additional keyword arguments |
{}
|
Source code in src/dhti_elixir_base/crewai/chain_tool_wrapper.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
__repr__()
¶
Return detailed string representation of the wrapper.
Source code in src/dhti_elixir_base/crewai/chain_tool_wrapper.py
155 156 157 | |
__str__()
¶
Return string representation of the wrapper.
Source code in src/dhti_elixir_base/crewai/chain_tool_wrapper.py
151 152 153 | |
Copyright 2025 Bell Eapen
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
CrewAILangChainToolWrapper
¶
Bases: BaseTool
Wrapper class to make LangChain Tool usable within CrewAI.
This wrapper allows the use of standard LangChain tools within the CrewAI framework by adapting their interface to CrewAI's tool requirements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
langchain_tool
|
BaseTool | Any
|
An instance of LangChain BaseTool |
required |
**kwargs
|
Any
|
Additional keyword arguments |
{}
|
Example
from langchain_community.tools import WikipediaQueryRun
from langchain_community.utilities import WikipediaAPIWrapper
from dhti_elixir_base.crewai import CrewAILangChainToolWrapper
# Create a LangChain tool
wikipedia = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper())
# Wrap it for use with CrewAI
crewai_tool = CrewAILangChainToolWrapper(langchain_tool=wikipedia)
Source code in src/dhti_elixir_base/crewai/langchain_tool_wrapper.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
__init__(langchain_tool, **kwargs)
¶
Initialize the CrewAI LangChain Tool wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
langchain_tool
|
BaseTool | Any
|
An instance of LangChain BaseTool or compatible tool |
required |
**kwargs
|
Any
|
Additional keyword arguments |
{}
|
Source code in src/dhti_elixir_base/crewai/langchain_tool_wrapper.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
__repr__()
¶
Return detailed string representation of the wrapper.
Source code in src/dhti_elixir_base/crewai/langchain_tool_wrapper.py
183 184 185 | |
__str__()
¶
Return string representation of the wrapper.
Source code in src/dhti_elixir_base/crewai/langchain_tool_wrapper.py
179 180 181 | |
Copyright 2025 Bell Eapen
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
CrewAILLMWrapper
¶
Bases: BaseLLM
Wrapper class to make BaseLLM and BaseChatLLM compatible with CrewAI.
This wrapper allows the use of DHTI's LLM classes within the CrewAI framework by adapting their interfaces to CrewAI's requirements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm
|
BaseLLM | BaseChatLLM
|
An instance of BaseLLM or BaseChatLLM from dhti_elixir_base |
required |
**kwargs
|
Any
|
Additional keyword arguments |
{}
|
Example
from dhti_elixir_base import BaseChatLLM
from dhti_elixir_base.crewai import CrewAILLMWrapper
# Create a DHTI LLM instance
dhti_llm = BaseChatLLM(
base_url="https://api.example.com/chat",
model="gpt-4",
api_key="your-api-key"
)
# Wrap it for use with CrewAI
crewai_llm = CrewAILLMWrapper(llm=dhti_llm)
Source code in src/dhti_elixir_base/crewai/llm_wrapper.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
model
property
¶
Return the model name.
provider
property
writable
¶
Return the provider name.
__init__(llm, **kwargs)
¶
Initialize the CrewAI LLM wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm
|
BaseLLM | BaseChatLLM
|
An instance of BaseLLM or BaseChatLLM |
required |
**kwargs
|
Any
|
Additional keyword arguments |
{}
|
Source code in src/dhti_elixir_base/crewai/llm_wrapper.py
54 55 56 57 58 59 60 61 62 63 | |
__repr__()
¶
Return detailed string representation of the wrapper.
Source code in src/dhti_elixir_base/crewai/llm_wrapper.py
159 160 161 | |
__str__()
¶
Return string representation of the wrapper.
Source code in src/dhti_elixir_base/crewai/llm_wrapper.py
155 156 157 | |
call(messages, *args, **kwargs)
¶
Call the underlying DHTI LLM with the provided messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[dict[str, Any]]
|
List of message dictionaries with 'role' and 'content' keys |
required |
*args
|
Any
|
Additional positional arguments |
()
|
**kwargs
|
Any
|
Additional keyword arguments |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The generated response from the LLM |
Raises:
| Type | Description |
|---|---|
ValueError
|
If messages list is empty or malformed |
RuntimeError
|
If LLM invocation fails |
Source code in src/dhti_elixir_base/crewai/llm_wrapper.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
get_context_window_size()
¶
Get the context window size for the model.
Source code in src/dhti_elixir_base/crewai/llm_wrapper.py
137 138 139 140 141 | |
get_token_usage_summary()
¶
Get token usage summary.
Source code in src/dhti_elixir_base/crewai/llm_wrapper.py
143 144 145 146 147 148 149 | |
supports_stop_words()
¶
Check if the model supports stop words.
Source code in src/dhti_elixir_base/crewai/llm_wrapper.py
151 152 153 | |
Copyright 2025 Bell Eapen
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
FileProcessingRequest
¶
Bases: CustomUserType
Request including a base64 encoded file.
Source code in src/dhti_elixir_base/rag/process.py
33 34 35 36 37 38 39 40 41 42 43 44 | |
combine_documents(documents, document_separator='\n\n')
¶
Combine documents into a single string.
Source code in src/dhti_elixir_base/rag/process.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
process_file(request)
¶
Extract the text from all pages of the PDF.
Source code in src/dhti_elixir_base/rag/process.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
search_vectorstore(query)
¶
Search the vectorstore for the given query.
Source code in src/dhti_elixir_base/rag/process.py
88 89 90 91 | |