fix ts sdk, tests pass
This commit is contained in:
parent
20664c5064
commit
7ab0e5b011
4 changed files with 16 additions and 23 deletions
|
|
@ -12,7 +12,6 @@ import type {
|
||||||
ConversationListResponse,
|
ConversationListResponse,
|
||||||
DoneEvent,
|
DoneEvent,
|
||||||
Message,
|
Message,
|
||||||
SearchFilters,
|
|
||||||
Source,
|
Source,
|
||||||
SourcesEvent,
|
SourcesEvent,
|
||||||
StreamEvent,
|
StreamEvent,
|
||||||
|
|
@ -69,11 +68,11 @@ export class ChatStream implements AsyncIterable<StreamEvent>, Disposable {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.options.chatId) {
|
if (this.options.chatId) {
|
||||||
body.chat_id = this.options.chatId;
|
body["chat_id"] = this.options.chatId;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.filters) {
|
if (this.options.filters) {
|
||||||
body.filters = this.options.filters;
|
body["filters"] = this.options.filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._response = await this.client._request("POST", "/api/v1/chat", {
|
this._response = await this.client._request("POST", "/api/v1/chat", {
|
||||||
|
|
@ -212,11 +211,11 @@ export class ChatClient {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (options.chatId) {
|
if (options.chatId) {
|
||||||
body.chat_id = options.chatId;
|
body["chat_id"] = options.chatId;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.filters) {
|
if (options.filters) {
|
||||||
body.filters = options.filters;
|
body["filters"] = options.filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await this.client._request("POST", "/api/v1/chat", {
|
const response = await this.client._request("POST", "/api/v1/chat", {
|
||||||
|
|
@ -260,11 +259,11 @@ export class ChatClient {
|
||||||
|
|
||||||
const conversations: Conversation[] = (data.conversations || []).map(
|
const conversations: Conversation[] = (data.conversations || []).map(
|
||||||
(c: Record<string, unknown>) => ({
|
(c: Record<string, unknown>) => ({
|
||||||
chatId: c.chat_id,
|
chatId: c["chat_id"],
|
||||||
title: c.title || "",
|
title: c["title"] || "",
|
||||||
createdAt: c.created_at || null,
|
createdAt: c["created_at"] || null,
|
||||||
lastActivity: c.last_activity || null,
|
lastActivity: c["last_activity"] || null,
|
||||||
messageCount: c.message_count || 0,
|
messageCount: c["message_count"] || 0,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -282,9 +281,9 @@ export class ChatClient {
|
||||||
|
|
||||||
const messages: Message[] = (data.messages || []).map(
|
const messages: Message[] = (data.messages || []).map(
|
||||||
(m: Record<string, unknown>) => ({
|
(m: Record<string, unknown>) => ({
|
||||||
role: m.role,
|
role: m["role"],
|
||||||
content: m.content,
|
content: m["content"],
|
||||||
timestamp: m.timestamp || null,
|
timestamp: m["timestamp"] || null,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ export class OpenRAGClient {
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method,
|
method,
|
||||||
headers,
|
headers,
|
||||||
body: options.body,
|
body: options.body ?? null,
|
||||||
signal: controller.signal,
|
signal: controller.signal,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { OpenRAGClient } from "./client";
|
import type { OpenRAGClient } from "./client";
|
||||||
import type { SearchFilters, SearchQueryOptions, SearchResponse } from "./types";
|
import type { SearchQueryOptions, SearchResponse } from "./types";
|
||||||
|
|
||||||
export class SearchClient {
|
export class SearchClient {
|
||||||
constructor(private client: OpenRAGClient) {}
|
constructor(private client: OpenRAGClient) {}
|
||||||
|
|
@ -26,7 +26,7 @@ export class SearchClient {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (options?.filters) {
|
if (options?.filters) {
|
||||||
body.filters = options.filters;
|
body["filters"] = options.filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await this.client._request("POST", "/api/v1/search", {
|
const response = await this.client._request("POST", "/api/v1/search", {
|
||||||
|
|
|
||||||
|
|
@ -115,13 +115,7 @@ describe.skipIf(SKIP_TESTS)("OpenRAG TypeScript SDK Integration", () => {
|
||||||
|
|
||||||
describe("Search", () => {
|
describe("Search", () => {
|
||||||
it("should search documents", async () => {
|
it("should search documents", async () => {
|
||||||
// Ensure document is ingested
|
// Documents already ingested by previous tests
|
||||||
await client.documents.ingest({ filePath: testFilePath });
|
|
||||||
|
|
||||||
// Wait for indexing
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
||||||
|
|
||||||
// Search
|
|
||||||
const results = await client.search.query("orange kangaroos jumping");
|
const results = await client.search.query("orange kangaroos jumping");
|
||||||
|
|
||||||
expect(results.results).toBeDefined();
|
expect(results.results).toBeDefined();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue