Skip to content

Commit

Permalink
Remove supabase and api routes
Browse files Browse the repository at this point in the history
  • Loading branch information
gcharis committed Nov 29, 2023
1 parent 579b984 commit 7a0dd0e
Show file tree
Hide file tree
Showing 31 changed files with 0 additions and 2,077 deletions.
249 changes: 0 additions & 249 deletions cypress/e2e/public-api.cy.ts
Original file line number Diff line number Diff line change
@@ -1,252 +1,3 @@
import { Chat } from 'openai/resources';
import { supabaseExecute } from '../../src/lib/public-api/database';
import {
DocumentsResponse,
CreateIndexResponse,
GetIndexesResponse,
ChatCompletionResponse,
RagCompletionResponse,
SimilarDocumentsResponse,
} from '../../src/lib/public-api/validation';
import { Project, Index } from '../../src/types/supabase-entities';

let state = {
project: null as Project | null,
index: null as Index | null,
};

const routes = {
getIndexes: '/api/indexes',
searchIndex: '/api/indexes/search',
postDocuments: '/api/documents',
getDocuments: '/api/documents',
searchDocuments: '/api/documents/search',
chat: '/api/chat/completions',
rag: '/api/chat/rag',
};

context('Test Public API', () => {
before(async () => {});

it('gets the project to be tested from database', () => {
const query = `select * from projects where name = 'Test project'`;
cy.task('supabaseExecute', query).then(({ data, error }: any) => {
expect(data[0].name).to.eq('Test project');
state.project = data[0];
});
});

context(`POST ${routes.getIndexes}`, () => {
it('should fail when there are no correct headers', () => {
cy.request({
method: 'POST',
url: routes.getIndexes,
failOnStatusCode: false,
}).then((response) => {
expect(response.status).to.eq(401);
});
});

it('should create a new index', () => {
const name = `Test index ${new Date().getTime()}`;
cy.request({
method: 'POST',
url: routes.getIndexes,
headers: {
authentication: `Bearer ${state.project?.api_key}`,
},
body: {
name,
},
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.body.name).to.eq(name);
CreateIndexResponse.parse(response.body);
});
});
});

context(`GET ${routes.getIndexes}`, () => {
it('should fail when there are no correct headers', () => {
cy.request({
method: 'GET',
url: routes.getIndexes,
failOnStatusCode: false,
}).then((response) => {
expect(response.status).to.eq(401);
});
});

it('should return the indexes', () => {
cy.request({
method: 'GET',
url: routes.getIndexes,
headers: {
authentication: `Bearer ${state.project?.api_key}`,
},
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.body.length).to.greaterThan(0);
GetIndexesResponse.parse(response.body);
state.index = response.body[0];
});
});
});

context(`POST ${routes.postDocuments}`, () => {
it('should load documents to an index along with metadata ', () => {
cy.request({
method: 'POST',
url: `${routes.postDocuments}?index_id=${state.index?.id}`,
headers: {
authentication: `Bearer ${state.project?.api_key}`,
},
body: [
{
content: 'The name of the company is SquareDev.',
source: 'the founders',
metadata: { string: 'string' },
},
],
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.body.length).to.greaterThan(0);
DocumentsResponse.parse(response.body);
});
});

it('should fail when there is no content in the document', () => {
cy.request({
failOnStatusCode: false,
method: 'POST',
url: `${routes.postDocuments}?index_id=${state.index?.id}`,
headers: {
authentication: `Bearer ${state.project?.api_key}`,
},
body: [
{
source: 'string',
metadata: { string: 'string' },
},
],
}).then((response) => {
// TODO: This should be 400
expect(response.status).to.eq(500);
});
});
});

context(`POST ${routes.postDocuments}/upload`, () => {
it.skip('json', () => {});
it.skip('pdf', () => {});
});

context(`POST ${routes.postDocuments}/web`, () => {});

