Skip to content

Commit

Permalink
Merge branch 'main' of github.com:SciPhi-AI/R2R into feature/api-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
NolanTrem committed Nov 12, 2024
2 parents 668ac9a + 22c0e26 commit da2514a
Show file tree
Hide file tree
Showing 71 changed files with 2,455 additions and 2,626 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ dist/
*.test
go.work
go.work.sum

.vscode/
24 changes: 23 additions & 1 deletion js/sdk/__tests__/r2rV2Client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ describe("R2RClient", () => {
const mockResponse = { success: true };
mockAxiosInstance.request.mockResolvedValue({ data: mockResponse });

const email = "test@example.com";
const verification_code = "123456";
const result = await client.verifyEmail(verification_code);
const result = await client.verifyEmail(email, verification_code);

expect(result).toEqual(mockResponse);
expect(mockAxiosInstance.request).toHaveBeenCalledWith({
Expand All @@ -113,6 +114,26 @@ describe("R2RClient", () => {
});
});

test("requestPasswordReset should send POST request to /request_password_reset with correct data", async () => {
const mockResponse = { success: true };
mockAxiosInstance.request.mockResolvedValue({ data: mockResponse });

const email = "test@example.com";
const result = await client.requestPasswordReset(email);

expect(result).toEqual(mockResponse);
expect(mockAxiosInstance.request).toHaveBeenCalledWith({
method: "POST",
url: "request_password_reset",
data: '"test@example.com"',
headers: {
"Content-Type": "application/json",
},
responseType: "json",
params: undefined,
});
});

test("logout should send POST request to /logout and clear tokens", async () => {
mockAxiosInstance.request.mockResolvedValue({ data: {} });

Expand Down Expand Up @@ -352,6 +373,7 @@ describe("R2RClient", () => {
documentId,
metadata,
run_with_orchestration,
undefined,
);

expect(result).toEqual(mockResponse);
Expand Down
9 changes: 8 additions & 1 deletion js/sdk/__tests__/r2rV2ClientIntegrationSuperUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let newCollectionId: string;
* X updateUser
* - refreshAccessToken
* X changePassword
* X requestPasswordReset
* - requestPasswordReset
* X confirmPasswordReset
* X deleteUser
* Ingestion:
Expand Down Expand Up @@ -71,6 +71,7 @@ let newCollectionId: string;
* - createConversation
* - addMessage
* X updateMessage
* X updateMessageMetadata
* X branchesOverview
* X getNextBranch
* X getPreviousBranch
Expand Down Expand Up @@ -240,6 +241,12 @@ describe("r2rClient Integration Tests", () => {
await expect(client.refreshAccessToken()).resolves.not.toThrow();
});

test("Request password reset", async () => {
await expect(
client.requestPasswordReset("admin@example.com"),
).resolves.not.toThrow();
});

test("Get analytics", async () => {
const filterCriteria: Record<string, any> | string = {
search_latencies: "search_latency",
Expand Down
9 changes: 8 additions & 1 deletion js/sdk/__tests__/r2rV2ClientIntegrationUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const baseUrl = "http://localhost:7272";
* - updateUser
* - refreshAccessToken
* - changePassword
* X requestPasswordReset
* - requestPasswordReset
* X confirmPasswordReset
* - deleteUser
* Ingestion:
Expand Down Expand Up @@ -67,6 +67,7 @@ const baseUrl = "http://localhost:7272";
* - createConversation
* - addMessage
* X updateMessage
* X updateMessageMetadata
* X branchesOverview
* X getNextBranch
* X getPreviousBranch
Expand Down Expand Up @@ -282,6 +283,12 @@ describe("r2rClient Integration Tests", () => {
).resolves.not.toThrow();
});

test("Request password reset", async () => {
await expect(
client.requestPasswordReset("newemail@example.com"),
).resolves.not.toThrow();
});

test("Delete User", async () => {
const currentUser = await client.user();
await expect(
Expand Down
2 changes: 1 addition & 1 deletion js/sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "r2r-js",
"version": "0.3.12",
"version": "0.3.15",
"description": "",
"main": "dist/index.js",
"browser": "dist/index.browser.js",
Expand Down
92 changes: 88 additions & 4 deletions js/sdk/src/r2rClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ export class r2rClient extends BaseClient {
* @deprecated Use `client.users.verifyEmail` instead.
*/
@feature("verifyEmail")
async verifyEmail(verification_code: string): Promise<any> {
async verifyEmail(email: string, verification_code: string): Promise<any> {
return await this._makeRequest("POST", "verify_email", {
data: { verification_code },
data: { email, verification_code },
});
}

Expand Down Expand Up @@ -322,8 +322,11 @@ export class r2rClient extends BaseClient {
*/
@feature("requestPasswordReset")
async requestPasswordReset(email: string): Promise<any> {
return this._makeRequest("POST", "request_password_reset", {
data: { email },
return await this._makeRequest("POST", "request_password_reset", {
data: JSON.stringify(email),
headers: {
"Content-Type": "application/json",
},
});
}

Expand Down Expand Up @@ -358,6 +361,17 @@ export class r2rClient extends BaseClient {
});
}

/**
* Generates a new verification code and sends a reset email to the user.
* @param email The email address of the user to send the reset email to.
* @returns A promise that resolves to the verification code and message from the server.
*/
@feature("sendResetEmail")
async sendResetEmail(email: string): Promise<Record<string, any>> {
return await this._makeRequest("POST", "send_reset_email", {
data: { email },
});
}
// -----------------------------------------------------------------------------
//
// Ingestion
Expand All @@ -380,6 +394,7 @@ export class r2rClient extends BaseClient {
document_ids?: string[];
user_ids?: (string | null)[];
ingestion_config?: Record<string, any>;
collection_ids?: string[];
run_with_orchestration?: boolean;
} = {},
): Promise<any> {
Expand Down Expand Up @@ -446,6 +461,9 @@ export class r2rClient extends BaseClient {
ingestion_config: options.ingestion_config
? JSON.stringify(options.ingestion_config)
: undefined,
collection_ids: options.collection_ids
? JSON.stringify(options.collection_ids)
: undefined,
run_with_orchestration:
options.run_with_orchestration != undefined
? String(options.run_with_orchestration)
Expand Down Expand Up @@ -488,6 +506,7 @@ export class r2rClient extends BaseClient {
document_ids: string[];
metadatas?: Record<string, any>[];
ingestion_config?: Record<string, any>;
collection_ids?: string[];
run_with_orchestration?: boolean;
},
): Promise<any> {
Expand Down Expand Up @@ -529,6 +548,9 @@ export class r2rClient extends BaseClient {
ingestion_config: options.ingestion_config
? JSON.stringify(options.ingestion_config)
: undefined,
collection_ids: options.collection_ids
? JSON.stringify(options.collection_ids)
: undefined,
run_with_orchestration:
options.run_with_orchestration != undefined
? String(options.run_with_orchestration)
Expand Down Expand Up @@ -572,12 +594,14 @@ export class r2rClient extends BaseClient {
documentId?: string,
metadata?: Record<string, any>,
run_with_orchestration?: boolean,
collection_ids?: string[],
): Promise<Record<string, any>> {
this._ensureAuthenticated();
let inputData: Record<string, any> = {
chunks: chunks,
document_id: documentId,
metadata: metadata,
collection_ids: collection_ids,
run_with_orchestration: run_with_orchestration,
};

Expand Down Expand Up @@ -1464,6 +1488,23 @@ export class r2rClient extends BaseClient {
});
}

/**
* Update the metadata of a message in an existing conversation.
* @param message_id The ID of the message to update.
* @param metadata The updated metadata.
* @returns A promise that resolves to the response from the server.
*/
@feature("updateMessageMetadata")
async updateMessageMetadata(
message_id: string,
metadata: Record<string, any>,
): Promise<Record<string, any>> {
this._ensureAuthenticated();
return this._makeRequest("PATCH", `messages/${message_id}/metadata`, {
data: metadata,
});
}

/**
* Get an overview of branches in a conversation.
* @param conversationId The ID of the conversation to get branches for.
Expand Down Expand Up @@ -1791,6 +1832,49 @@ export class r2rClient extends BaseClient {
//
// -----------------------------------------------------------------------------

/**
* Search over documents.
* @param query The query to search for.
* @param settings Settings for the document search.
* @returns A promise that resolves to the response from the server.
*/
@feature("searchDocuments")
async searchDocuments(
query: string,
settings?: {
searchOverMetadata?: boolean;
metadataKeys?: string[];
searchOverBody?: boolean;
filters?: Record<string, any>;
searchFilters?: Record<string, any>;
offset?: number;
limit?: number;
titleWeight?: number;
metadataWeight?: number;
},
): Promise<any> {
this._ensureAuthenticated();

const json_data: Record<string, any> = {
query,
settings: {
search_over_metadata: settings?.searchOverMetadata ?? true,
metadata_keys: settings?.metadataKeys ?? ["title"],
search_over_body: settings?.searchOverBody ?? false,
filters: settings?.filters ?? {},
search_filters: settings?.searchFilters ?? {},
offset: settings?.offset ?? 0,
limit: settings?.limit ?? 10,
title_weight: settings?.titleWeight ?? 0.5,
metadata_weight: settings?.metadataWeight ?? 0.5,
},
};

return await this._makeRequest("POST", "search_documents", {
data: json_data,
});
}

/**
* Conduct a vector and/or KG search.
* @param query The query to search for.
Expand Down
7 changes: 5 additions & 2 deletions py/cli/commands/ingestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,13 @@ async def update_files(
@click.option(
"--v2", is_flag=True, help="use aristotle_v2.txt (a smaller file)"
)
@click.option(
"--v3", is_flag=True, help="use aristotle_v3.txt (a larger file)"
)
@pass_context
async def ingest_sample_file(ctx, v2=False):
async def ingest_sample_file(ctx, v2=False, v3=False):
"""Ingest the first sample file into R2R."""
sample_file_url = f"https://raw.githubusercontent.com/SciPhi-AI/R2R/main/py/core/examples/data/aristotle{'_v2' if v2 else ''}.txt"
sample_file_url = f"https://raw.githubusercontent.com/SciPhi-AI/R2R/main/py/core/examples/data/aristotle{'_v2' if v2 else ''}{'_v3' if v3 else ''}.txt"
client = ctx.obj

with timer():
Expand Down
2 changes: 1 addition & 1 deletion py/cli/commands/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async def list_document_chunks(
for index, chunk in enumerate(chunks, 1):
click.echo(f"\nChunk {index}:")
if isinstance(chunk, dict):
click.echo(f"Extraction ID: {chunk.get('chunk_id', 'N/A')}")
click.echo(f"Extraction ID: {chunk.get('extraction_id', 'N/A')}")
click.echo(f"Text: {chunk.get('text', '')[:100]}...")
click.echo(f"Metadata: {chunk.get('metadata', {})}")
if include_vectors:
Expand Down
1 change: 1 addition & 0 deletions py/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"KGSearchSettings",
"VectorSearchResult",
"VectorSearchSettings",
"DocumentSearchSettings",
"HybridSearchSettings",
# User abstractions
"Token",
Expand Down
1 change: 1 addition & 0 deletions py/core/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"KGSearchSettings",
"VectorSearchResult",
"VectorSearchSettings",
"DocumentSearchSettings",
"HybridSearchSettings",
# KG abstractions
"KGCreationSettings",
Expand Down
3 changes: 3 additions & 0 deletions py/core/base/abstractions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
)
from shared.abstractions.graph import (
Community,
CommunityInfo,
CommunityReport,
Entity,
EntityLevel,
Expand Down Expand Up @@ -52,6 +53,7 @@
from shared.abstractions.prompt import Prompt
from shared.abstractions.search import (
AggregateSearchResult,
DocumentSearchSettings,
HybridSearchSettings,
KGCommunityResult,
KGEntityResult,
Expand Down Expand Up @@ -133,6 +135,7 @@
"KGSearchSettings",
"VectorSearchResult",
"VectorSearchSettings",
"DocumentSearchSettings",
"HybridSearchSettings",
# KG abstractions
"KGCreationSettings",
Expand Down
Loading

0 comments on commit da2514a

Please sign in to comment.