Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metamodel entity changes #51

Merged
merged 10 commits into from
Oct 16, 2024
1 change: 1 addition & 0 deletions src/monocle_apptrace/instrumentor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def _instrument(self, **kwargs):
"method": method.method,
"span_name": method.span_name,
"wrapper": method.wrapper,
"output_processor":method.output_processor
} for method in self.user_wrapper_methods]

final_method_list = user_method_list + INBUILT_METHODS_LIST
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
sachintendulkar576123 marked this conversation as resolved.
Show resolved Hide resolved
sachintendulkar576123 marked this conversation as resolved.
Show resolved Hide resolved
"type": "inference",
"attributes": [
[
{
"_comment": "provider type ,name , deployment , inference_endpoint",
"attribute": "type",
"accessor": "lambda instance,args:'inference.azure_oai'"
},
{
"attribute": "provider_name",
"accessor": "lambda instance,args:args['provider_name']"
},
{
"attribute": "deployment",
"accessor": "lambda instance,args: resolve_from_alias(instance.__dict__, ['engine', 'azure_deployment', 'deployment_name', 'deployment_id', 'deployment'])"
},
{
"attribute": "inference_endpoint",
"accessor": "lambda instance,args: resolve_from_alias(instance.__dict__, ['azure_endpoint', 'api_base'])"
}
],
[
{
"_comment": "LLM Model",
"attribute": "name",
"accessor": "lambda instance,args: resolve_from_alias(instance.__dict__, ['model', 'model_name'])"
},
{
"attribute": "type",
"accessor": "lambda instance,args: 'model.llm'"
},
{
"attribute": "model_name",
"accessor": "lambda instance,args: resolve_from_alias(instance.__dict__, ['model', 'model_name'])"
}
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"type": "inference",
"attributes": [
[
{
"_comment": "provider type ,name , deployment , inference_endpoint",
"attribute": "type",
"accessor": "lambda instance,args:'inference.azure_oai'"
},
{
"attribute": "provider_name",
"accessor": "lambda instance,args:args['provider_name']"
},
{
"attribute": "deployment",
"accessor": "lambda instance,args: resolve_from_alias(instance.__dict__, ['engine', 'azure_deployment', 'deployment_name', 'deployment_id', 'deployment'])"
},
{
"attribute": "inference_endpoint",
"accessor": "lambda instance,args: resolve_from_alias(instance.__dict__, ['azure_endpoint', 'api_base'])"
}
],
[
{
"_comment": "LLM Model",
"attribute": "name",
"accessor": "lambda instance,args: resolve_from_alias(instance.__dict__, ['model', 'model_name'])"
},
{
"attribute": "type",
"accessor": "lambda instance,args: 'model.llm'"
},
{
"attribute": "model_name",
"accessor": "lambda instance,args: resolve_from_alias(instance.__dict__, ['model', 'model_name'])"
}
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"type": "retreival",
sachintendulkar576123 marked this conversation as resolved.
Show resolved Hide resolved
"attributes": [
[
{
"_comment": "vector store name and type",
"attribute": "name",
"accessor": "lambda instance,args: type(instance.vectorstore).__name__"
},
{
"attribute": "type",
"accessor": "lambda instance,args: 'vectorstore.'+type(instance.vectorstore).__name__"
},
{
"attribute": "embedding_model_name",
"accessor": "lambda instance,args: instance.vectorstore.embeddings.model"
}
],
[
{
"_comment": "embedding model name and type",
"attribute": "name",
"accessor": "lambda instance,args: instance.vectorstore.embeddings.model"
},
{
"attribute": "type",
"accessor": "lambda instance ,args: 'model.embedding'"
},
{
"attribute": "model_name",
"accessor": "lambda instance,args: instance.vectorstore.embeddings.model"
}
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"type": "retreival",
sachintendulkar576123 marked this conversation as resolved.
Show resolved Hide resolved
"attributes": [
[
{
"_comment": "vector store name and type",
"attribute": "name",
"accessor": "lambda instance,args: type(instance._vector_store).__name__"
},
{
"attribute": "type",
"accessor": "lambda instance,args: 'vectorstore.'+type(instance._vector_store).__name__"
},
{
"attribute": "embedding_model_name",
"accessor": "lambda instance,args: instance._embed_model.model_name"
}
],
[
{
"_comment": "embedding model name and type",
"attribute": "name",
"accessor": "lambda instance,args: instance._embed_model.model_name"
},
{
"attribute": "type",
"accessor": "lambda instance ,args: 'model.embedding'"
},
{
"attribute": "model_name",
"accessor": "lambda instance,args: instance._embed_model.model_name"
}
]
]
}
9 changes: 6 additions & 3 deletions src/monocle_apptrace/metamodel/maps/lang_chain_methods.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"wrapper_methods" : [
{
"package": "langchain.prompts.base",
Expand All @@ -19,7 +19,8 @@
"object": "BaseChatModel",
"method": "invoke",
"wrapper_package": "wrap_common",
"wrapper_method": "llm_wrapper"
"wrapper_method": "llm_wrapper",
"output_processor": ["metamodel/maps/attributes/inference/lang_chain_entities.json"]
},
{
"package": "langchain.chat_models.base",
Expand Down Expand Up @@ -47,7 +48,9 @@
"object": "BaseRetriever",
"method": "invoke",
"wrapper_package": "wrap_common",
"wrapper_method": "task_wrapper"
"wrapper_method": "task_wrapper",
"output_processor": ["metamodel/maps/attributes/retrieval/lang_chain_entities.json"]

},
{
"package": "langchain_core.retrievers",
Expand Down
6 changes: 3 additions & 3 deletions src/monocle_apptrace/metamodel/maps/llama_index_methods.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"method": "retrieve",
"span_name": "llamaindex.retrieve",
"wrapper_package": "wrap_common",
"wrapper_method": "task_wrapper"
"wrapper_method": "task_wrapper",
"output_processor": ["metamodel/maps/attributes/retrieval/llama_index_entities.json"]
},
{
"package": "llama_index.core.indices.base_retriever",
Expand Down Expand Up @@ -55,8 +56,7 @@
"span_name": "llamaindex.openai",
"wrapper_package": "wrap_common",
"wrapper_method": "llm_wrapper",
"span_name_getter_package" : "llamaindex",
"span_name_getter_mothod" : "get_llm_span_name_for_openai"
"output_processor": ["metamodel/maps/attributes/inference/llama_index_entities.json"]
},
{
"package": "llama_index.llms.openai.base",
Expand Down
8 changes: 8 additions & 0 deletions src/monocle_apptrace/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ def load_wrapper_from_config(config_file_path: str, module_name: str = None):
wrapper_method["span_name_getter"] = get_wrapper_method(
wrapper_method["span_name_getter_package"],
wrapper_method["span_name_getter_method"])
if "output_processor" in wrapper_method:
if type(wrapper_method["output_processor"]) is list:
output_processor_file_path = wrapper_method["output_processor"][0]
current_dir = os.path.dirname(os.path.abspath(__file__))
absolute_file_path = os.path.join(current_dir,output_processor_file_path)
if isinstance(output_processor_file_path, str):
with open(absolute_file_path, encoding='UTF-8') as op_file:
wrapper_method["output_processor"] = json.load(op_file)
return wrapper_methods

def get_wrapper_method(package_name: str, method_name: str):
Expand Down
Loading