Skip to content

Commit

Permalink
fix: Read embedder URL from env
Browse files Browse the repository at this point in the history
I had hardcoded it before 🤦
  • Loading branch information
Dschoordsch committed Jul 4, 2024
1 parent 28a500b commit 707aea0
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packages/server/graphql/public/types/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 =
Expand All @@ -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) =>
Expand Down

0 comments on commit 707aea0

Please sign in to comment.