Skip to content

Instantly share code, notes, and snippets.

View vndee's full-sized avatar
🎯
Focusing

Duy Huynh vndee

🎯
Focusing
View GitHub Profile
@vndee
vndee / cleanup.sh
Created May 20, 2025 03:07
My mac cleanup utilities.
#!/bin/bash
# Colors for better output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to show help
col1, col2, col3, col4, col5 = st.columns(5)
with col1:
st.markdown(f"""
<div class='metric-container'>
<div class='metric-value'>{max_width}</div>
<div class='metric-label'>Search Width</div>
</div>
""", unsafe_allow_html=True)
# Create tabs for results and reasoning process
result_tab, process_tab, viz_tab = st.tabs(["Answer", "Reasoning Process", "Graph Visualization"])
with result_tab:
st.markdown("### Answer")
# Display the final answer...
with process_tab:
st.markdown("### Reasoning Steps")
# Show detailed reasoning steps...
def rank_relations(self, query: str, entity_name: str, relations: List[Dict]) -> List[Dict]:
"""Rank relations by their relevance to the query"""
relation_info = '\n'.join([
f"- {rel['relation_name']} (connects {entity_name} to {rel['target_name']})"
for rel in relations
])
# Craft a prompt that asks the LLM to evaluate relations
system_prompt = """
You are an expert knowledge graph reasoner. Your task is to:
def iterative_reasoning(self, query: str) -> Tuple[List[Dict], str]:
# Initialize tracking variables
reasoning_steps = []
visited_entities = set()
# Step 1: Initial Topic Entities
topic_entities = self.identify_topic_entities(query)
visited_entities.update(topic_entities)
# Initial document retrieval
class KnowledgeGraph:
def __init__(self, model=None):
self.entities = {}
self.relations = {}
self.triples = []
self.documents = {}
self.model = model
self.llm = None
def get_relation_candidates(self, entity_id: str) -> List[Dict]:
# Simplified pseudocode for ToG reasoning loop
for depth in range(max_depth):
# Explore the knowledge graph
related_entities = explore_connections(current_entities, query)
# Retrieve and evaluate contextual information
context_information = retrieve_contexts(related_entities)
# Evaluate whether we have sufficient information
if has_sufficient_information(context_information, query):
@vndee
vndee / rds_06.py
Last active December 26, 2024 17:03
from redis_data_structures import PriorityQueue
from enum import IntEnum
class TaskPriority(IntEnum):
CRITICAL = 1
HIGH = 2
MEDIUM = 3
LOW = 4
class TaskScheduler:
@vndee
vndee / rds_05.py
Last active December 26, 2024 17:02
from redis_data_structures import RingBuffer
from datetime import datetime, timedelta
class RateLimiter:
def __init__(self, window_size: int, max_requests: int):
self.buffer = RingBuffer("rate-limits", capacity=max_requests)
self.window_size = window_size
def is_allowed(self, client_id: str) -> bool:
key = f"rate_limit:{client_id}"
from redis_data_structures import ConnectionManager
from datetime import timedelta
conn = ConnectionManager(
host='redis.example.com',
max_connections=20,
retry_max_attempts=5,
circuit_breaker_threshold=10,
circuit_breaker_timeout=timedelta(minutes=5),
ssl=True