change logs repo
Browse files- climateqa/logging.py +25 -10
climateqa/logging.py
CHANGED
|
@@ -124,22 +124,37 @@ def serialize_docs(docs:list)->list:
|
|
| 124 |
|
| 125 |
## HUGGING FACE LOGGING
|
| 126 |
|
| 127 |
-
def log_on_huggingface(log_filename, logs):
|
| 128 |
"""Log data to Hugging Face dataset repository.
|
| 129 |
|
| 130 |
Args:
|
| 131 |
log_filename (str): Name of the file to store logs
|
| 132 |
logs (dict): Log data to store
|
|
|
|
| 133 |
"""
|
| 134 |
try:
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
| 140 |
|
| 141 |
-
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
# Initialize HfApi
|
| 145 |
api = HfApi(token=hf_token)
|
|
@@ -189,7 +204,7 @@ def log_interaction_to_huggingface(history, output_query, sources, docs, share_c
|
|
| 189 |
"time": timestamp,
|
| 190 |
}
|
| 191 |
# Log to Hugging Face
|
| 192 |
-
log_on_huggingface(f"chat/{timestamp}.json", logs)
|
| 193 |
print(f"Logged interaction to Hugging Face")
|
| 194 |
else:
|
| 195 |
print("Did not log to Hugging Face because GRADIO_ENV is local")
|
|
@@ -216,7 +231,7 @@ def log_drias_interaction_to_huggingface(query, sql_query, user_id):
|
|
| 216 |
"sql_query": sql_query,
|
| 217 |
"time": timestamp,
|
| 218 |
}
|
| 219 |
-
log_on_huggingface(f"drias/drias_{timestamp}.json", logs)
|
| 220 |
print(f"Logged Drias interaction to Hugging Face: {logs}")
|
| 221 |
else:
|
| 222 |
print("share_client or user_id is None, or GRADIO_ENV is local")
|
|
|
|
| 124 |
|
| 125 |
## HUGGING FACE LOGGING
|
| 126 |
|
| 127 |
+
def log_on_huggingface(log_filename, logs, log_type="chat"):
|
| 128 |
"""Log data to Hugging Face dataset repository.
|
| 129 |
|
| 130 |
Args:
|
| 131 |
log_filename (str): Name of the file to store logs
|
| 132 |
logs (dict): Log data to store
|
| 133 |
+
log_type (str): Type of log to store
|
| 134 |
"""
|
| 135 |
try:
|
| 136 |
+
if log_type =="chat":
|
| 137 |
+
# Get Hugging Face token from environment
|
| 138 |
+
hf_token = os.getenv("HF_LOGS_TOKEN")
|
| 139 |
+
if not hf_token:
|
| 140 |
+
print("HF_LOGS_TOKEN not found in environment variables")
|
| 141 |
+
return
|
| 142 |
|
| 143 |
+
# Get repository name from environment or use default
|
| 144 |
+
repo_id = os.getenv("HF_DATASET_REPO", "Ekimetrics/climateqa_logs")
|
| 145 |
+
|
| 146 |
+
elif log_type =="drias":
|
| 147 |
+
# Get Hugging Face token from environment
|
| 148 |
+
hf_token = os.getenv("HF_LOGS_DRIAS_TOKEN")
|
| 149 |
+
if not hf_token:
|
| 150 |
+
print("HF_LOGS_DRIAS_TOKEN not found in environment variables")
|
| 151 |
+
return
|
| 152 |
+
|
| 153 |
+
# Get repository name from environment or use default
|
| 154 |
+
repo_id = os.getenv("HF_DATASET_REPO_DRIAS", "Ekimetrics/climateqa_logs_talk_to_data")
|
| 155 |
+
|
| 156 |
+
else:
|
| 157 |
+
raise ValueError(f"Invalid log type: {log_type}")
|
| 158 |
|
| 159 |
# Initialize HfApi
|
| 160 |
api = HfApi(token=hf_token)
|
|
|
|
| 204 |
"time": timestamp,
|
| 205 |
}
|
| 206 |
# Log to Hugging Face
|
| 207 |
+
log_on_huggingface(f"chat/{timestamp}.json", logs, log_type="chat")
|
| 208 |
print(f"Logged interaction to Hugging Face")
|
| 209 |
else:
|
| 210 |
print("Did not log to Hugging Face because GRADIO_ENV is local")
|
|
|
|
| 231 |
"sql_query": sql_query,
|
| 232 |
"time": timestamp,
|
| 233 |
}
|
| 234 |
+
log_on_huggingface(f"drias/drias_{timestamp}.json", logs, log_type="drias")
|
| 235 |
print(f"Logged Drias interaction to Hugging Face: {logs}")
|
| 236 |
else:
|
| 237 |
print("share_client or user_id is None, or GRADIO_ENV is local")
|