Skip to content

Commit

Permalink
Create a stub semanticSort callable endpoint.
Browse files Browse the repository at this point in the history
Part of #688.
  • Loading branch information
jkomoros committed Apr 8, 2024
1 parent 56b6873 commit 1de984f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
9 changes: 9 additions & 0 deletions functions/src/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
CardID,
CardSimilarityItem,
EmbeddableCard,
SemanticSortRequestData,
SemanticSortResponseData,
SimilarCardsRequestData,
SimilarCardsResponseData
} from './types.js';
Expand Down Expand Up @@ -477,6 +479,13 @@ export const reindexCardEmbeddings = async () : Promise<void> => {
console.log('Done indexing cards');
};

export const semanticSort = async (request : CallableRequest<SemanticSortRequestData>) : Promise<SemanticSortResponseData> => {
//For now, we'll just reverse the cards as a distinctive no-op style.
const cards =[...request.data.cards];
cards.reverse();
return {cards};
};

//How many milliseconds of slop do we allow for last_updated check? This gets
//across that the server and client times might be out of sync. If this is too
//big, then the common case of 'create-a-card' (which gets a generic embedding
Expand Down
5 changes: 4 additions & 1 deletion functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ import {
import {
processCardEmbedding,
reindexCardEmbeddings as reindexCardEmbeddingsImpl,
similarCards as similarCardsImpl
similarCards as similarCardsImpl,
semanticSort as semanticSortImpl
} from './embeddings.js';

import * as openaiimpl from './openai.js';
Expand Down Expand Up @@ -93,6 +94,8 @@ screenshotApp.get('/:id', async (req, res) => {
res.status(404).end();
});

export const semanticSort = onCall({}, semanticSortImpl);

export const similarCards = onCall({}, similarCardsImpl);

export const screenshot = onRequest({
Expand Down
10 changes: 9 additions & 1 deletion functions/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,12 @@ export type SimilarCardsResponseData = {
} | {
success: true
cards: CardSimilarityItem[]
};
};

export type SemanticSortRequestData = {
cards: CardID[]
}

export type SemanticSortResponseData = {
cards: CardID[]
}
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ gulp.task(BUILD_TASK, makeExecutor('npm run build'));

gulp.task(GENERATE_SEO_PAGES, makeExecutor('npm run generate:seo:pages'));

gulp.task(FIREBASE_DEPLOY_TASK, makeExecutor(ENABLE_TWITTER ? 'firebase deploy' : 'firebase deploy --only hosting,storage,firestore,functions:emailAdminOnMessage,functions:emailAdminOnStar,functions:legal' + (OPENAI_ENABLED ? ',functions:openai,functions:updateCardEmbedding,functions:reindexCardEmbeddings,functions:similarCards' : '')));
gulp.task(FIREBASE_DEPLOY_TASK, makeExecutor(ENABLE_TWITTER ? 'firebase deploy' : 'firebase deploy --only hosting,storage,firestore,functions:emailAdminOnMessage,functions:emailAdminOnStar,functions:legal' + (OPENAI_ENABLED ? ',functions:openai,functions:updateCardEmbedding,functions:reindexCardEmbeddings,functions:similarCards,functions:semanticSort' : '')));

gulp.task(FIREBASE_SET_CONFIG_LAST_DEPLOY_AFFECTING_RENDERING, async (cb) => {
const projectID = await selectedProjectID();
Expand Down

0 comments on commit 1de984f

Please sign in to comment.