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

[draft] Metamodel entity changes #49

Closed

Conversation

sachintendulkar576123
Copy link
Contributor

Proposed changes

Added Attributes for Span Type Retrieval, Inference:

Updated wrap_common.py:

  • Modified the wrap_common.py file to include logic for updating attributes related to span type retrieval and inference.

Types of changes

What types of changes does your code introduce to this project?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

Signed-off-by: sachintendulkar576123 <[email protected]>
embed_model = self.instance.__dict__.get('_embed_model').__class__.__name__

# Fallback to None or specific default values if not found
# temperature = self.instance.__dict__.get("temperature", None)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented code can be removed if not needed, check other files as well

def __init__(self, instance):
self.instance = instance


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid consecutive new lines, single new line is generally enough
also have new line after all imports, and before beginning of classes and functions

please check other files as well for this consistency


model_name = resolve_from_alias(self.instance.__dict__, ["model", "model_name"])

span.set_attribute("entity.2.name", model_name)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you check if its possible to avoid hardcoding the entity index, 2 in this case

def __init__(self, instance):
self.instance = instance
def set_provider_name(self):
provider_url = ""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it needed, its setting to empty string

deployment_name = resolve_from_alias(self.instance.__dict__, ["engine", "azure_deployment",
"deployment_name", "deployment_id", "deployment"])
span.set_attribute("entity.1.name","AzureOpenAI")
span.set_attribute("entity.1.type", "inference.azure_oai")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entity name and type should not be hardcoded but deduced in this case
at least for the type you can refer existing code, how its differentiating between openai vs az_oai vs sagemaker etc

@oi-raanne I think we still have to look at name vs provider_name in this case, we were discussing in previous PR but didn't reach conclusion yet

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it has to be deduced

# Check if _vector_store exists and get its class name

span.set_attribute("entity.1.name", provider)
span.set_attribute("entity.1.type", "vectorstore.chroma")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see if type can be deduced instead of hardcoded, what if another vectorstore is used instead

# extract token uasge from langchain openai
if (response is not None and hasattr(response, "response_metadata")):
response_metadata = response.response_metadata
token_usage = response_metadata.get("token_usage")
d = {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid cryptic variable names

@@ -21,7 +25,7 @@
PROVIDER = "provider_name"
EMBEDDING_MODEL = "embedding_model"
VECTOR_STORE = 'vector_store'

META_DATA="meta_data"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

metadata is single word, underscore is not needed



def add_entities(self,span):
span.set_attribute("span_type","Inference")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the 'keys' that we are adding are in lower case, refer https://github.com/monocle2ai/monocle/blob/main/src/monocle_apptrace/metamodel/entities/entity_types.json

so it would be inference instead of Inference

@oi-raanne oi-raanne changed the title Metamodel entity changes [draft] Metamodel entity changes Oct 3, 2024

# Check if model_name is valid and set the attributes accordingly
if embed_model:
span.set_attribute("entity.2.name", embedding_model)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you accept the "2" string from constructor, hard coding it here could be problematic in future

# extract token uasge from langchain openai
if (response is not None and hasattr(response, "response_metadata")):
response_metadata = response.response_metadata
token_usage = response_metadata.get("token_usage")
d = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give this variable a self describing name

pass
def add_provider_attributes(self, span):
# Assuming the provider details are in instance.provider
provider_name = ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in python there is no need to initialize a variable twice.
Even if it declared inside the if statement, it can be used outside if statement as well.

@@ -85,9 +89,15 @@ def pre_task_processing(to_wrap, instance, args, span):
update_span_with_infra_name(span, INFRA_SERVICE_KEY)

#capture the tags attribute of the instance if present, else ignore
retreival = Retreival(instance)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling

@oi-raanne
Copy link
Contributor

no longer needed as the changes have been incorporated in #51

@oi-raanne oi-raanne closed this Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants