-
Notifications
You must be signed in to change notification settings - Fork 10
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…
…e out of box wrapper methods into config files Signed-off-by: Prasad Mujumdar <[email protected]>
- Loading branch information
1 parent
6584869
commit d9933b5
Showing
7 changed files
with
214 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,22 @@ | ||
{ | ||
"wrapper_methods" : [ | ||
{ | ||
"package": "haystack.components.generators.openai", | ||
"object": "OpenAIGenerator", | ||
"method": "run", | ||
"wrapper": "haystack.wrap_openai.wrap_openai" | ||
}, | ||
{ | ||
"package": "haystack.components.generators.chat.openai", | ||
"object": "OpenAIChatGenerator", | ||
"method": "run", | ||
"wrapper": "haystack.wrap_openai.wrap_openai" | ||
}, | ||
{ | ||
"package": "haystack.core.pipeline.pipeline", | ||
"object": "Pipeline", | ||
"method": "run", | ||
"wrapper": "haystack.wrap_openai.wrap_pipeline" | ||
} | ||
] | ||
} |
92 changes: 92 additions & 0 deletions
92
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,92 @@ | ||
{ | ||
"wrapper_methods" : [ | ||
{ | ||
"package": "langchain.prompts.base", | ||
"object": "BasePromptTemplate", | ||
"method": "invoke", | ||
"wrapper": "wrap_common.task_wrapper" | ||
}, | ||
{ | ||
"package": "langchain.prompts.base", | ||
"object": "BasePromptTemplate", | ||
"method": "ainvoke", | ||
"wrapper": "wrap_common.atask_wrapper" | ||
}, | ||
{ | ||
"package": "langchain.chat_models.base", | ||
"object": "BaseChatModel", | ||
"method": "invoke", | ||
"wrapper": "wrap_common.llm_wrapper" | ||
}, | ||
{ | ||
"package": "langchain.chat_models.base", | ||
"object": "BaseChatModel", | ||
"method": "ainvoke", | ||
"wrapper": "wrap_common.allm_wrapper" | ||
}, | ||
{ | ||
"package": "langchain_core.language_models.llms", | ||
"object": "LLM", | ||
"method": "_generate", | ||
"wrapper": "wrap_common.llm_wrapper" | ||
}, | ||
{ | ||
"package": "langchain_core.language_models.llms", | ||
"object": "LLM", | ||
"method": "_agenerate", | ||
"wrapper": "wrap_common.llm_wrapper" | ||
}, | ||
{ | ||
"package": "langchain_core.retrievers", | ||
"object": "BaseRetriever", | ||
"method": "invoke", | ||
"wrapper": "wrap_common.task_wrapper" | ||
}, | ||
{ | ||
"package": "langchain_core.retrievers", | ||
"object": "BaseRetriever", | ||
"method": "ainvoke", | ||
"wrapper": "wrap_common.atask_wrapper" | ||
}, | ||
{ | ||
"package": "langchain.schema", | ||
"object": "BaseOutputParser", | ||
"method": "invoke", | ||
"wrapper": "wrap_common.task_wrapper" | ||
}, | ||
{ | ||
"package": "langchain.schema", | ||
"object": "BaseOutputParser", | ||
"method": "ainvoke", | ||
"wrapper": "wrap_common.atask_wrapper" | ||
}, | ||
{ | ||
"package": "langchain.schema.runnable", | ||
"object": "RunnableSequence", | ||
"method": "invoke", | ||
"span_name": "langchain.workflow", | ||
"wrapper": "wrap_common.task_wrapper" | ||
}, | ||
{ | ||
"package": "langchain.schema.runnable", | ||
"object": "RunnableSequence", | ||
"method": "ainvoke", | ||
"span_name": "langchain.workflow", | ||
"wrapper": "wrap_common.atask_wrapper" | ||
}, | ||
{ | ||
"package": "langchain.schema.runnable", | ||
"object": "RunnableParallel", | ||
"method": "invoke", | ||
"span_name": "langchain.workflow", | ||
"wrapper": "wrap_common.task_wrapper" | ||
}, | ||
{ | ||
"package": "langchain.schema.runnable", | ||
"object": "RunnableParallel", | ||
"method": "ainvoke", | ||
"span_name": "langchain.workflow", | ||
"wrapper": "wrap_common.atask_wrapper" | ||
} | ||
] | ||
} |
Oops, something went wrong.