From 568fe9540df3e9ab521f3e7318b2c945de4185d2 Mon Sep 17 00:00:00 2001 From: George Herbert Date: Sun, 4 Feb 2024 20:21:30 +0000 Subject: [PATCH] feat: github action for PR --- .github/workflows/pull-request.yml | 25 +++++++++++ server/src/repositories/api-repository.ts | 2 +- server/src/repositories/ingest-repository.ts | 2 - .../langchain-to-langtrace-service.ts | 4 +- server/src/services/trace-service.test.ts | 44 ++++++++++++------- ui/src/pages/projects/index.tsx | 8 ++-- 6 files changed, 62 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/pull-request.yml diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 0000000..b9e2f32 --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,25 @@ +name: Node.js CI + +on: [pull_request] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + project: [ui, server] + steps: + - uses: actions/checkout@v2 + - name: Use Node.js + uses: actions/setup-node@v2 + with: + node-version: '20' + - name: Install dependencies + run: npm install + working-directory: ${{ matrix.project }} + - name: Run lint + run: npm run lint + working-directory: ${{ matrix.project }} + - name: Build + run: npm run build + working-directory: ${{ matrix.project }} diff --git a/server/src/repositories/api-repository.ts b/server/src/repositories/api-repository.ts index f2597b1..e8cfe6c 100644 --- a/server/src/repositories/api-repository.ts +++ b/server/src/repositories/api-repository.ts @@ -31,7 +31,7 @@ export class ApiRepository { private createMatchForFilters(feedbackFilters?: FeedbackFilters) { interface MongoDBQuery { - $or?: { [key: string]: any }[]; + $or?: { [key: string]: unknown }[]; } const feedbackFilter: MongoDBQuery = {}; diff --git a/server/src/repositories/ingest-repository.ts b/server/src/repositories/ingest-repository.ts index 36fea5c..3fa7489 100644 --- a/server/src/repositories/ingest-repository.ts +++ b/server/src/repositories/ingest-repository.ts @@ -48,6 +48,4 @@ export class IngestRepository { return await collection.updateOne({ 'feedback.id': feedbackId }, { $set: setOperation }); } - - } diff --git a/server/src/services/langchain-to-langtrace-service.ts b/server/src/services/langchain-to-langtrace-service.ts index f91c08d..fa53221 100644 --- a/server/src/services/langchain-to-langtrace-service.ts +++ b/server/src/services/langchain-to-langtrace-service.ts @@ -31,10 +31,10 @@ export class LangchainToLangtraceService { return langchainData.run_id; } - async updateTrace(trace_id: string, langchainData: TraceData): Promise { + async updateTrace(traceId: string, langchainData: TraceData): Promise { this.convertToDates(langchainData); - const updateResult = await this.repository.updateTrace(trace_id, langchainData); + const updateResult = await this.repository.updateTrace(traceId, langchainData); return updateResult.matchedCount > 0; } diff --git a/server/src/services/trace-service.test.ts b/server/src/services/trace-service.test.ts index 12ea39f..49a3666 100644 --- a/server/src/services/trace-service.test.ts +++ b/server/src/services/trace-service.test.ts @@ -10,6 +10,8 @@ describe('TraceService', () => { let service: TraceService; let mockRepository: jest.Mocked; + const mockProjectId = 'projectId'; + beforeEach(() => { mockRepository = new ApiRepository() as any; service = new TraceService(); @@ -26,7 +28,12 @@ describe('TraceService', () => { run_type: '', session_name: '', start_time: '', - 'run_id': mockTraceId, name: 'Test Trace' + 'run_id': mockTraceId, + name: 'Test Trace', + execution_order: 0, + trace_id: null, + dotted_order: null, + }; @@ -42,17 +49,26 @@ describe('TraceService', () => { mockRepository.getTraces.mockResolvedValue(expectedResult); mockRepository.getFeedbackCounts.mockResolvedValue( - [{ key: 'useful', counts: { 'true': 0, 'false': 0 } }]); + [{ + key: 'useful', + feedbackType: 'value', + counts: { 'true': 0, 'false': 0 } + }] + ); - mockRepository.getLatencyPercentile.mockResolvedValue( [ + mockRepository.getLatencyPercentile.mockResolvedValue([ { percentile: 0, latency: 0 } as TracePercentile, ] ); - const result = await service.getTopLevelTraces(); + const result = await service.getTopLevelTraces(mockProjectId); expect(result).toEqual({ - feedback_counts: [{ key: 'useful', counts: { 'true': 0, 'false': 0 } }], + feedback_counts: [{ + key: 'useful', + feedbackType: 'value', + counts: { 'true': 0, 'false': 0 } + }], latency_percentiles: [{ percentile: 0, latency: 0 }], traces: expectedResult } satisfies TracesResponse); @@ -66,30 +82,28 @@ describe('TraceService', () => { it('should return null if no trace is found', async () => { mockRepository.getTraceTreeById.mockResolvedValue([]); - const result = await service.getTraceTreeByRunId(mockTraceId); + const result = await service.getTraceTreeByRunId(mockProjectId, mockTraceId); expect(result).toBeNull(); - expect(mockRepository.getTraceTreeById).toHaveBeenCalledWith(mockTraceId); + expect(mockRepository.getTraceTreeById).toHaveBeenCalledWith(mockProjectId, mockTraceId); }); it('should throw an error if multiple traces are found', async () => { mockRepository.getTraceTreeById.mockResolvedValue([mockTraceDocument, mockTraceDocument]); - await expect(service.getTraceTreeByRunId(mockTraceId)).rejects.toThrow('Trace not found'); - expect(mockRepository.getTraceTreeById).toHaveBeenCalledWith(mockTraceId); + await expect(service.getTraceTreeByRunId(mockProjectId, mockTraceId)) + .rejects.toThrow('Trace not found'); + expect(mockRepository.getTraceTreeById).toHaveBeenCalledWith(mockProjectId, mockTraceId); }); it('should return a trace document if exactly one trace is found', async () => { mockRepository.getTraceTreeById.mockResolvedValue([mockTraceDocument]); - const result = await service.getTraceTreeByRunId(mockTraceId); + const result = await service.getTraceTreeByRunId(mockProjectId, mockTraceId); expect(result).toEqual(mockTraceDocument); - expect(mockRepository.getTraceTreeById).toHaveBeenCalledWith(mockTraceId); + expect(mockRepository.getTraceTreeById).toHaveBeenCalledWith(mockProjectId, mockTraceId); }); }); - - -}) -; +}); diff --git a/ui/src/pages/projects/index.tsx b/ui/src/pages/projects/index.tsx index 099cc7d..f2565f7 100644 --- a/ui/src/pages/projects/index.tsx +++ b/ui/src/pages/projects/index.tsx @@ -1,7 +1,5 @@ import React from 'react'; import { getProjects } from '@/services/projects-service'; -import Breadcrumb from '@/components/Breadcrumb'; -import Link from 'next/link'; import Panel from '@/components/Panel'; import OutlineButton from '@/components/OutlineButton'; import AppBar from '@/components/AppBar'; @@ -21,7 +19,11 @@ const Projects: React.FC = ({ projects }) => {

Projects

{projects.map((project, index) => ( -

{project}

+

+ + {project} + +

))}
;