-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c547be
commit 8ebf96b
Showing
7 changed files
with
909 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ | ||
{ | ||
"context_precision": 0, | ||
"context_recall": 0 | ||
} | ||
] |
Binary file not shown.
Binary file not shown.
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,57 @@ | ||
"""The metrics used to perform the RAG evaluation""" | ||
import re | ||
import json | ||
import textwrap | ||
from json import JSONDecodeError | ||
from dataclasses import dataclass | ||
from abc import ABC, abstractmethod | ||
|
||
import requests | ||
import numpy as np | ||
|
||
|
||
EVAL_PROMPTS = { | ||
'mistral': { | ||
'context_recall': { | ||
'sys': '', | ||
'usr': '' | ||
}, | ||
'context_precision': { | ||
'sys': '', | ||
'usr': '' | ||
} | ||
} | ||
} | ||
|
||
|
||
@dataclass | ||
class HuggingFaceLLM: | ||
"""Represents HuggingFace Inference Endpoint, it is used for convenience in performance of evaluation.""" | ||
url: str | ||
key: str | ||
|
||
def __post_init__(self): | ||
self.headers = {"Authorization": f"Bearer {self.key}", "Content-Type": "application/json"} | ||
|
||
def __query(self, payload): | ||
response = requests.post(self.url, headers=self.headers, json={'inputs': payload}) | ||
response.raise_for_status() | ||
return response.json() | ||
|
||
def query(self, messages: list): | ||
prompt = '\n'.join([msg['content'] for msg in messages]) | ||
return self.__query(prompt) | ||
|
||
|
||
@dataclass | ||
class Metric(ABC): | ||
"""Represents a RAG evaluation metric using LLM-as-a-judge paradigm""" | ||
system_prompt: str | ||
user_prompt: str | ||
llm_provider: HuggingFaceLLM | ||
|
||
@abstractmethod | ||
def compute(self, *args, **kwargs) -> float: | ||
"""Needs to be implemented to evaluate a metric""" | ||
pass | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.