From d11790181771e2350fb809c8e31b726c3a976a63 Mon Sep 17 00:00:00 2001 From: Daniel Madalitso Phiri Date: Mon, 29 Apr 2024 17:04:32 +0200 Subject: [PATCH 1/3] added components --- app.vue | 100 +-------------------------- components/cover.vue | 18 +++++ components/loading.vue | 13 ++++ components/results.vue | 32 +++++++++ components/search.vue | 28 ++++++++ package.json | 2 +- pages/index.vue | 24 +++++++ pages/keyword.vue | 148 ++++++++++++++++++++++++++++++++++++++++ pages/vector.vue | 97 ++++++++++++++++++++++++++ server/api/newsearch.ts | 17 +++-- server/api/search.ts | 10 ++- types.ts | 15 ++-- yarn.lock | 8 +-- 13 files changed, 394 insertions(+), 118 deletions(-) create mode 100644 components/cover.vue create mode 100644 components/loading.vue create mode 100644 components/results.vue create mode 100644 components/search.vue create mode 100644 pages/index.vue create mode 100644 pages/keyword.vue create mode 100644 pages/vector.vue diff --git a/app.vue b/app.vue index 2c417ae..8a3e7bc 100644 --- a/app.vue +++ b/app.vue @@ -1,99 +1,5 @@ - - - + \ No newline at end of file diff --git a/components/cover.vue b/components/cover.vue new file mode 100644 index 0000000..39256b4 --- /dev/null +++ b/components/cover.vue @@ -0,0 +1,18 @@ + \ No newline at end of file diff --git a/components/loading.vue b/components/loading.vue new file mode 100644 index 0000000..aeb0df2 --- /dev/null +++ b/components/loading.vue @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/components/results.vue b/components/results.vue new file mode 100644 index 0000000..0e94165 --- /dev/null +++ b/components/results.vue @@ -0,0 +1,32 @@ + + + \ No newline at end of file diff --git a/components/search.vue b/components/search.vue new file mode 100644 index 0000000..b5e7388 --- /dev/null +++ b/components/search.vue @@ -0,0 +1,28 @@ + + + + \ No newline at end of file diff --git a/package.json b/package.json index f50aa68..58b587e 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "nuxt": "^3.11.1", "vue": "^3.4.21", "vue-router": "^4.3.0", - "weaviate-client": "^3.0.0-beta.22", + "weaviate-client": "^3.0.0-beta.23", "zod": "^3.22.4" }, "devDependencies": { diff --git a/pages/index.vue b/pages/index.vue new file mode 100644 index 0000000..551124e --- /dev/null +++ b/pages/index.vue @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/pages/keyword.vue b/pages/keyword.vue new file mode 100644 index 0000000..d2611f8 --- /dev/null +++ b/pages/keyword.vue @@ -0,0 +1,148 @@ + + + + + \ No newline at end of file diff --git a/pages/vector.vue b/pages/vector.vue new file mode 100644 index 0000000..f9eaa1e --- /dev/null +++ b/pages/vector.vue @@ -0,0 +1,97 @@ + + + + + \ No newline at end of file diff --git a/server/api/newsearch.ts b/server/api/newsearch.ts index 6371497..2fc1233 100644 --- a/server/api/newsearch.ts +++ b/server/api/newsearch.ts @@ -28,13 +28,16 @@ export default defineEventHandler<{query: { query: string } }>(async (event) => // User object is validated and typed! const searchTerm = result.data.query // add search - const myCollection = client.collections.get('TrackSearch') + + const myCollection = client.collections.get('CalvinHarris') const response = await myCollection.generate.nearText(searchTerm, { - groupedTask: `pick your favourite pleeeease and tell me why. also say how confident you are based off results`, - } - ,{ - limit: 5 - }) + groupedTask: `out of all of these what is your favourite?` + }, + { + limit: 5 + }) + + console.log(response.generated) - return response.generated + return response.objects }) diff --git a/server/api/search.ts b/server/api/search.ts index bc316fb..891a5ae 100644 --- a/server/api/search.ts +++ b/server/api/search.ts @@ -23,13 +23,19 @@ export default defineEventHandler<{query: { query: string } }>(async (event) => if (!result.success) throw result.error.issues + + // User object is validated and typed! const searchTerm = result.data.query - const myCollection = client.collections.get('TrackSearcher') + // add search + const myCollection = client.collections.get('CalvinHarris') - const response = await myCollection.query.nearText(searchTerm, { + const response = await myCollection.query.nearText(searchTerm, + { limit: 5 }) + console.log(response.objects) + return response.objects }) diff --git a/types.ts b/types.ts index 1885106..4656998 100644 --- a/types.ts +++ b/types.ts @@ -1,4 +1,4 @@ -import weaviate, { type WeaviateObjectType } from 'weaviate-client' +import weaviate, { type GenerateObject, type GenerativeReturn, type WeaviateObjectType } from 'weaviate-client' export type QuoteType = { quote: string; @@ -12,15 +12,16 @@ export type JeopartyCollection = { } export type TrackSearcher = { + title: string, + artist: string, + album: string, year: number, - rank: number, - title: string - artist: string - album: string + rank: number } - + export type TrackSearchResult = { - response: WeaviateObjectType + response: GenerateObject + } export type SearchResult = { diff --git a/yarn.lock b/yarn.lock index e014c7a..05ab072 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6207,10 +6207,10 @@ vue@^3.4.21: "@vue/server-renderer" "3.4.21" "@vue/shared" "3.4.21" -weaviate-client@^3.0.0-beta.22: - version "3.0.0-beta.22" - resolved "https://registry.yarnpkg.com/weaviate-client/-/weaviate-client-3.0.0-beta.22.tgz#21891be2a38f208cbfbf6eebb09521cd10eac946" - integrity sha512-sFLblj2sLlrccqZQs4l5gXDlbLnaqGVzrXajVguFsBofAZSJEv25TxQMxW1Ta1tsI7CPyy0S15f5QcY69Fx/XA== +weaviate-client@^3.0.0-beta.23: + version "3.0.0-beta.23" + resolved "https://registry.yarnpkg.com/weaviate-client/-/weaviate-client-3.0.0-beta.23.tgz#2d0ecc05899cdf67b3689dc89df3b3e3ef6df52a" + integrity sha512-K8JiW3XjMcvRNOXkXSAz2CwS7Vlzpgc5hV4ZY+5Vm2NxNTLpTbmBmCHecxB0baaDuzFo3l014wuMgIWFJVfPCg== dependencies: graphql "^16.8.1" graphql-request "^6.1.0" From e6396a26525e6f32322a1681765a13445e1bf3a6 Mon Sep 17 00:00:00 2001 From: Daniel Madalitso Phiri Date: Fri, 10 May 2024 15:55:50 +0200 Subject: [PATCH 2/3] cleaned structure --- components/results.vue | 8 +++--- components/search.vue | 2 -- nuxt.config.ts | 9 ++++++ pages/index.vue | 8 ++++-- server/api/newsearch.ts | 43 --------------------------- server/api/search.ts | 59 +++++++++++++++++--------------------- server/tasks/db/migrate.ts | 14 +++++++++ 7 files changed, 59 insertions(+), 84 deletions(-) delete mode 100644 server/api/newsearch.ts create mode 100644 server/tasks/db/migrate.ts diff --git a/components/results.vue b/components/results.vue index 0e94165..29f0660 100644 --- a/components/results.vue +++ b/components/results.vue @@ -8,16 +8,16 @@
-
+

- {{ result.properties.title }} by {{ result.properties.rank }} -

+ {{ item.properties.title }} by {{ item.properties.artist }} +
- +
diff --git a/components/search.vue b/components/search.vue index b5e7388..3b8e7a9 100644 --- a/components/search.vue +++ b/components/search.vue @@ -21,8 +21,6 @@ \ No newline at end of file diff --git a/nuxt.config.ts b/nuxt.config.ts index 4882451..def7859 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -8,5 +8,14 @@ export default defineNuxtConfig({ weaviateToken: '', openai: '', cohere: '', + }, + nitro: { + experimental: { + tasks: true + }, + scheduledTasks: { + // Run `db:migrate` task every minute + '15 13 * * 1-5': ['db:migrate'] + } } }) diff --git a/pages/index.vue b/pages/index.vue index 551124e..3b79c0e 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -3,16 +3,18 @@ - +

+ {{ searchResult }} +

+ - \ No newline at end of file diff --git a/pages/vector.vue b/pages/vector.vue deleted file mode 100644 index f9eaa1e..0000000 --- a/pages/vector.vue +++ /dev/null @@ -1,97 +0,0 @@ - - - - - \ No newline at end of file diff --git a/server/tasks/db/migrate.ts b/server/tasks/db/migrate.ts deleted file mode 100644 index c705d32..0000000 --- a/server/tasks/db/migrate.ts +++ /dev/null @@ -1,14 +0,0 @@ -export default defineTask({ - meta: { - name: "db:migrate", - description: "Run database migrations", - }, - run({ payload, context }) { - console.log('This is the payload', payload) - console.log('This is the context', context) - console.log("Running DB migration task..."); - return { result: "Success" }; - }, - }); - -