From e8041f2813923fc82c5cfdbeaa74729f5e80b82a Mon Sep 17 00:00:00 2001 From: Believethehype <1097224+believethehype@users.noreply.github.com> Date: Thu, 26 Sep 2024 17:05:38 +0200 Subject: [PATCH] adding llm chat to frontend --- nostr_dvm/utils/dvmconfig.py | 2 +- tests/generic_dvm_duck_chat.py | 4 +- ui/noogle/src/components/Chat.vue | 26 + ui/noogle/src/components/ChatGeneration.vue | 709 +++++++++++++++++++ ui/noogle/src/components/ImageGeneration.vue | 32 + ui/noogle/src/layouts/ThreeColumnLayout.vue | 1 + ui/noogle/src/router/index.js | 1 + ui/noogle/src/store.js | 21 +- 8 files changed, 790 insertions(+), 6 deletions(-) create mode 100644 ui/noogle/src/components/Chat.vue create mode 100644 ui/noogle/src/components/ChatGeneration.vue diff --git a/nostr_dvm/utils/dvmconfig.py b/nostr_dvm/utils/dvmconfig.py index 131c966..e924ad8 100644 --- a/nostr_dvm/utils/dvmconfig.py +++ b/nostr_dvm/utils/dvmconfig.py @@ -15,7 +15,7 @@ class DVMConfig: FIX_COST: float = None PER_UNIT_COST: float = None - RELAY_LIST = [ + RELAY_LIST = ["wss://relay.primal.net", "wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.net" ] diff --git a/tests/generic_dvm_duck_chat.py b/tests/generic_dvm_duck_chat.py index 3622666..1429c48 100644 --- a/tests/generic_dvm_duck_chat.py +++ b/tests/generic_dvm_duck_chat.py @@ -1,5 +1,6 @@ import json from pathlib import Path +from platform import system import dotenv from duck_chat import ModelType @@ -54,7 +55,8 @@ def playground(announce=False): from duck_chat import DuckChat options = dvm.set_options(request_form) async with DuckChat(model=ModelType.GPT4o) as chat: - query = options["input"] + system_prompt= "You are a Bitcoiner.." + query = ("{System}: " + system_prompt +" {User}: "+ options["input"]) result = await chat.ask_question(query) print(result) return result diff --git a/ui/noogle/src/components/Chat.vue b/ui/noogle/src/components/Chat.vue new file mode 100644 index 0000000..4f6fc68 --- /dev/null +++ b/ui/noogle/src/components/Chat.vue @@ -0,0 +1,26 @@ + + + + + \ No newline at end of file diff --git a/ui/noogle/src/components/ChatGeneration.vue b/ui/noogle/src/components/ChatGeneration.vue new file mode 100644 index 0000000..6cf3984 --- /dev/null +++ b/ui/noogle/src/components/ChatGeneration.vue @@ -0,0 +1,709 @@ + + + + diff --git a/ui/noogle/src/components/ImageGeneration.vue b/ui/noogle/src/components/ImageGeneration.vue index b640ce2..3096c11 100644 --- a/ui/noogle/src/components/ImageGeneration.vue +++ b/ui/noogle/src/components/ImageGeneration.vue @@ -267,6 +267,38 @@ async function listen() { let entries = [] console.log("6100:", event.content); + + + for (const el of store.state.nip89dvms) { + let status = "unknown" + let jsonentry = { + id: event.author.toHex(), + kind: "", + status: status, + result: "", + name: "Not announced" + event.author.toBech32(), + about: "", + image: "", + amount: 0, + bolt11: "", + nip90params: {}, + + } + if (JSON.parse(el.event).pubkey === event.author.toHex().toString() && el.kind === "5100" ) { + jsonentry.name = el.name + jsonentry.about = el.about + jsonentry.image = el.image + jsonentry.nip90Params = el.nip90Params + jsonentry.reactions = await dvmreactions(PublicKey.parse(el.id), store.state.followings) + jsonentry.event = Event.fromJson(el.event) + + + } + } + if (dvms.filter(i => i.id === jsonentry.id).length === 0) { + dvms.push(jsonentry) + } + //miniToastr.showMessage("DVM: " + dvmname, "Received Results", VueNotifications.types.success) dvms.find(i => i.id === event.author.toHex()).result = event.content dvms.find(i => i.id === event.author.toHex()).status = "finished" diff --git a/ui/noogle/src/layouts/ThreeColumnLayout.vue b/ui/noogle/src/layouts/ThreeColumnLayout.vue index 4e9598a..4669f17 100644 --- a/ui/noogle/src/layouts/ThreeColumnLayout.vue +++ b/ui/noogle/src/layouts/ThreeColumnLayout.vue @@ -15,6 +15,7 @@ import {isVisible} from "bootstrap/js/src/util/index.js"; Discover Filter Create + Ask DVMs diff --git a/ui/noogle/src/router/index.js b/ui/noogle/src/router/index.js index 5f8c125..f7f088f 100644 --- a/ui/noogle/src/router/index.js +++ b/ui/noogle/src/router/index.js @@ -9,6 +9,7 @@ const routes = [ { path: "/nip89", component: () => import("@/components/Nip89view.vue") }, { path: "/image", component: () => import("@/components/Image.vue") }, { path: "/filter", component: () => import("@/components/FilterGeneration.vue") }, + { path: "/ask", component: () => import("@/components/ChatGeneration.vue") }, { path: "/discover", component: () => import("@/components/RecommendationGeneration.vue") }, { path: "/article/:id", component: () => import("@/components/Home.vue") }, diff --git a/ui/noogle/src/store.js b/ui/noogle/src/store.js index b3306c9..5217311 100644 --- a/ui/noogle/src/store.js +++ b/ui/noogle/src/store.js @@ -19,9 +19,11 @@ const store = createStore({ requestidSearchProfile: String, requestidImage: [], requestidRecommendation: [], + requestidChat: [], requestidSummarization: [], requestidFilter: [], imagedvmreplies: [], + chatdvmreplies: [], nip89dvms: [], activesearchdvms: [], recommendationdvms: [], @@ -31,8 +33,7 @@ const store = createStore({ profile_results: [], relays: ["wss://relay.primal.net", "wss://nostr.mom", "wss://nostr.oxtr.dev", - "wss://relay.nostr.net", - //"wss://relay.nostr.bg", + "wss://relay.nostr.net" ], } }, @@ -126,9 +127,15 @@ const store = createStore({ }, set_current_request_id_recommendation(state, requestid){ state.requestidRecommendation.length = 0 - state.requestidRecommendation.push.apply(state.requestidRecommendation, requestid) - //state.requestidRecommendation = requestid + state.requestidRecommendation.push.apply(state.requestidRecommendation, requestid) }, + set_current_request_id_chat(state, requestid){ + state.requestidChat.length = 0 + state.requestidChat.push.apply(state.requestidChat, requestid) + + }, + + set_search_results(state, results){ state.results.length = 0 @@ -139,6 +146,12 @@ const store = createStore({ state.imagedvmreplies.push.apply(state.imagedvmreplies, results) }, + set_chat_dvm_results(state, results){ + state.chatdvmreplies.length = 0 + state.chatdvmreplies.push.apply(state.chatdvmreplies, results) + }, + + } })