coyotte508 HF staff commited on
Commit
67867a9
1 Parent(s): 4c70bcc

🔧 Configure a base path (#47)

Browse files
.env CHANGED
@@ -4,6 +4,7 @@
4
  MONGODB_URL=#your mongodb URL here
5
  MONGODB_DB_NAME=chat-ui
6
  HF_TOKEN=#your huggingface token here
 
7
 
8
  PUBLIC_MODEL_ENDPOINT=https://api-inference.huggingface.co/models/OpenAssistant/oasst-sft-1-pythia-12b
9
  PUBLIC_MODEL_NAME=OpenAssistant/oasst-sft-1-pythia-12b
 
4
  MONGODB_URL=#your mongodb URL here
5
  MONGODB_DB_NAME=chat-ui
6
  HF_TOKEN=#your huggingface token here
7
+ SHARE_BASE_URL=#https://hf.co/chat
8
 
9
  PUBLIC_MODEL_ENDPOINT=https://api-inference.huggingface.co/models/OpenAssistant/oasst-sft-1-pythia-12b
10
  PUBLIC_MODEL_NAME=OpenAssistant/oasst-sft-1-pythia-12b
package-lock.json CHANGED
@@ -11,6 +11,7 @@
11
  "@huggingface/inference": "^2.0.0-rc2",
12
  "autoprefixer": "^10.4.14",
13
  "date-fns": "^2.29.3",
 
14
  "highlight.js": "^11.7.0",
15
  "marked": "^4.3.0",
16
  "mongodb": "^5.3.0",
@@ -1614,6 +1615,14 @@
1614
  "node": ">=6.0.0"
1615
  }
1616
  },
 
 
 
 
 
 
 
 
1617
  "node_modules/electron-to-chromium": {
1618
  "version": "1.4.359",
1619
  "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.359.tgz",
 
11
  "@huggingface/inference": "^2.0.0-rc2",
12
  "autoprefixer": "^10.4.14",
13
  "date-fns": "^2.29.3",
14
+ "dotenv": "^16.0.3",
15
  "highlight.js": "^11.7.0",
16
  "marked": "^4.3.0",
17
  "mongodb": "^5.3.0",
 
1615
  "node": ">=6.0.0"
1616
  }
1617
  },
