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

Feature/change default url #1738

Merged
merged 5 commits into from
Dec 29, 2024
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
10 changes: 9 additions & 1 deletion .github/workflows/r2r-light-py-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,15 @@ jobs:

- name: Run R2R Light Python Integration Test
run: |
cd py && poetry run pytest tests/ \
cd py && poetry run pytest tests/unit \
--verbose \
--capture=no \
--log-cli-level=INFO \
--junit-xml=test-results/junit.xml \
--html=test-results/report.html
- name: Run R2R Full Python Integration Test
run: |
cd py && poetry run pytest tests/integration \
--verbose \
--capture=no \
--log-cli-level=INFO \
Expand Down
6 changes: 4 additions & 2 deletions py/cli/command_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def format_help(self, ctx, formatter):

console.print("[bold cyan]Options:[/bold cyan]")
console.print(
" --base-url TEXT Base URL for the API [default: http://localhost:7272]"
" --base-url TEXT Base URL for the API [default: https://api.cloud.sciphi.ai]"
)
console.print(" --help Show this message and exit.\n")

Expand Down Expand Up @@ -167,7 +167,9 @@ def initialize_client(base_url: str) -> R2RAsyncClient:

@click.group(cls=CustomGroup)
@click.option(
"--base-url", default="http://localhost:7272", help="Base URL for the API"
"--base-url",
default="https://cloud.sciphi.ai",
help="Base URL for the API",
)
@pass_context
async def cli(ctx: click.Context, base_url: str) -> None:
Expand Down
1 change: 1 addition & 0 deletions py/cli/commands/retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ async def search(ctx: click.Context, query, **kwargs):

client: R2RAsyncClient = ctx.obj

print("client.base_url = ", client.base_url)
try:
with timer():
results = await client.retrieval.search(
Expand Down
12 changes: 6 additions & 6 deletions py/cli/commands/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,13 @@ def generate_report():
except subprocess.CalledProcessError as e:
report["docker_error"] = f"Error running Docker command: {e}"
except FileNotFoundError:
report[
"docker_error"
] = "Docker command not found. Is Docker installed and in PATH?"
report["docker_error"] = (
"Docker command not found. Is Docker installed and in PATH?"
)
except subprocess.TimeoutExpired:
report[
"docker_error"
] = "Docker command timed out. Docker might be unresponsive."
report["docker_error"] = (
"Docker command timed out. Docker might be unresponsive."
)

# Get OS information
report["os_info"] = {
Expand Down
62 changes: 53 additions & 9 deletions py/core/database/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,18 @@ class QueryBuilder:
def __init__(self, table_name: str):
self.table_name = table_name
self.conditions: list[str] = []
self.params: dict = {}
self.params: list = (
[]
) # Changed from dict to list for PostgreSQL $1, $2 style
self.select_fields = "*"
self.operation = "SELECT"
self.limit_value: Optional[int] = None
self.offset_value: Optional[int] = None
self.order_by_fields: Optional[str] = None
self.returning_fields: Optional[list[str]] = None
self.insert_data: Optional[dict] = None
self.update_data: Optional[dict] = None
self.param_counter = 1 # For generating $1, $2, etc.

def select(self, fields: list[str]):
self.select_fields = ", ".join(fields)
Expand All @@ -69,40 +76,77 @@ def insert(self, data: dict):
self.insert_data = data
return self

def update(self, data: dict):
self.operation = "UPDATE"
self.update_data = data
return self

def delete(self):
self.operation = "DELETE"
return self

def where(self, condition: str, **kwargs):
def where(self, condition: str):
self.conditions.append(condition)
self.params.update(kwargs)
return self

def limit(self, value: int):
def limit(self, value: Optional[str]):
self.limit_value = value
return self

def offset(self, value: str):
self.offset_value = value
return self

def order_by(self, fields: str):
self.order_by_fields = fields
return self

def returning(self, fields: list[str]):
self.returning_fields = fields
return self

def build(self):
if self.operation == "SELECT":
query = f"SELECT {self.select_fields} FROM {self.table_name}"

elif self.operation == "INSERT":
columns = ", ".join(self.insert_data.keys())
values = ", ".join(f":{key}" for key in self.insert_data.keys())
query = (
f"INSERT INTO {self.table_name} ({columns}) VALUES ({values})"
placeholders = ", ".join(
f"${i}" for i in range(1, len(self.insert_data) + 1)
)
self.params.update(self.insert_data)
query = f"INSERT INTO {self.table_name} ({columns}) VALUES ({placeholders})"
self.params.extend(list(self.insert_data.values()))

elif self.operation == "UPDATE":
set_clauses = []
for i, (key, value) in enumerate(
self.update_data.items(), start=len(self.params) + 1
):
set_clauses.append(f"{key} = ${i}")
self.params.append(value)
query = f"UPDATE {self.table_name} SET {', '.join(set_clauses)}"

elif self.operation == "DELETE":
query = f"DELETE FROM {self.table_name}"

else:
raise ValueError(f"Unsupported operation: {self.operation}")

if self.conditions:
query += " WHERE " + " AND ".join(self.conditions)

if self.limit_value is not None and self.operation == "SELECT":
if self.order_by_fields and self.operation == "SELECT":
query += f" ORDER BY {self.order_by_fields}"

if self.offset_value is not None:
query += f" OFFSET {self.offset_value}"

if self.limit_value is not None:
query += f" LIMIT {self.limit_value}"

if self.returning_fields:
query += f" RETURNING {', '.join(self.returning_fields)}"

return query, self.params


Expand Down
6 changes: 3 additions & 3 deletions py/core/database/chunks.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,9 @@ async def hybrid_search(
semantic_results: list[ChunkSearchResult] = await self.semantic_search(
query_vector, semantic_settings
)
full_text_results: list[
ChunkSearchResult
] = await self.full_text_search(query_text, full_text_settings)
full_text_results: list[ChunkSearchResult] = (
await self.full_text_search(query_text, full_text_settings)
)

semantic_limit = search_settings.limit
full_text_limit = search_settings.hybrid_settings.full_text_limit
Expand Down
6 changes: 3 additions & 3 deletions py/core/database/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ async def upsert_documents_overview(
else:
new_attempt_number = db_version

db_entry[
"ingestion_attempt_number"
] = new_attempt_number
db_entry["ingestion_attempt_number"] = (
new_attempt_number
)

update_query = f"""
UPDATE {self._get_table_name(PostgresDocumentsHandler.TABLE_NAME)}
Expand Down
6 changes: 3 additions & 3 deletions py/core/database/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ def __init__(
else:
self.top_level_columns = set(top_level_columns)
self.json_column = json_column
self.params: list[
Any
] = params # params are mutated during construction
self.params: list[Any] = (
params # params are mutated during construction
)
self.mode = mode

def build(self, expr: FilterExpression) -> Tuple[str, list[Any]]:
Expand Down
6 changes: 3 additions & 3 deletions py/core/database/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2505,9 +2505,9 @@ async def _compute_leiden_communities(
from graspologic.partition import hierarchical_leiden

if "random_seed" not in leiden_params:
leiden_params[
"random_seed"
] = 7272 # add seed to control randomness
leiden_params["random_seed"] = (
7272 # add seed to control randomness
)

start_time = time.time()
logger.info(
Expand Down
Loading
Loading