-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathdummy_model.py
73 lines (60 loc) · 3.75 KB
/
dummy_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os
from typing import Any, Dict, List
from models.utils import trim_predictions_to_max_token_length
# Load the environment variable that specifies the URL of the MockAPI. This URL is essential
# for accessing the correct API endpoint in Task 2 and Task 3. The value of this environment variable
# may vary across different evaluation settings, emphasizing the importance of dynamically obtaining
# the API URL to ensure accurate endpoint communication.
# Please refer to https://gitlab.aicrowd.com/aicrowd/challenges/meta-comprehensive-rag-benchmark-kdd-cup-2024/crag-mock-api
# for more information on the MockAPI.
#
# **Note**: This environment variable will not be available for Task 1 evaluations.
CRAG_MOCK_API_URL = os.getenv("CRAG_MOCK_API_URL", "http://localhost:8000")
class DummyModel:
def __init__(self):
"""
Initialize your model(s) here if necessary.
This is the constructor for your DummyModel class, where you can set up any
required initialization steps for your model(s) to function correctly.
"""
pass
def get_batch_size(self) -> int:
"""
Determines the batch size that is used by the evaluator when calling the `batch_generate_answer` function.
Returns:
int: The batch size, an integer between 1 and 16. This value indicates how many
queries should be processed together in a single batch. It can be dynamic
across different batch_generate_answer calls, or stay a static value.
"""
self.batch_size = 4
return self.batch_size
def batch_generate_answer(self, batch: Dict[str, Any]) -> List[str]:
"""
Generates answers for a batch of queries using associated (pre-cached) search results and query times.
Parameters:
batch (Dict[str, Any]): A dictionary containing a batch of input queries with the following keys:
- 'interaction_id; (List[str]): List of interaction_ids for the associated queries
- 'query' (List[str]): List of user queries.
- 'search_results' (List[List[Dict]]): List of search result lists, each corresponding
to a query. Please refer to the following link for
more details about the individual search objects:
https://gitlab.aicrowd.com/aicrowd/challenges/meta-comprehensive-rag-benchmark-kdd-cup-2024/meta-comphrehensive-rag-benchmark-starter-kit/-/blob/master/docs/dataset.md#search-results-detail
- 'query_time' (List[str]): List of timestamps (represented as a string), each corresponding to when a query was made.
Returns:
List[str]: A list of plain text responses for each query in the batch. Each response is limited to 75 tokens.
If the generated response exceeds 75 tokens, it will be truncated to fit within this limit.
Notes:
- If the correct answer is uncertain, it's preferable to respond with "I don't know" to avoid
the penalty for hallucination.
- Response Time: Ensure that your model processes and responds to each query within 30 seconds.
Failing to adhere to this time constraint **will** result in a timeout during evaluation.
"""
batch_interaction_ids = batch["interaction_id"]
queries = batch["query"]
search_results = batch["search_results"]
query_times = batch["query_time"]
answers = []
for idx, query in enumerate(queries):
# Implement logic to generate answers based on search results and query times
answers.append("i don't know") # Default placeholder response
return answers