Skip to content

Commit

Permalink
Merge branch 'main' into adil/use_docker_cli
Browse files Browse the repository at this point in the history
  • Loading branch information
adilhafeez committed Feb 15, 2025
2 parents ae4a0a5 + 2f6c434 commit 31c4ec8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 36 deletions.
2 changes: 1 addition & 1 deletion demos/shared/jaeger/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM jaegertracing/all-in-one:1.62.0
FROM jaegertracing/jaeger:2.3.0
HEALTHCHECK \
--interval=1s \
--timeout=1s \
Expand Down
44 changes: 26 additions & 18 deletions model_server/src/core/utils/hallucination_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MaskToken(Enum):
},
MaskToken.PARAMETER_VALUE.value: {
"entropy": 0.28,
"varentropy": 1.2,
"varentropy": 1.4,
"probability": 0.8,
},
}
Expand All @@ -60,7 +60,7 @@ def check_threshold(entropy: float, varentropy: float, thd: Dict) -> bool:
thd (dict): A dictionary containing the threshold values with keys 'entropy' and 'varentropy'.
Returns:
bool: True if either the entropy or varentropy exceeds their respective thresholds, False otherwise.
bool: True if both the entropy and varentropy exceeds their respective thresholds, False otherwise.
"""
return entropy > thd["entropy"] and varentropy > thd["varentropy"]

Expand All @@ -82,7 +82,7 @@ def calculate_uncertainty(log_probs: List[float]) -> Tuple[float, float]:
token_probs = torch.exp(log_probs)
entropy = -torch.sum(log_probs * token_probs, dim=-1) / math.log(2, math.e)
varentropy = torch.sum(
token_probs * (log_probs / math.log(2, math.e)) + entropy.unsqueeze(-1) ** 2,
token_probs * (log_probs / math.log(2, math.e) + entropy.unsqueeze(-1)) ** 2,
dim=-1,
)
return entropy.item(), varentropy.item(), token_probs[0].item()
Expand Down Expand Up @@ -303,22 +303,30 @@ def _process_token(self):
self.mask.append(MaskToken.PARAMETER_VALUE)

# checking if the parameter doesn't have enum and the token is the first parameter value token
if (
len(self.mask) > 1
and self.mask[-2] != MaskToken.PARAMETER_VALUE
and is_parameter_required(
self.function_properties[self.function_name],
self.parameter_name[-1],
# check if function name is in function properties
if self.function_name in self.function_properties:
if (
len(self.mask) > 1
and self.mask[-2] != MaskToken.PARAMETER_VALUE
and is_parameter_required(
self.function_properties[self.function_name],
self.parameter_name[-1],
)
and not is_parameter_property(
self.function_properties[self.function_name],
self.parameter_name[-1],
"enum",
)
):
if self.parameter_name[-1] not in self.check_parameter_name:
self._check_logprob()
self.check_parameter_name[self.parameter_name[-1]] = True
else:
self._check_logprob()
self.error_message = f"Function name {self.function_name} not found in function properties"
logger.warning(
f"Function name {self.function_name} not found in function properties"
)
and not is_parameter_property(
self.function_properties[self.function_name],
self.parameter_name[-1],
"enum",
)
):
if self.parameter_name[-1] not in self.check_parameter_name:
self._check_logprob()
self.check_parameter_name[self.parameter_name[-1]] = True
else:
self.mask.append(MaskToken.NOT_USED)
# if the state is parameter value and the token is an end token, change the state
Expand Down
15 changes: 0 additions & 15 deletions model_server/tests/core/test_function_calling.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,6 @@ def get_hallucination_data_complex():
return req, True, True, True


def get_hallucination_data_easy():
# Create instances of the Message class
message1 = Message(role="user", content="How is the weather in Seattle?")

# Create a list of tools
tools = [get_weather_api]

# Create an instance of the ChatMessage class
req = ChatMessage(messages=[message1], tools=tools)

# model will hallucinate
return req, True, True, True


def get_hallucination_data_medium():
# Create instances of the Message class
message1 = Message(role="user", content="How is the weather in?")
Expand Down Expand Up @@ -142,7 +128,6 @@ def get_greeting_data():
"get_data_func",
[
get_hallucination_data_complex,
get_hallucination_data_easy,
get_complete_data,
get_irrelevant_data,
get_complete_data_2,
Expand Down
4 changes: 2 additions & 2 deletions tests/modelserver/test_hallucination_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ test_cases:
- role: "assistant"
content: "Can you please provide me the days for the weather forecast?"
- role: "user"
content: "los angeles in 5 days"
content: "5 days"
tools:
- type: "function"
function:
Expand All @@ -82,7 +82,7 @@ test_cases:
required: ["location", "days"]
expected:
- type: "metadata"
hallucination: true
hallucination: false

- id: "[WEATHER AGENT] - multi turn, single tool, clarification"
input:
Expand Down

0 comments on commit 31c4ec8

Please sign in to comment.