From 707aea05afea305827150afc3c81097bf75a83de Mon Sep 17 00:00:00 2001 From: Georg Bremer Date: Thu, 4 Jul 2024 11:10:23 +0200 Subject: [PATCH] fix: Read embedder URL from env MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I had hardcoded it before 🤦 --- packages/server/graphql/public/types/User.ts | 21 +++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/server/graphql/public/types/User.ts b/packages/server/graphql/public/types/User.ts index 7947deed713..df9e22b8f17 100644 --- a/packages/server/graphql/public/types/User.ts +++ b/packages/server/graphql/public/types/User.ts @@ -28,6 +28,20 @@ import {UserResolvers} from '../resolverTypes' declare const __PRODUCTION__: string +const MODEL = 'Embeddings_ember_1' +const EMBED_URL = (() => { + try { + const availableModels = + process.env.AI_EMBEDDING_MODELS && JSON.parse(process.env.AI_EMBEDDING_MODELS) + return availableModels.find( + ({model}: {model?: string}) => model?.split(':')[1] === 'llmrails/ember-v1' + )?.url + } catch { + return undefined + } +})() +const SIMILARITY_THRESHOLD = 0.5 + const User: UserResolvers = { activity: async (_source, {activityId}, {dataLoader}) => { const activity = await dataLoader.get('meetingTemplates').load(activityId) @@ -186,7 +200,7 @@ const User: UserResolvers = { return connectionFromTemplateArray(allActivities, first, after) }, templateSearch: async ({id: userId}, {search}, {authToken, dataLoader}) => { - if (!search) return [] + if (!search || !EMBED_URL) return [] const viewerId = getUserId(authToken) const user = await dataLoader.get('users').loadNonNull(userId) const teamIds = @@ -203,16 +217,13 @@ const User: UserResolvers = { // all team ids which could have accessible templates const allTeamIds = ['aGhostTeam', ...allOrgTeams.map(({id}) => id)] - const response = await fetch('http://localhost:3040/embed', { + const response = await fetch(EMBED_URL, { method: 'POST', body: JSON.stringify({inputs: search}), headers: {'Content-Type': 'application/json'} }) const data = await response.json() - const MODEL = 'Embeddings_ember_1' - const SIMILARITY_THRESHOLD = 0.5 - const pg = getKysely() const similarEmbeddings = await pg .with('Model', (qc) =>