Spaces:
Sleeping
Sleeping
simplify data population
Browse files
task_specific_data_population.py
CHANGED
@@ -7,7 +7,7 @@ import json_repair
|
|
7 |
class DataPopulation:
|
8 |
def __init__(self, api_key):
|
9 |
# Set the API key during initialization
|
10 |
-
self.client = OpenAI(api_key=
|
11 |
self.conversation = [
|
12 |
{
|
13 |
"role": "system",
|
@@ -27,7 +27,6 @@ class DataPopulation:
|
|
27 |
}
|
28 |
]
|
29 |
|
30 |
-
|
31 |
def fetch_huggingface_dataset(self, dataset_name):
|
32 |
"""Fetch the dataset from Hugging Face."""
|
33 |
return load_dataset(dataset_name)
|
@@ -62,41 +61,24 @@ class DataPopulation:
|
|
62 |
self.conversation.append({
|
63 |
"role": "user",
|
64 |
"content": (
|
65 |
-
f"Given the task: '{task}' and the following page details:\n{relevant_page_details}\n\n"
|
66 |
-
"
|
67 |
-
"
|
68 |
-
"
|
69 |
-
"
|
70 |
-
"4. Confirm that both 'features' and 'user_data' are dictionaries.\n"
|
71 |
-
"5. Verify that every page includes exactly the three required keys: 'page_name', 'features', and 'user_data'."
|
72 |
-
"6. Make sure 'user_data' must exist as a key! "
|
73 |
)
|
74 |
})
|
75 |
response_content = self.gpt4_chat(self.conversation)
|
76 |
return response_content
|
77 |
|
78 |
-
def ask_to_update_sitemap(self, sitemap, new_page):
|
79 |
-
"""Update the sitemap with the new page and adjust links."""
|
80 |
-
self.conversation.append({
|
81 |
-
"role": "user",
|
82 |
-
"content": (
|
83 |
-
f"Given the current sitemap:\n{sitemap}\nand a new page: '{new_page}' (currently only has a 'uid'), update the sitemap by:\n"
|
84 |
-
"- Adding necessary details to '{new_page}', including 'links_to'.\n"
|
85 |
-
"- Updating 'links_to' in other relevant pages to include '{new_page}'.\n"
|
86 |
-
"Ensure the output retains the exact structure of the input."
|
87 |
-
)
|
88 |
-
})
|
89 |
-
response_sitemap = self.gpt4_chat(self.conversation)
|
90 |
-
return json_repair.loads(response_sitemap)
|
91 |
-
|
92 |
def ask_to_update_user_state(self, task, user_state):
|
93 |
"""Update the user state based on the task."""
|
94 |
self.conversation.append({
|
95 |
"role": "user",
|
96 |
"content": (
|
97 |
-
f"Given the task: '{task}'
|
98 |
-
"
|
99 |
-
"
|
100 |
)
|
101 |
})
|
102 |
response_content = self.gpt4_chat(self.conversation)
|
|
|
7 |
class DataPopulation:
|
8 |
def __init__(self, api_key):
|
9 |
# Set the API key during initialization
|
10 |
+
self.client = OpenAI(api_key=openai_api_key)
|
11 |
self.conversation = [
|
12 |
{
|
13 |
"role": "system",
|
|
|
27 |
}
|
28 |
]
|
29 |
|
|
|
30 |
def fetch_huggingface_dataset(self, dataset_name):
|
31 |
"""Fetch the dataset from Hugging Face."""
|
32 |
return load_dataset(dataset_name)
|
|
|
61 |
self.conversation.append({
|
62 |
"role": "user",
|
63 |
"content": (
|
64 |
+
f"Given the task: '{task}' and the following task-relevant page details:\n{relevant_page_details}\n\n"
|
65 |
+
f"Update each page's 'user_data' field with essential information for task-completion."
|
66 |
+
f"Do not modify the other fields"
|
67 |
+
"Output should maintain the exact input structure, making changes only to 'user_data' where required."
|
68 |
+
"'user_data' must exists as a key in each page.\n"
|
|
|
|
|
|
|
69 |
)
|
70 |
})
|
71 |
response_content = self.gpt4_chat(self.conversation)
|
72 |
return response_content
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
def ask_to_update_user_state(self, task, user_state):
|
75 |
"""Update the user state based on the task."""
|
76 |
self.conversation.append({
|
77 |
"role": "user",
|
78 |
"content": (
|
79 |
+
f"Given the task: '{task}', default user state:\n{user_state}, and user_data in chat history.\n\n"
|
80 |
+
"Initialize the user state values to reflect any initial status necessary for completing the task. "
|
81 |
+
"Output should maintain the exact input structure."
|
82 |
)
|
83 |
})
|
84 |
response_content = self.gpt4_chat(self.conversation)
|