Skip to content

Commit

Permalink
Merge pull request #1694 from SciPhi-AI/feature/merge-with-nolan
Browse files Browse the repository at this point in the history
merge in nolan + main
  • Loading branch information
emrgnt-cmplxty authored Dec 14, 2024
2 parents 6299856 + 9e2d556 commit 6ec5404
Show file tree
Hide file tree
Showing 31 changed files with 302 additions and 142 deletions.
7 changes: 0 additions & 7 deletions js/sdk/__tests__/ConversationsIntegrationSuperUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ describe("r2rClient V3 Collections Integration Tests", () => {
// expect(response.results).toBeDefined();
// });

test("List branches in a conversation", async () => {
const response = await client.conversations.listBranches({
id: conversationId,
});
expect(response.results).toBeDefined();
});

test("Delete a conversation", async () => {
const response = await client.conversations.delete({ id: conversationId });
expect(response.results).toBeDefined();
Expand Down
34 changes: 32 additions & 2 deletions js/sdk/__tests__/DocumentsAndCollectionsIntegrationUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe("r2rClient V3 System Integration Tests User", () => {
});

test("Register user 1", async () => {
const response = await client.users.register({
const response = await client.users.create({
email: "user_1@example.com",
password: "change_me_immediately",
});
Expand All @@ -52,7 +52,7 @@ describe("r2rClient V3 System Integration Tests User", () => {
});

test("Register user 2", async () => {
const response = await client.users.register({
const response = await client.users.create({
email: "user_2@example.com",
password: "change_me_immediately",
});
Expand Down Expand Up @@ -160,6 +160,36 @@ describe("r2rClient V3 System Integration Tests User", () => {
expect(Array.isArray(response.results)).toBe(true);
});

test("List document chunks as user 1", async () => {
const response = await user1Client.documents.listChunks({
id: user1DocumentId,
});

expect(response.results).toBeDefined();
expect(Array.isArray(response.results)).toBe(true);
});

test("List document chunks as user 2", async () => {
const response = await user2Client.documents.listChunks({
id: user2DocumentId,
});

expect(response.results).toBeDefined();
expect(Array.isArray(response.results)).toBe(true);
});

test("User 2 should not be able to list user 1's document chunks", async () => {
await expect(
user2Client.documents.listChunks({ id: user1DocumentId }),
).rejects.toThrow(/Status 403/);
});

test("User 1 should not be able to list user 2's document chunks", async () => {
await expect(
user1Client.documents.listChunks({ id: user2DocumentId }),
).rejects.toThrow(/Status 403/);
});

test("Delete document as user 1", async () => {
const response = await user1Client.documents.delete({
id: user1DocumentId,
Expand Down
4 changes: 3 additions & 1 deletion js/sdk/__tests__/GraphsIntegrationSuperUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ describe("r2rClient V3 Graphs Integration Tests", () => {
expect(response.results.subject).toBe("Razumikhin");
expect(response.results.object).toBe("Dunia");
expect(response.results.predicate).toBe("falls in love with");
expect(response.results.description).toBe("Razumikhn and Dunia are central to the story");
expect(response.results.description).toBe(
"Razumikhn and Dunia are central to the story",
);
});

test("Retrieve the relationship", async () => {
Expand Down
5 changes: 0 additions & 5 deletions js/sdk/__tests__/SystemIntegrationSuperUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ describe("r2rClient V3 Collections Integration Tests", () => {
expect(response.results).toBeDefined();
});

test("Get system logs", async () => {
const response = await client.system.logs({});
expect(response.results).toBeDefined();
});

test("Get the settings of the system", async () => {
const response = await client.system.settings();
expect(response.results).toBeDefined();
Expand Down
11 changes: 5 additions & 6 deletions js/sdk/__tests__/SystemIntegrationUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ describe("r2rClient V3 System Integration Tests User", () => {
});

test("Register a new user", async () => {
const response = await client.users.register({
const response = await client.users.create({
email: "system_integration_test_user@example.com",
password: "change_me_immediately",
name: "Test User",
bio: "This is the bio of the test user.",
});

userId = response.results.id;
name = response.results.name;
expect(response.results).toBeDefined();
expect(response.results.is_superuser).toBe(false);
expect(response.results.name).toBe(null);
expect(response.results.name).toBe("Test User");
expect(response.results.bio).toBe("This is the bio of the test user.");
});

test("Login as a user", async () => {
Expand All @@ -38,10 +41,6 @@ describe("r2rClient V3 System Integration Tests User", () => {
expect(response.results).toBeDefined();
});

test("Only a superuser can call the `system/logs` endpoint.", async () => {
await expect(client.system.logs({})).rejects.toThrow(/Status 403/);
});

test("Only a superuser can call the `system/settings` endpoint.", async () => {
await expect(client.system.settings()).rejects.toThrow(/Status 403/);
});
Expand Down
2 changes: 1 addition & 1 deletion js/sdk/__tests__/UsersIntegrationSuperUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("r2rClient V3 Users Integration Tests", () => {
});

test("Register a new user", async () => {
const response = await client.users.register({
const response = await client.users.create({
email: "new_user@example.com",
password: "change_me_immediately",
});
Expand Down
8 changes: 0 additions & 8 deletions js/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,6 @@ export interface CombinedSearchResponse {
}

// System types
export interface LogsResponse {
run_id: string;
run_type: string;
entries: Record<string, any>[];
timestamp?: string;
user_id?: string;
}

export interface ServerStats {
start_time: string;
Expand Down Expand Up @@ -371,7 +364,6 @@ export type WrappedSearchResponse = ResultsWrapper<CombinedSearchResponse>;

// System Responses
export type WrappedSettingsResponse = ResultsWrapper<SettingsResponse>;
export type WrappedLogsResponse = PaginatedResultsWrapper<LogsResponse[]>;
export type WrappedServerStatsResponse = ResultsWrapper<ServerStats>;

// User Responses
Expand Down
10 changes: 1 addition & 9 deletions js/sdk/src/v3/clients/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,13 @@ export class ConversationsClient {
/**
* Get detailed information about a specific conversation.
* @param id The ID of the conversation to retrieve
* @param branchID The ID of the branch to retrieve
* @returns
*/
@feature("conversations.retrieve")
async retrieve(options: {
id: string;
branchID?: string;
}): Promise<WrappedConversationMessagesResponse> {
const params: Record<string, any> = {
branchID: options.branchID,
};

return this.client.makeRequest("GET", `conversations/${options.id}`, {
params,
});
return this.client.makeRequest("GET", `conversations/${options.id}`);
}

/**
Expand Down
6 changes: 0 additions & 6 deletions js/sdk/src/v3/clients/retrieval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export class RetrievalClient {
* - Customizable generation parameters for response style and length
* - Source document citation with optional title inclusion
* - Streaming support for real-time responses
* - Branch management for exploring different conversation paths
*
* Common Use Cases:
* - Research assistance and literature review
Expand All @@ -157,7 +156,6 @@ export class RetrievalClient {
* @param taskPromptOverride Optional custom prompt to override default
* @param includeTitleIfAvailable Include document titles in responses when available
* @param conversationId ID of the conversation
* @param branchId ID of the conversation branch
* @returns
*/
@feature("retrieval.agent")
Expand All @@ -169,7 +167,6 @@ export class RetrievalClient {
taskPromptOverride?: string;
includeTitleIfAvailable?: boolean;
conversationId?: string;
branchId?: string;
}): Promise<any | AsyncGenerator<string, void, unknown>> {
const data: Record<string, any> = {
message: options.message,
Expand All @@ -191,9 +188,6 @@ export class RetrievalClient {
...(options.conversationId && {
conversation_id: options.conversationId,
}),
...(options.branchId && {
branch_id: options.branchId,
}),
};

if (options.ragGenerationConfig && options.ragGenerationConfig.stream) {
Expand Down
24 changes: 0 additions & 24 deletions js/sdk/src/v3/clients/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { feature } from "../../feature";
import { r2rClient } from "../../r2rClient";
import {
WrappedGenericMessageResponse,
WrappedLogsResponse,
WrappedServerStatsResponse,
WrappedSettingsResponse,
} from "../../types";
Expand All @@ -18,29 +17,6 @@ export class SystemClient {
return await this.client.makeRequest("GET", "health");
}

/**
* Get logs from the server.
* @param options
* @returns
*/
@feature("system.logs")
async logs(options: {
runTypeFilter?: string;
offset?: number;
limit?: number;
}): Promise<WrappedLogsResponse> {
const params: Record<string, any> = {
offset: options.offset ?? 0,
limit: options.limit ?? 100,
};

if (options.runTypeFilter) {
params.runTypeFilter = options.runTypeFilter;
}

return this.client.makeRequest("GET", "system/logs", { params });
}

/**
* Get the configuration settings for the R2R server.
* @returns
Expand Down
35 changes: 34 additions & 1 deletion js/sdk/src/v3/clients/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,44 @@ import {
export class UsersClient {
constructor(private client: r2rClient) {}

/**
* Create a new user.
* @param email User's email address
* @param password User's password
* @param name The name for the new user
* @param bio The bio for the new user
* @param profilePicture The profile picture for the new user
* @returns WrappedUserResponse
*/
@feature("users.create")
async create(options: {
email: string;
password: string;
name?: string;
bio?: string;
profilePicture?: string;
}): Promise<WrappedUserResponse> {
const data = {
...(options.email && { email: options.email }),
...(options.password && { password: options.password }),
...(options.name && { name: options.name }),
...(options.bio && { bio: options.bio }),
...(options.profilePicture && {
profile_picture: options.profilePicture,
}),
};

return this.client.makeRequest("POST", "users", {
data: data,
});
}

/**
* Register a new user.
* @param email User's email address
* @param password User's password
* @returns
* @returns WrappedUserResponse
* @deprecated Use `client.users.create` instead.
*/
@feature("users.register")
async register(options: {
Expand Down
4 changes: 2 additions & 2 deletions py/cli/commands/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ def users():
@click.argument("email", required=True, type=str)
@click.argument("password", required=True, type=str)
@pass_context
async def register(ctx, email, password):
async def create(ctx, email, password):
"""Create a new user."""
client: R2RAsyncClient = ctx.obj

with timer():
response = await client.users.register(email=email, password=password)
response = await client.users.create(email=email, password=password)

click.echo(json.dumps(response, indent=2))

Expand Down
23 changes: 12 additions & 11 deletions py/core/database/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2062,7 +2062,7 @@ async def delete_graph_for_collection(

# don't delete if status is PROCESSING.
QUERY = f"""
SELECT graph_cluster_status FROM {self._get_table_name("collections")} WHERE collection_id = $1
SELECT graph_cluster_status FROM {self._get_table_name("collections")} WHERE id = $1
"""
status = (
await self.connection_manager.fetch_query(QUERY, [collection_id])
Expand Down Expand Up @@ -2103,19 +2103,20 @@ async def delete_graph_for_collection(
QUERY, [KGExtractionStatus.PENDING, collection_id]
)

for query in DELETE_QUERIES:
if "community" in query or "graphs_entities" in query:
await self.connection_manager.execute_query(
query, [collection_id]
)
else:
await self.connection_manager.execute_query(
query, [document_ids]
)
if document_ids:
for query in DELETE_QUERIES:
if "community" in query or "graphs_entities" in query:
await self.connection_manager.execute_query(
query, [collection_id]
)
else:
await self.connection_manager.execute_query(
query, [document_ids]
)

# set status to PENDING for this collection.
QUERY = f"""
UPDATE {self._get_table_name("collections")} SET graph_cluster_status = $1 WHERE collection_id = $2
UPDATE {self._get_table_name("collections")} SET graph_cluster_status = $1 WHERE id = $2
"""
await self.connection_manager.execute_query(
QUERY, [KGExtractionStatus.PENDING, collection_id]
Expand Down
2 changes: 1 addition & 1 deletion py/core/examples/scripts/test_v3_sdk/test_v3_sdk_chunks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def generate_random_email():

# First create and authenticate a user if not already done
try:
new_user = client.users.register(
new_user = client.users.create(
email=user_email, password="new_secure_password123"
)
print("New user created:", new_user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# First create and authenticate a user if not already done
try:
new_user = client.users.register(
new_user = client.users.create(
email=user_email, password="new_secure_password123"
)
print("New user created:", new_user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# First create and authenticate a user if not already done
try:
new_user = client.users.register(
new_user = client.users.create(
email=user_email, password="new_secure_password123"
)
print("New user created:", new_user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# First create and authenticate a user if not already done
try:
new_user = client.users.register(
new_user = client.users.create(
email=user_email, password="new_secure_password123"
)
print("New user created:", new_user)
Expand Down
2 changes: 1 addition & 1 deletion py/core/examples/scripts/test_v3_sdk/test_v3_sdk_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def setup_prerequisites():

# # Login
# try:
# client.users.register(email=user_email, password="new_secure_password123")
# client.users.create(email=user_email, password="new_secure_password123")
# except Exception as e:
# print("User might already exist:", str(e))

Expand Down
Loading

0 comments on commit 6ec5404

Please sign in to comment.