Skip to content

Commit

Permalink
Merge pull request #39 from CapgeminiInventUK/feat/action
Browse files Browse the repository at this point in the history
feat: github action for MR
  • Loading branch information
georgeherby authored Feb 4, 2024
2 parents a0e583c + 86af5a4 commit 2c5052c
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 30 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Pull Request

on: [pull_request]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
project: [ui, server]
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
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 }}
4 changes: 4 additions & 0 deletions server/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"deprecation",
"unicorn"
],
"ignorePatterns": [
"node_modules/",
"dist/"
],
"rules": {
"unicorn/filename-case": "error",
"indent": [
Expand Down
4 changes: 2 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "langtrace-ingest",
"name": "langtrace-server",
"version": "1.0.0",
"main": "src/ingestor_server.ts",
"main": "src/ingestor-server.ts",
"scripts": {
"start:langtrace": "ts-node src/langtrace-server.ts",
"start:ingestor": "ts-node src/ingest-server.ts",
Expand Down
2 changes: 1 addition & 1 deletion server/src/repositories/api-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class ApiRepository {

private createMatchForFilters(feedbackFilters?: FeedbackFilters) {
interface MongoDBQuery {
$or?: { [key: string]: any }[];
$or?: { [key: string]: unknown }[];
}

const feedbackFilter: MongoDBQuery = {};
Expand Down
2 changes: 0 additions & 2 deletions server/src/repositories/ingest-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,4 @@ export class IngestRepository {
return await collection.updateOne({ 'feedback.id': feedbackId },
{ $set: setOperation });
}


}
4 changes: 2 additions & 2 deletions server/src/services/langchain-to-langtrace-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export class LangchainToLangtraceService {
return langchainData.run_id;
}

async updateTrace(trace_id: string, langchainData: TraceData): Promise<boolean> {
async updateTrace(traceId: string, langchainData: TraceData): Promise<boolean> {
this.convertToDates(langchainData);

const updateResult = await this.repository.updateTrace(trace_id, langchainData);
const updateResult = await this.repository.updateTrace(traceId, langchainData);
return updateResult.matchedCount > 0;
}

Expand Down
44 changes: 29 additions & 15 deletions server/src/services/trace-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ describe('TraceService', () => {
let service: TraceService;
let mockRepository: jest.Mocked<ApiRepository>;

const mockProjectId = 'projectId';

beforeEach(() => {
mockRepository = new ApiRepository() as any;
service = new TraceService();
Expand All @@ -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,

};


Expand All @@ -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);
Expand All @@ -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);
});
});


})
;
});
5 changes: 5 additions & 0 deletions ui/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"plugins": [
"unicorn"
],
"ignorePatterns": [
"node_modules/",
".next/",
"dist/"
],
"rules": {
"unicorn/filename-case": [
"error",
Expand Down
15 changes: 10 additions & 5 deletions ui/src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import NextAuth, { NextAuthOptions } from 'next-auth';
import NextAuth, { NextAuthOptions, Profile } from 'next-auth';
import GithubProvider from 'next-auth/providers/github';
import { NextApiRequest, NextApiResponse } from 'next';

const enableAuth = process.env.NEXTAUTH_ENABLE === 'true';

interface GitHubProfile extends Profile {
login: string;

}

const options = {
providers: [
GithubProvider({
clientId: process.env.NEXTAUTH_GITHUB_ID,
clientSecret: process.env.NEXTAUTH_GITHUB_SECRET,
clientId: process.env.NEXTAUTH_GITHUB_ID!,
clientSecret: process.env.NEXTAUTH_GITHUB_SECRET!,
authorization: {
params: {
scope: 'read:user,user:email,read:org',
Expand All @@ -20,10 +25,10 @@ const options = {
async signIn({ account, profile }) {
if (account?.provider === 'github' &&
(process.env.NEXTAUTH_GITHUB_ORGANISATION ?? '').trim() !== '') {

const orgName = process.env.NEXTAUTH_GITHUB_ORGANISATION;
const token = account.access_token;
const url = `https://api.github.com/orgs/${orgName}/members/${profile?.login}`;
const url =
`https://api.github.com/orgs/${orgName}/members/${(profile as GitHubProfile).login}`;
const response = await fetch(url, {
headers: {
Authorization: `token ${token}`,
Expand Down
8 changes: 5 additions & 3 deletions ui/src/pages/projects/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -21,7 +19,11 @@ const Projects: React.FC<ProjectsProps> = ({ projects }) => {
<h1>Projects</h1>
<Panel>
{projects.map((project, index) => (
<p><OutlineButton key={index} href={`/projects/${project}`}>{project}</OutlineButton></p>
<p key={index}>
<OutlineButton key={index} href={`/projects/${project}`}>
{project}
</OutlineButton>
</p>
))}
</Panel>
</div>;
Expand Down

0 comments on commit 2c5052c

Please sign in to comment.