-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add framework for reading wrapper methods from configuration. Move th… (
#20) * Add framework for reading wrapper methods from configuration. Move the out of box wrapper methods into config files Signed-off-by: Prasad Mujumdar <[email protected]> Signed-off-by: prasad-okahu <[email protected]> * fixed haystack method name typo Signed-off-by: prasad-okahu <[email protected]> * Updated the wrapper method format Signed-off-by: prasad-okahu <[email protected]> --------- Signed-off-by: Prasad Mujumdar <[email protected]> Signed-off-by: prasad-okahu <[email protected]> Signed-off-by: Kshitiz Vijayvargiya <[email protected]>
- Loading branch information
1 parent
6584869
commit 582c795
Showing
7 changed files
with
237 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,9 @@ | ||
|
||
|
||
import os | ||
import logging | ||
from monocle_apptrace.haystack.wrap_openai import wrap_openai | ||
from monocle_apptrace.haystack.wrap_pipeline import wrap as wrap_pipeline | ||
from monocle_apptrace.utils import load_wrapper_from_config | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
HAYSTACK_METHODS = [ | ||
{ | ||
"package": "haystack.components.generators.openai", | ||
"object": "OpenAIGenerator", | ||
"method": "run", | ||
"wrapper": wrap_openai, | ||
}, | ||
{ | ||
"package": "haystack.components.generators.chat.openai", | ||
"object": "OpenAIChatGenerator", | ||
"method": "run", | ||
"wrapper": wrap_openai, | ||
}, | ||
{ | ||
"package": "haystack.core.pipeline.pipeline", | ||
"object": "Pipeline", | ||
"method": "run", | ||
"wrapper": wrap_pipeline, | ||
}, | ||
] | ||
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) | ||
HAYSTACK_METHODS = load_wrapper_from_config( | ||
os.path.join(parent_dir, 'wrapper_config', 'haystack_methods.json')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,6 @@ | ||
import os | ||
from monocle_apptrace.utils import load_wrapper_from_config | ||
|
||
|
||
from monocle_apptrace.wrap_common import allm_wrapper, atask_wrapper, llm_wrapper, task_wrapper | ||
|
||
LANGCHAIN_METHODS = [ | ||
{ | ||
"package": "langchain.prompts.base", | ||
"object": "BasePromptTemplate", | ||
"method": "invoke", | ||
"wrapper": task_wrapper, | ||
}, | ||
{ | ||
"package": "langchain.prompts.base", | ||
"object": "BasePromptTemplate", | ||
"method": "ainvoke", | ||
"wrapper": atask_wrapper, | ||
}, | ||
{ | ||
"package": "langchain.chat_models.base", | ||
"object": "BaseChatModel", | ||
"method": "invoke", | ||
"wrapper": llm_wrapper, | ||
}, | ||
{ | ||
"package": "langchain.chat_models.base", | ||
"object": "BaseChatModel", | ||
"method": "ainvoke", | ||
"wrapper": allm_wrapper, | ||
}, | ||
{ | ||
"package": "langchain_core.language_models.llms", | ||
"object": "LLM", | ||
"method": "_generate", | ||
"wrapper": llm_wrapper, | ||
}, | ||
{ | ||
"package": "langchain_core.language_models.llms", | ||
"object": "LLM", | ||
"method": "_agenerate", | ||
"wrapper": llm_wrapper, | ||
}, | ||
{ | ||
"package": "langchain_core.retrievers", | ||
"object": "BaseRetriever", | ||
"method": "invoke", | ||
"wrapper": task_wrapper, | ||
}, | ||
{ | ||
"package": "langchain_core.retrievers", | ||
"object": "BaseRetriever", | ||
"method": "ainvoke", | ||
"wrapper": atask_wrapper, | ||
}, | ||
{ | ||
"package": "langchain.schema", | ||
"object": "BaseOutputParser", | ||
"method": "invoke", | ||
"wrapper": task_wrapper, | ||
}, | ||
{ | ||
"package": "langchain.schema", | ||
"object": "BaseOutputParser", | ||
"method": "ainvoke", | ||
"wrapper": atask_wrapper, | ||
}, | ||
{ | ||
"package": "langchain.schema.runnable", | ||
"object": "RunnableSequence", | ||
"method": "invoke", | ||
"span_name": "langchain.workflow", | ||
"wrapper": task_wrapper, | ||
}, | ||
{ | ||
"package": "langchain.schema.runnable", | ||
"object": "RunnableSequence", | ||
"method": "ainvoke", | ||
"span_name": "langchain.workflow", | ||
"wrapper": atask_wrapper, | ||
}, | ||
{ | ||
"package": "langchain.schema.runnable", | ||
"object": "RunnableParallel", | ||
"method": "invoke", | ||
"span_name": "langchain.workflow", | ||
"wrapper": task_wrapper, | ||
}, | ||
{ | ||
"package": "langchain.schema.runnable", | ||
"object": "RunnableParallel", | ||
"method": "ainvoke", | ||
"span_name": "langchain.workflow", | ||
"wrapper": atask_wrapper, | ||
}, | ||
|
||
] | ||
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) | ||
LANGCHAIN_METHODS = load_wrapper_from_config( | ||
os.path.join(parent_dir, 'wrapper_config', 'lang_chain_methods.json')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"wrapper_methods" : [ | ||
{ | ||
"package": "haystack.components.generators.openai", | ||
"object": "OpenAIGenerator", | ||
"method": "run", | ||
"wrapper_package": "haystack.wrap_openai", | ||
"wrapper_method": "wrap_openai" | ||
}, | ||
{ | ||
"package": "haystack.components.generators.chat.openai", | ||
"object": "OpenAIChatGenerator", | ||
"method": "run", | ||
"wrapper_package": "haystack.wrap_openai", | ||
"wrapper_method": "wrap_openai" | ||
}, | ||
{ | ||
"package": "haystack.core.pipeline.pipeline", | ||
"object": "Pipeline", | ||
"method": "run", | ||
"wrapper_package": "haystack.wrap_pipeline", | ||
"wrapper_method": "wrap" | ||
} | ||
] | ||
} |
106 changes: 106 additions & 0 deletions
106
src/monocle_apptrace/wrapper_config/lang_chain_methods.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
{ | ||
"wrapper_methods" : [ | ||
{ | ||
"package": "langchain.prompts.base", | ||
"object": "BasePromptTemplate", | ||
"method": "invoke", | ||
"wrapper_package": "wrap_common", | ||
"wrapper_method": "task_wrapper" | ||
}, | ||
{ | ||
"package": "langchain.prompts.base", | ||
"object": "BasePromptTemplate", | ||
"method": "ainvoke", | ||
"wrapper_package": "wrap_common", | ||
"wrapper_method": "atask_wrapper" | ||
}, | ||
{ | ||
"package": "langchain.chat_models.base", | ||
"object": "BaseChatModel", | ||
"method": "invoke", | ||
"wrapper_package": "wrap_common", | ||
"wrapper_method": "llm_wrapper" | ||
}, | ||
{ | ||
"package": "langchain.chat_models.base", | ||
"object": "BaseChatModel", | ||
"method": "ainvoke", | ||
"wrapper_package": "wrap_common", | ||
"wrapper_method": "allm_wrapper" | ||
}, | ||
{ | ||
"package": "langchain_core.language_models.llms", | ||
"object": "LLM", | ||
"method": "_generate", | ||
"wrapper_package": "wrap_common", | ||
"wrapper_method": "llm_wrapper" | ||
}, | ||
{ | ||
"package": "langchain_core.language_models.llms", | ||
"object": "LLM", | ||
"method": "_agenerate", | ||
"wrapper_package": "wrap_common", | ||
"wrapper_method": "llm_wrapper" | ||
}, | ||
{ | ||
"package": "langchain_core.retrievers", | ||
"object": "BaseRetriever", | ||
"method": "invoke", | ||
"wrapper_package": "wrap_common", | ||
"wrapper_method": "task_wrapper" | ||
}, | ||
{ | ||
"package": "langchain_core.retrievers", | ||
"object": "BaseRetriever", | ||
"method": "ainvoke", | ||
"wrapper_package": "wrap_common", | ||
"wrapper_method": "atask_wrapper" | ||
}, | ||
{ | ||
"package": "langchain.schema", | ||
"object": "BaseOutputParser", | ||
"method": "invoke", | ||
"wrapper_package": "wrap_common", | ||
"wrapper_method": "task_wrapper" | ||
}, | ||
{ | ||
"package": "langchain.schema", | ||
"object": "BaseOutputParser", | ||
"method": "ainvoke", | ||
"wrapper_package": "wrap_common", | ||
"wrapper_method": "atask_wrapper" | ||
}, | ||
{ | ||
"package": "langchain.schema.runnable", | ||
"object": "RunnableSequence", | ||
"method": "invoke", | ||
"span_name": "langchain.workflow", | ||
"wrapper_package": "wrap_common", | ||
"wrapper_method": "task_wrapper" | ||
}, | ||
{ | ||
"package": "langchain.schema.runnable", | ||
"object": "RunnableSequence", | ||
"method": "ainvoke", | ||
"span_name": "langchain.workflow", | ||
"wrapper_package": "wrap_common", | ||
"wrapper_method": "atask_wrapper" | ||
}, | ||
{ | ||
"package": "langchain.schema.runnable", | ||
"object": "RunnableParallel", | ||
"method": "invoke", | ||
"span_name": "langchain.workflow", | ||
"wrapper_package": "wrap_common", | ||
"wrapper_method": "task_wrapper" | ||
}, | ||
{ | ||
"package": "langchain.schema.runnable", | ||
"object": "RunnableParallel", | ||
"method": "ainvoke", | ||
"span_name": "langchain.workflow", | ||
"wrapper_package": "wrap_common", | ||
"wrapper_method": "atask_wrapper" | ||
} | ||
] | ||
} |
Oops, something went wrong.