context(`GET ${routes.getDocuments}`, () => {
it('should get the documents of an index', () => {
cy.request({
method: 'GET',
url: `${routes.postDocuments}?index_id=${state.index?.id}`,
headers: {
authentication: `Bearer ${state.project?.api_key}`,
},
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.body.length).to.greaterThan(0);
DocumentsResponse.parse(response.body);
});
});

it.skip('return the correct error for wrong indexes', () => {});
});

context(`GET ${routes.searchIndex}`, () => {
it('should get the documents of an index that are contextually similar to the search term', () => {
cy.request({
method: 'GET',
url: `${routes.searchIndex}?index_id=${state.index?.id}&search=A random`,
headers: {
authentication: `Bearer ${state.project?.api_key}`,
},
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.body.length).to.greaterThan(0);
SimilarDocumentsResponse.parse(response.body);
});
});

it.skip('return the correct error for wrong indexes', () => {});
it.skip('return the correct error for no search term', () => {});
});

context(`POST /chat/completions`, () => {
it('should chat with the LLM, only completing the requested prompt', () => {
cy.request({
method: 'POST',
url: `/api/chat/completions?model=gpt-3.5-turbo`,
headers: {
authentication: `Bearer ${state.project?.api_key}`,
},
body: {
model: 'gpt-3.5-turbo',
messages: {
system: 'Hello, how are you?',
user: 'I am fine, how are you?',
},
},
}).then((response) => {
expect(response.status).to.eq(200);
ChatCompletionResponse.parse(response.body);
});
});
});

context(`POST ${routes.rag}`, () => {
it('chats with RAG', () => {
cy.request({
method: 'POST',
url: `${routes.rag}?model=gpt-3.5-turbo`,
headers: {
authentication: `Bearer ${state.project?.api_key}`,
},
body: {
model: 'gpt-3.5-turbo',
messages: {
system:
'You are a helpful assistant. Try to answer the question using the given context.',
user: 'Context: {context} \nQuestion: What is the name of the company?',
},
indexId: state.index?.id,
},
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.body.message).to.include('SquareDev');
console.log(response.body);
RagCompletionResponse.parse(response.body);
});
});

it('returns an error if no {context} placeholder', () => {
cy.request({
method: 'POST',
url: `${routes.rag}`,
failOnStatusCode: false,
headers: {
authentication: `Bearer ${state.project?.api_key}`,
},
body: {
model: 'gpt-3.5-turbo',
messages: {
system:
'You are a helpful assistant. Try to answer the question using the given context.',
user: 'Context: no context placeholder \nQuestion: What is the name of the company?',
},
indexId: state.index?.id,
},
}).then((response) => {
expect(response.status).to.eq(400);
});
});
});
});
6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"reset": "npx supabase db reset",
"diff": "npx supabase db diff -f feature",
"migration": "npx supabase migration new feature",
"update-types": "npx supabase gen types typescript --local > src/types/supabase.ts",
"update-db": "npm run diff && npm run reset && npm run update-types",
"prepare": "husky install",
"pretty-staged": "pretty-quick --staged",
Expand All @@ -28,7 +24,6 @@
"@radix-ui/react-dropdown-menu": "2.0.6",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-slot": "^1.0.2",
"@supabase/auth-helpers-nextjs": "^0.8.1",
"@vercel/analytics": "^1.1.1",
"bcrypt": "^5.1.1",
"class-variance-authority": "^0.7.0",
Expand Down Expand Up @@ -69,7 +64,6 @@
"husky": "^8.0.3",
"postcss": "^8.4.14",
"pretty-quick": "^3.1.3",
"supabase": "^1.99.5",
"tailwindcss": "^3.3.3",
"typescript": "^5.2.2"
}
Expand Down
34 changes: 0 additions & 34 deletions src/app/api/chat/completions/route.ts

This file was deleted.

73 changes: 0 additions & 73 deletions src/app/api/chat/rag/route.ts

This file was deleted.

Loading

0 comments on commit 7a0dd0e

Please sign in to comment.