Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(QueryExecTracker): store and get last log id from query tracker #733

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pandasai/agent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,7 @@ def last_reasoning(self):
@property
def last_answer(self):
return self._lake.last_answer

@property
def last_query_log_id(self):
return self._lake.last_query_log_id
21 changes: 19 additions & 2 deletions pandasai/helpers/query_exec_tracker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import base64
import json
import os
import time
from typing import Any, List, TypedDict, Union
import uuid

import requests
from collections import defaultdict
Expand Down Expand Up @@ -30,6 +32,7 @@ class QueryExecTracker:
_func_exec_count: dict
_success: bool
_server_config: dict
_last_log_id: int

def __init__(
self,
Expand All @@ -51,7 +54,11 @@ def set_related_query(self, flag: bool):
self._is_related_query = flag

def add_query_info(
self, conversation_id: str, instance: str, query: str, output_type: str
self,
conversation_id: uuid.UUID,
instance: str,
query: str,
output_type: str,
):
"""
Adds query information for new track
Expand All @@ -62,7 +69,7 @@ def add_query_info(
output_type (str): output type expected by user
"""
self._query_info = {
"conversation_id": conversation_id,
"conversation_id": str(conversation_id),
"instance": instance,
"query": query,
"output_type": output_type,
Expand All @@ -73,6 +80,7 @@ def start_new_track(self):
"""
Resets tracking variables to start new track
"""
self._last_log_id = None
self._start_time = time.time()
self._dataframes: List = []
self._response: ResponseType = {}
Expand Down Expand Up @@ -267,6 +275,11 @@ def publish(self) -> None:
if response.status_code != 200:
raise Exception(response.text)

json_data = json.loads(response.text)

if "data" in json_data and json_data["data"] is not None:
self._last_log_id = json_data["data"]["log_id"]

except Exception as e:
print(f"Exception in APILogger: {e}")

Expand All @@ -277,3 +290,7 @@ def success(self) -> bool:
@success.setter
def success(self, value: bool):
self._success = value

@property
def last_log_id(self) -> int:
return self._last_log_id
4 changes: 4 additions & 0 deletions pandasai/smart_dataframe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,10 @@ def last_answer(self):
def sample_head(self, sample_head: pd.DataFrame):
self._sample_head = sample_head.to_csv(index=False)

@property
def last_query_log_id(self):
return self._lake.last_query_log_id

def __getattr__(self, name):
if name in self._core.__dir__():
return getattr(self._core, name)
Expand Down
4 changes: 4 additions & 0 deletions pandasai/smart_datalake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,3 +777,7 @@ def memory(self):
@property
def instance(self):
return self._instance

@property
def last_query_log_id(self):
return self._query_exec_tracker.last_log_id