Skip to content

Commit

Permalink
Interface instead of type; add data check to queryRag
Browse files Browse the repository at this point in the history
  • Loading branch information
diksipav committed Sep 19, 2024
1 parent ec9a0cb commit 31b96ae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
11 changes: 11 additions & 0 deletions packages/ai/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ export class EdgeDBAI {
});

const data = await res.json();

if (
!data ||
typeof data !== "object" ||
typeof data.response !== "string"
) {
throw new Error(
"Expected response to be object with response key of type string",
);
}

return data.response;
}

Expand Down
24 changes: 12 additions & 12 deletions packages/ai/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,48 @@ export interface RAGRequest {
stream?: boolean;
}

export type MessageStart = {
export interface MessageStart {
type: "message_start";
message: {
role: "assistant" | "system" | "user";
id: string;
model: string;
};
};
}

export type ContentBlockStart = {
export interface ContentBlockStart {
type: "content_block_start";
index: number;
content_block: {
text: string;
type: "text";
};
};
}

export type ContentBlockDelta = {
export interface ContentBlockDelta {
type: "content_block_delta";
delta: {
type: "text_delta";
text: string;
};
index: number;
};
}

export type ContentBlockStop = {
export interface ContentBlockStop {
type: "content_block_stop";
index: number;
};
}

export type MessageDelta = {
export interface MessageDelta {
type: "message_delta";
delta: {
stop_reason: "stop";
};
};
}

export type MessageStop = {
export interface MessageStop {
type: "message_stop";
};
}

export type StreamingMessage =
| MessageStart
Expand Down

0 comments on commit 31b96ae

Please sign in to comment.