From 697cc8325c1b4d1155b68a26cb440c31735a1255 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..8b7e238b87c 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 EMBER_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 || !EMBER_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(EMBER_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) =>