Skip to content

Commit

Permalink
Merge pull request #3 from awhiteside1/aw/example
Browse files Browse the repository at this point in the history
Builds with Nextjs
  • Loading branch information
awhiteside1 authored Sep 16, 2024
2 parents 187412d + e336c8a commit 3ccf62d
Show file tree
Hide file tree
Showing 182 changed files with 10,754 additions and 72 deletions.
13 changes: 8 additions & 5 deletions packages/semantic-search/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
".": {
"types": "./src/index.ts",
"default": "./dist/index.mjs"
},
"./lancedb": {
"types": "./src/components/lancedb/index.ts",
"default": "./dist/components/lancedb/index.mjs"
}
},
"scripts": {
Expand All @@ -20,16 +24,15 @@
"postinstall": "pnpm build:stub"
},
"devDependencies": {
"@lancedb/lancedb": "0.10.0",
"@payloadcms/db-mongodb": "^3.0.0-beta.107",
"@payloadcms/db-postgres": "^3.0.0-beta.107",
"@types/dockerode": "^3.3.31",
"apache-arrow": "^17.0.0",
"dockerode": "^4.0.2",
"mongodb-memory-server": "^10.0.0",
"ollama": "^0.5.9"
"mongodb-memory-server": "^10.0.0"
},
"dependencies": {
"apache-arrow": "^17.0.0",
"ollama": "^0.5.9",
"@lancedb/lancedb": "0.10.0",
"@workspace/llm-utils": "workspace:*",
"defu": "^6.1.4",
"pathe": "^1.1.2",
Expand Down
6 changes: 4 additions & 2 deletions packages/semantic-search/src/components/lancedb/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { type Table, connect } from '@lancedb/lancedb'
import { LanceSchema } from '@lancedb/lancedb/embedding'
import { LanceSchema, getRegistry } from '@lancedb/lancedb/embedding'
import { Utf8 } from 'apache-arrow'
import type { Identifier, InsertFields, VectorDB } from '../../types'
import { OllamaEmbeddings } from '../ollama'
import { OllamaEmbeddings, register } from '../ollama'

register()

export class LanceDB implements VectorDB {
public name = 'lancedb'
Expand Down
10 changes: 2 additions & 8 deletions packages/semantic-search/src/components/ollama/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import { embedding } from '@lancedb/lancedb'
import {
EmbeddingFunction,
TextEmbeddingFunction,
getRegistry,
} from '@lancedb/lancedb/embedding'
import { TextEmbeddingFunction, getRegistry } from '@lancedb/lancedb/embedding'
import type { Float } from 'apache-arrow'
import { Ollama } from 'ollama'

Expand All @@ -12,8 +7,7 @@ interface Options {
timeout: number
host: string
}
// @ts-ignore
@embedding.register('ollama')

export class OllamaEmbeddings extends TextEmbeddingFunction<Partial<Options>> {
private client: Ollama
constructor(private modelOptions: Options) {
Expand Down
1 change: 0 additions & 1 deletion packages/semantic-search/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const semanticSearchPlugin =

return setupSemanticSearchCustom(config, {
vectorDB: incomingPluginConfig.vectorDB,
embeddingFn: incomingPluginConfig.vectorDB,
})
}

Expand Down
3 changes: 1 addition & 2 deletions packages/semantic-search/src/utils/customContext.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { Config } from 'payload'
import { isObject } from 'radash'
import type { SemanticSearchPluginConfig, VectorDB } from '../types'
import type { VectorDB } from '../types'

export type SemanticSearchCustomObject = {
vectorDB: VectorDB
embeddingFn: SemanticSearchPluginConfig['embeddingFn']
}

export const CUSTOMKEY = 'semantic-search'
Expand Down
10 changes: 10 additions & 0 deletions playground/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
max_line_length = null
16 changes: 16 additions & 0 deletions playground/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Added by Payload
# Database connection string
DATABASE_URI=file:./db/playground.db
# Used to encrypt JWT tokens
PAYLOAD_SECRET=5a9a296d283d03980a3110f3
# Used to format links and URLs
PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000
NEXT_PUBLIC_SERVER_URL=http://localhost:3000
# Allow robots to index the site (optional)
NEXT_PUBLIC_IS_LIVE=
# Used to preview drafts
PAYLOAD_PUBLIC_DRAFT_SECRET=demo-draft-secret
NEXT_PRIVATE_DRAFT_SECRET=demo-draft-secret
# Used to revalidate static pages
REVALIDATION_KEY=demo-revalation-key
NEXT_PRIVATE_REVALIDATION_KEY=demo-revalation-key
12 changes: 12 additions & 0 deletions playground/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.tmp
**/.git
**/.hg
**/.pnp.*
**/.svn
**/.yarn/**
**/build
**/dist/**
**/node_modules
**/temp
playwright.config.ts
jest.config.js
8 changes: 8 additions & 0 deletions playground/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
extends: 'next',
root: true,
parserOptions: {
project: ['./tsconfig.json'],
tsconfigRootDir: __dirname,
},
}
11 changes: 11 additions & 0 deletions playground/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
build
dist / media
node_modules
.DS_Store
.env
.next
.vercel

# Payload default media upload directory
public/media/
db/
14 changes: 14 additions & 0 deletions playground/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
**/payload-types.ts
.tmp
**/.git
**/.hg
**/.pnp.*
**/.svn
**/.yarn/**
**/build
**/dist/**
**/node_modules
**/temp
**/docs/**
tsconfig.json

6 changes: 6 additions & 0 deletions playground/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"semi": false
}
24 changes: 24 additions & 0 deletions playground/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM node:18.8-alpine as base

FROM base as builder

WORKDIR /home/node/app
COPY package*.json ./

COPY . .
RUN yarn install
RUN yarn build

FROM base as runtime

ENV NODE_ENV=production

WORKDIR /home/node/app
COPY package*.json ./
COPY yarn.lock ./

RUN yarn install --production

EXPOSE 3000

CMD ["node", "dist/server.js"]
Loading

0 comments on commit 3ccf62d

Please sign in to comment.