1618
+ "node_modules/dotenv": {
1619
+ "version": "16.0.3",
1620
+ "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
1621
+ "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==",
1622
+ "engines": {
1623
+ "node": ">=12"
1624
+ }
1625
+ },
1626
  "node_modules/electron-to-chromium": {
1627
  "version": "1.4.359",
1628
  "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.359.tgz",
package.json CHANGED
@@ -36,6 +36,7 @@
36
  "@huggingface/inference": "^2.0.0-rc2",
37
  "autoprefixer": "^10.4.14",
38
  "date-fns": "^2.29.3",
 
39
  "highlight.js": "^11.7.0",
40
  "marked": "^4.3.0",
41
  "mongodb": "^5.3.0",
 
36
  "@huggingface/inference": "^2.0.0-rc2",
37
  "autoprefixer": "^10.4.14",
38
  "date-fns": "^2.29.3",
39
+ "dotenv": "^16.0.3",
40
  "highlight.js": "^11.7.0",
41
  "marked": "^4.3.0",
42
  "mongodb": "^5.3.0",
src/routes/+layout.svelte CHANGED
@@ -6,6 +6,7 @@
6
 
7
  import CarbonTrashCan from '~icons/carbon/trash-can';
8
  import CarbonExport from '~icons/carbon/export';
 
9
 
10
  export let data: LayoutData;
11
 
@@ -22,7 +23,7 @@
22
 
23
  async function shareConversation(id: string, title: string) {
24
  try {
25
- const res = await fetch(`/conversation/${id}/share`, {
26
  method: 'POST',
27
  headers: {
28
  'Content-Type': 'application/json'
@@ -53,7 +54,7 @@
53
 
54
  async function deleteConversation(id: string) {
55
  try {
56
- const res = await fetch(`/conversation/${id}`, {
57
  method: 'DELETE',
58
  headers: {
59
  'Content-Type': 'application/json'
@@ -85,7 +86,7 @@
85
  >
86
  <div class="flex-none sticky top-0 p-3 flex flex-col">
87
  <a
88
- href="/"
89
  class="border px-12 py-2.5 rounded-lg shadow bg-white dark:bg-gray-700 dark:border-gray-600 text-center"
90
  >
91
  New Chat
@@ -94,7 +95,7 @@
94
  <div class="flex flex-col overflow-y-auto p-3 -mt-3 gap-2">
95
  {#each data.conversations as conv}
96
  <a
97
- href="/conversation/{conv.id}"
98
  class="pl-3 pr-2 h-12 group rounded-lg flex-none text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 flex items-center gap-1 {conv.id ===
99
  $page.params.id
100
  ? 'bg-gray-100 dark:bg-gray-700'
@@ -125,12 +126,13 @@
125
  <div class="flex flex-col p-3 gap-2">
126
  <button
127
  on:click={switchTheme}
 
128
  class="text-left flex items-center first-letter:capitalize truncate py-3 px-3 rounded-lg flex-none text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700"
129
  >
130
  Theme
131
  </button>
132
  <a
133
- href="/"
134
  class="truncate py-3 px-3 rounded-lg flex-none text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700"
135
  >
136
  Settings
 
6
 
7
  import CarbonTrashCan from '~icons/carbon/trash-can';
8
  import CarbonExport from '~icons/carbon/export';
9
+ import { base } from '$app/paths';
10
 
11
  export let data: LayoutData;
12
 
 
23
 
24
  async function shareConversation(id: string, title: string) {
25
  try {
26
+ const res = await fetch(`${base}/conversation/${id}/share`, {
27
  method: 'POST',
28
  headers: {
29
  'Content-Type': 'application/json'
 
54
 
55
  async function deleteConversation(id: string) {
56
  try {
57
+ const res = await fetch(`${base}/conversation/${id}`, {
58
  method: 'DELETE',
59
  headers: {
60
  'Content-Type': 'application/json'
 
86
  >
87
  <div class="flex-none sticky top-0 p-3 flex flex-col">
88
  <a
89
+ href={base}
90
  class="border px-12 py-2.5 rounded-lg shadow bg-white dark:bg-gray-700 dark:border-gray-600 text-center"
91
  >
92
  New Chat
 
95
  <div class="flex flex-col overflow-y-auto p-3 -mt-3 gap-2">
96
  {#each data.conversations as conv}
97
  <a
98
+ href="{base}/conversation/{conv.id}"
99
  class="pl-3 pr-2 h-12 group rounded-lg flex-none text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 flex items-center gap-1 {conv.id ===
100
  $page.params.id
101
  ? 'bg-gray-100 dark:bg-gray-700'
 
126
  <div class="flex flex-col p-3 gap-2">
127
  <button
128
  on:click={switchTheme}
129
+ type="button"
130
  class="text-left flex items-center first-letter:capitalize truncate py-3 px-3 rounded-lg flex-none text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700"
131
  >
132
  Theme
133
  </button>
134
  <a
135
+ href={base}
136
  class="truncate py-3 px-3 rounded-lg flex-none text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700"
137
  >
138
  Settings
src/routes/+page.svelte CHANGED
@@ -1,5 +1,6 @@
1
  <script lang="ts">
2
  import { goto } from '$app/navigation';
 
3
  import ChatWindow from '$lib/components/chat/ChatWindow.svelte';
4
  import { pendingMessage } from '$lib/stores/pendingMessage';
5
 
@@ -8,7 +9,7 @@
8
  async function createConversation(message: string) {
9
  try {
10
  loading = true;
11
- const res = await fetch('/conversation', {
12
  method: 'POST',
13
  headers: {
14
  'Content-Type': 'application/json'
@@ -26,7 +27,7 @@
26
  pendingMessage.set(message);
27
 
28
  // invalidateAll to update list of conversations
29
- await goto(`/conversation/${conversationId}`, { invalidateAll: true });
30
  } finally {
31
  loading = false;
32
  }
 
1
  <script lang="ts">
2
  import { goto } from '$app/navigation';
3
+ import { base } from '$app/paths';
4
  import ChatWindow from '$lib/components/chat/ChatWindow.svelte';
5
  import { pendingMessage } from '$lib/stores/pendingMessage';
6
 
 
9
  async function createConversation(message: string) {
10
  try {
11
  loading = true;
12
+ const res = await fetch(`${base}/conversation`, {
13
  method: 'POST',
14
  headers: {
15
  'Content-Type': 'application/json'
 
27
  pendingMessage.set(message);
28
 
29
  // invalidateAll to update list of conversations
30
+ await goto(`${base}/conversation/${conversationId}`, { invalidateAll: true });
31
  } finally {
32
  loading = false;
33
  }
src/routes/conversation/[id]/share/+server.ts CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import { collections } from '$lib/server/database.js';
2
  import type { SharedConversation } from '$lib/types/SharedConversation.js';
3
  import { sha256 } from '$lib/utils/sha256.js';
@@ -22,7 +24,7 @@ export async function POST({ params, url, locals }) {
22
  if (existingShare) {
23
  return new Response(
24
  JSON.stringify({
25
- url: url.origin + `/r/${existingShare._id}`
26
  }),
27
  { headers: { 'Content-Type': 'application/json' } }
28
  );
@@ -41,7 +43,7 @@ export async function POST({ params, url, locals }) {
41
 
42
  return new Response(
43
  JSON.stringify({
44
- url: url.origin.replace('huggingface.co', 'hf.co') + `/r/${shared._id}`
45
  }),
46
  { headers: { 'Content-Type': 'application/json' } }
47
  );
 
1
+ import { base } from '$app/paths';
2
+ import { SHARE_BASE_URL } from '$env/static/private';
3
  import { collections } from '$lib/server/database.js';
4
  import type { SharedConversation } from '$lib/types/SharedConversation.js';
5
  import { sha256 } from '$lib/utils/sha256.js';
 
24
  if (existingShare) {
25
  return new Response(
26
  JSON.stringify({
27
+ url: url.origin + `${base}/r/${existingShare._id}`
28
  }),
29
  { headers: { 'Content-Type': 'application/json' } }
30
  );
 
43
 
44
  return new Response(
45
  JSON.stringify({
46
+ url: (SHARE_BASE_URL || `${url.origin}${base}`) + `/r/${shared._id}`
47
  }),
48
  { headers: { 'Content-Type': 'application/json' } }
49
  );
svelte.config.js CHANGED
@@ -1,5 +1,9 @@
1
  import adapter from '@sveltejs/adapter-node';
2
  import { vitePreprocess } from '@sveltejs/kit/vite';
 
 
 
 
3
 
4
  /** @type {import('@sveltejs/kit').Config} */
5
  const config = {
@@ -8,7 +12,11 @@ const config = {
8
  preprocess: vitePreprocess(),
9
 
10
  kit: {
11
- adapter: adapter()
 
 
 
 
12
  }
13
  };
14
 
 
1
  import adapter from '@sveltejs/adapter-node';
2
  import { vitePreprocess } from '@sveltejs/kit/vite';
3
+ import dotenv from 'dotenv';
4
+
5
+ dotenv.config({ path: './.env.local' });
6
+ dotenv.config({ path: './.env' });
7
 
8
  /** @type {import('@sveltejs/kit').Config} */
9
  const config = {
 
12
  preprocess: vitePreprocess(),
13
 
14
  kit: {
15
+ adapter: adapter(),
16
+
17
+ paths: {
18
+ base: process.env.APP_BASE || ''
19
+ }
20
  }
21
  };
22