-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Sync collections JS * More documents * Clean up messy code * list not List * Users first pass * User tests and fixmes * More * typo * More prompts * Pre-commit improvements * Remove prints * Cleanups on conversations * Branches response * Chunks * More work on the return types * Jest config * Fix branch creation time
- Loading branch information
Showing
81 changed files
with
4,164 additions
and
1,820 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { r2rClient } from "../src/index"; | ||
const fs = require("fs"); | ||
import { describe, test, beforeAll, expect } from "@jest/globals"; | ||
|
||
const baseUrl = "http://localhost:7272"; | ||
|
||
describe("r2rClient V3 Collections Integration Tests", () => { | ||
let client: r2rClient; | ||
|
||
beforeAll(async () => { | ||
client = new r2rClient(baseUrl); | ||
await client.users.login({ | ||
email: "admin@example.com", | ||
password: "change_me_immediately", | ||
}); | ||
}); | ||
|
||
test("Create a chunk", async () => { | ||
const response = await client.chunks.create({ | ||
chunks: [ | ||
{ | ||
id: "a285d6ff-1219-4315-a7d4-649b300af992", | ||
document_id: "a285d6ff-1219-4315-a7d4-649b300af992", | ||
collection_ids: [], | ||
metadata: { key: "value" }, | ||
text: "Hello, world!", | ||
}, | ||
], | ||
run_with_orchestration: false, | ||
}); | ||
|
||
expect(response.results).toEqual([ | ||
{ | ||
document_id: expect.any(String), | ||
message: "Ingestion task completed successfully.", | ||
task_id: null, | ||
}, | ||
]); | ||
}); | ||
|
||
test("Retrieve a chunk", async () => { | ||
const response = await client.chunks.retrieve({ | ||
id: "a285d6ff-1219-4315-a7d4-649b300af992", | ||
}); | ||
|
||
expect(response.results).toMatchObject({ | ||
id: expect.any(String), | ||
document_id: expect.any(String), | ||
text: expect.any(String), | ||
collection_ids: expect.any(Array), | ||
metadata: expect.any(Object), | ||
}); | ||
}); | ||
|
||
test("Update a chunk", async () => { | ||
const response = await client.chunks.update({ | ||
id: "a285d6ff-1219-4315-a7d4-649b300af992", | ||
text: "Hello, world! How are you?", | ||
}); | ||
|
||
expect(response.results).toMatchObject({ | ||
id: expect.any(String), | ||
document_id: expect.any(String), | ||
text: "Hello, world! How are you?", | ||
collection_ids: expect.any(Array), | ||
metadata: expect.any(Object), | ||
}); | ||
}); | ||
|
||
test("Retrieve a chunk after update and check text", async () => { | ||
const response = await client.chunks.retrieve({ | ||
id: "a285d6ff-1219-4315-a7d4-649b300af992", | ||
}); | ||
|
||
expect(response.results.text).toBe("Hello, world! How are you?"); | ||
}); | ||
|
||
test("List chunks", async () => { | ||
const response = await client.chunks.list(); | ||
expect(response.results).toBeDefined(); | ||
}); | ||
|
||
test("Delete a chunk", async () => { | ||
const response = await client.chunks.delete( | ||
"a285d6ff-1219-4315-a7d4-649b300af992", | ||
); | ||
expect(response.results.success).toBe(true); | ||
}); | ||
|
||
test("Delete a chunk that does not exist", async () => { | ||
await expect( | ||
client.chunks.delete("a285d6ff-1219-4315-a7d4-649b300af992"), | ||
).rejects.toThrow(/Status 404/); | ||
}); | ||
}); |
This file contains 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
62 changes: 62 additions & 0 deletions
62
js/sdk/__tests__/ConversationsIntegrationSuperUser.test.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { r2rClient } from "../src/index"; | ||
const fs = require("fs"); | ||
import { describe, test, beforeAll, expect } from "@jest/globals"; | ||
|
||
const baseUrl = "http://localhost:7272"; | ||
|
||
describe("r2rClient V3 Collections Integration Tests", () => { | ||
let client: r2rClient; | ||
let conversationId: string; | ||
let messageId: string; | ||
|
||
beforeAll(async () => { | ||
client = new r2rClient(baseUrl); | ||
await client.users.login({ | ||
email: "admin@example.com", | ||
password: "change_me_immediately", | ||
}); | ||
}); | ||
|
||
test("List all conversations", async () => { | ||
const response = await client.conversations.list(); | ||
expect(response.results).toBeDefined(); | ||
}); | ||
|
||
test("Create a conversation", async () => { | ||
const response = await client.conversations.create(); | ||
conversationId = response.results.id; | ||
expect(response.results).toBeDefined(); | ||
}); | ||
|
||
test("Add a message to a conversation", async () => { | ||
const response = await client.conversations.addMessage({ | ||
id: conversationId, | ||
content: "Hello, world!", | ||
role: "user", | ||
}); | ||
messageId = response.results.id; | ||
expect(response.results).toBeDefined(); | ||
}); | ||
|
||
// TODO: This is throwing a 405? Why? | ||
// test("Update a message in a conversation", async () => { | ||
// const response = await client.conversations.updateMessage({ | ||
// id: conversationId, | ||
// message_id: messageId, | ||
// content: "Hello, world! How are you?", | ||
// }); | ||
// 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(); | ||
}); | ||
}); |
Oops, something went wrong.