Skip to content

Commit

Permalink
fix typeerrors and typecheks
Browse files Browse the repository at this point in the history
  • Loading branch information
dani2112 committed Jan 23, 2025
1 parent a4f7905 commit 18c767f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import '@testing-library/jest-dom'; // for DOM matchers like toBeInTheDocument
import { SourcesDisplay } from './SourcesDisplay';
import { RAGProvider } from '../RAGProvider';
import type {
Message,
SourceReference,
GetDataSourceResponse,
RAGConfig,
Expand Down
18 changes: 8 additions & 10 deletions rag-ui/lib/state/rag-state.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface MockProviderProps {
*/
const createMockRetrieveAndGenerate = () =>
vi.fn(
(messages: Message[], metadata?: Record<string, any>): RetrieveAndGenerateResponse => ({
(_messages: Message[], _metadata?: Record<string, any>): RetrieveAndGenerateResponse => ({
sources: Promise.resolve([
{
text: 'This is a text source',
Expand All @@ -57,12 +57,12 @@ const createMockRetrieveAndGenerate = () =>

const createMockGenerate = () =>
vi.fn(
(messages: Message[], sources?: RetrievalResult[]): GenerateResponse =>
(_messages: Message[], _sources?: RetrievalResult[]): GenerateResponse =>
Promise.resolve('Generated response')
);

const createMockGetDataSource = () =>
vi.fn(async (source: SourceReference): Promise<PDFSourceContent> => ({
vi.fn(async (_source: SourceReference): Promise<PDFSourceContent> => ({
type: 'pdf',
content: new Uint8Array([1, 2, 3]),
metadata: { title: 'PDF Document' },
Expand Down Expand Up @@ -118,15 +118,13 @@ function renderRAGHooks(
* Helper to add a user message and automatically wait
* for any returned promises (like `response` and `sources`) to resolve.
*/
async function addUserMessage(content: string, metadata?: Record<string, any>) {
let response;
async function addUserMessage(content: string) {
await act(async () => {
response = await result.current.messages.addMessage({
const response = result.current.messages.addMessage({
role: 'user',
content,
metadata,
});
if (response) {
if (response && typeof response === 'object' && 'sources' in response && 'response' in response) {
await response.sources;
await response.response;
}
Expand Down Expand Up @@ -222,7 +220,7 @@ describe('RAG Workflow Tests', () => {
];

const mockGenerate = vi.fn(
(messages: Message[], sources?: RetrievalResult[]): GenerateResponse => {
(_messages: Message[], _sources?: RetrievalResult[]): GenerateResponse => {
return Promise.resolve('Follow-up response');
}
);
Expand Down Expand Up @@ -321,7 +319,7 @@ describe('RAG Workflow Tests', () => {
});

it('should handle source search with metadata', async () => {
const mockRetrieve = vi.fn((query: string, metadata?: Record<string, any>) =>
const mockRetrieve = vi.fn((_query: string, _metadata?: Record<string, any>) =>
Promise.resolve([
{
text: 'result 1',
Expand Down
2 changes: 1 addition & 1 deletion rag-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"preview": "vite preview",
"test": "vitest",
"coverage": "vitest run --coverage",
"typecheck": "tsc --noEmit",
"typecheck": "tsc -b ./tsconfig.lib.json --noEmit",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
Expand Down

0 comments on commit 18c767f

Please sign in to comment.