Skip to content

Commit

Permalink
remove unwanted code (#5)
Browse files Browse the repository at this point in the history
Co-authored-by: Ubuntu <[email protected]>
  • Loading branch information
RicLaiZA and Ubuntu authored Dec 16, 2024
1 parent 0bf181c commit 3768cfe
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 36 deletions.
1 change: 1 addition & 0 deletions psl_proof/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def load_config() -> Dict[str, Any]:
'input_dir': INPUT_DIR,
'salt': '5EkntCWI',
'validator_base_api_url': 'https://api.vana.genesis.dfusion.ai'
#'validator_base_api_url': 'https://07c8-169-0-170-105.ngrok-free.app'
}
logging.info(f"Using config: {json.dumps(config, indent=2)}")
return config
Expand Down
13 changes: 7 additions & 6 deletions psl_proof/models/cargo_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,17 @@ def to_verification_json(self) -> dict:
# ChatData for Source (final destination data structure)
@dataclass
class ChatData:
chat_id: int
chat_length: int

chat_start_on: datetime = None
chat_ended_on: datetime = None
sentiment: Dict[str, Any] = field(default_factory=dict)
keywords: Dict[str, Any] = field(default_factory=dict)

def to_dict(self):
return {
"chat_id": self.chat_id,
"chat_length": self.chat_length,
"chat_start_on": self.chat_start_on.isoformat(),
"chat_ended_on": self.chat_ended_on.isoformat(),
"sentiment": self.sentiment, # No need to call .to_dict() for dicts
"keywords": self.keywords, # Same for other dict fields
}
Expand All @@ -202,14 +203,14 @@ def to_dict(self):
class CargoData:
source_data: SourceData
source_id: str
chat_list: List[ChatData] = field(default_factory=list)
# chat_list: List[ChatData] = field(default_factory=list)

def to_dict(self):
# Return a dictionary representation of the CargoData object
return {
"source_data": self.source_data, # Assuming source_data can be serialized directly
"source_id": self.source_id,
"chat_list": [chat.to_dict() for chat in self.chat_list] # Convert each ChatData in the list to a dict
"source_id": self.source_id #,
#"chat_list": [chat.to_dict() for chat in self.chat_list] # Convert each ChatData in the list to a dict
}

@staticmethod
Expand Down
9 changes: 4 additions & 5 deletions psl_proof/proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def generate(self) -> ProofResponse:
print(f"verify_result: {verify_result}")
is_data_authentic = verify_result.is_valid
proof_failed_reason = verify_result.error_text

cargo_data = CargoData(
source_data = source_data,
source_id = source_user_hash_64
Expand Down Expand Up @@ -78,8 +78,7 @@ def generate(self) -> ProofResponse:
'did_score_content': False,
'source': source_data.source.name,
'revision': data_revision,
'submitted_on': current_datetime,
'chat_data': None
'submitted_on': current_datetime
}
self.proof_response.metadata = metadata
logging.info(f"ProofResponseAttributes: {json.dumps(self.proof_response.attributes, indent=2)}")
Expand Down Expand Up @@ -108,8 +107,8 @@ def generate(self) -> ProofResponse:
'did_score_content': True,
'source': source_data.source.name,
'revision': data_revision,
'submitted_on': current_datetime,
'chat_data': None
'submitted_on': current_datetime
#'chat_data': None #RL: No longer generate usesful data...
}
self.proof_response.metadata = metadata

Expand Down
25 changes: 16 additions & 9 deletions psl_proof/utils/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,18 @@ def get_historical_chats(

return chat_histories
except ValueError as e:
RuntimeError("Error parsing JSON response:", e)
return None
logging.error(f"Error during parsing Get_historical_chats status: {e}")
traceback.print_exc()
sys.exit(1)
else:
RuntimeError(f"Validation failed. Status code: {response.status_code}, Response: {response.text}")
return None

logging.error(f"Validation failed. Status code: {response.status_code}, Response: {response.text}")
traceback.print_exc()
sys.exit(1)
except requests.exceptions.RequestException as e:
RuntimeError("get_historical_chats:", e)
return None
logging.error("get_historical_chats:", e)
traceback.print_exc()
sys.exit(1)



def submit_data(
Expand All @@ -89,8 +92,12 @@ def submit_data(
response = requests.post(url, json=payload, headers=headers)

if response.status_code != 200:
RuntimeError(f"Submission failed. Status code: {response.status_code}, Response: {response.text}")
logging.error(f"Submission failed. Status code: {response.status_code}, Response: {response.text}")
traceback.print_exc()
sys.exit(1)


except requests.exceptions.RequestException as e:
RuntimeError("submit_data:", e)
logging.error("submit_data:", e)
traceback.print_exc()
sys.exit(1)
26 changes: 11 additions & 15 deletions psl_proof/utils/validate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ def validate_data(
source_data : SourceChatData = cargo_data.source_data
source_chats = source_data.source_chats

#Patrick_ToCheck score_threshold should be 0.5
score_threshold = 0.5
total_quality = 0.00
total_uniqueness = 0.00
chat_count = 0
Expand Down Expand Up @@ -87,19 +85,17 @@ def validate_data(
total_uniqueness += uniqueness

#print(f"source_contents: {source_contents}")
# if chat data has meaningful data...
if quality > score_threshold and uniqueness > score_threshold:
# Create a ChatData instance and add it to the list
chat_data = ChatData(
chat_id=source_chat.chat_id,
chat_length=contents_length
)
#print(f"chat_data: {chat_data}")
cargo_data.chat_list.append(
chat_data
)
else:
print(f"Extract data skiped - values are below threshold({score_threshold})")
#RL: No longer generate data for sentiment & keywords
# Create a ChatData instance and add it to the list
#chat_data = ChatData(
# chat_length=contents_length,
# chat_start_on = source_chat.chat_start_on,
# chat_ended_on = source_chat.chat_ended_on
#)
#print(f"chat_data: {chat_data}")
#cargo_data.chat_list.append(
# chat_data
#)

# Calculate uniqueness if there are chats
if chat_count > 0:
Expand Down
2 changes: 1 addition & 1 deletion psl_proof/utils/verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def verify_token(config: Dict[str, Any], source_data: SourceData) -> Optional[Ve
traceback.print_exc()
sys.exit(1)
else:
logging.error(f"Error, unexpected verification response: {e}")
logging.error(f"Error, unexpected verification response: Status code: {response.status_code}, Response: {response.text}")
traceback.print_exc()
sys.exit(1)

Expand Down

0 comments on commit 3768cfe

Please sign in to comment.