This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from redis_data_structures import PriorityQueue | |
from enum import IntEnum | |
class TaskPriority(IntEnum): | |
CRITICAL = 1 | |
HIGH = 2 | |
MEDIUM = 3 | |
LOW = 4 | |
class TaskScheduler: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder