llms-py 3.0.0b1__py3-none-any.whl → 3.0.0b3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. llms/__pycache__/__init__.cpython-312.pyc +0 -0
  2. llms/__pycache__/__init__.cpython-313.pyc +0 -0
  3. llms/__pycache__/__init__.cpython-314.pyc +0 -0
  4. llms/__pycache__/__main__.cpython-312.pyc +0 -0
  5. llms/__pycache__/__main__.cpython-314.pyc +0 -0
  6. llms/__pycache__/llms.cpython-312.pyc +0 -0
  7. llms/__pycache__/main.cpython-312.pyc +0 -0
  8. llms/__pycache__/main.cpython-313.pyc +0 -0
  9. llms/__pycache__/main.cpython-314.pyc +0 -0
  10. llms/__pycache__/plugins.cpython-314.pyc +0 -0
  11. llms/index.html +27 -57
  12. llms/llms.json +48 -15
  13. llms/main.py +923 -624
  14. llms/providers/__pycache__/anthropic.cpython-314.pyc +0 -0
  15. llms/providers/__pycache__/chutes.cpython-314.pyc +0 -0
  16. llms/providers/__pycache__/google.cpython-314.pyc +0 -0
  17. llms/providers/__pycache__/nvidia.cpython-314.pyc +0 -0
  18. llms/providers/__pycache__/openai.cpython-314.pyc +0 -0
  19. llms/providers/__pycache__/openrouter.cpython-314.pyc +0 -0
  20. llms/providers/anthropic.py +189 -0
  21. llms/providers/chutes.py +152 -0
  22. llms/providers/google.py +306 -0
  23. llms/providers/nvidia.py +107 -0
  24. llms/providers/openai.py +159 -0
  25. llms/providers/openrouter.py +70 -0
  26. llms/providers-extra.json +356 -0
  27. llms/providers.json +1 -1
  28. llms/ui/App.mjs +150 -57
  29. llms/ui/ai.mjs +84 -50
  30. llms/ui/app.css +1 -4963
  31. llms/ui/ctx.mjs +196 -0
  32. llms/ui/index.mjs +117 -0
  33. llms/ui/lib/charts.mjs +9 -13
  34. llms/ui/markdown.mjs +6 -0
  35. llms/ui/{Analytics.mjs → modules/analytics.mjs} +76 -64
  36. llms/ui/{Main.mjs → modules/chat/ChatBody.mjs} +91 -179
  37. llms/ui/{SettingsDialog.mjs → modules/chat/SettingsDialog.mjs} +8 -8
  38. llms/ui/{ChatPrompt.mjs → modules/chat/index.mjs} +281 -96
  39. llms/ui/modules/layout.mjs +267 -0
  40. llms/ui/modules/model-selector.mjs +851 -0
  41. llms/ui/{Recents.mjs → modules/threads/Recents.mjs} +10 -11
  42. llms/ui/{Sidebar.mjs → modules/threads/index.mjs} +48 -45
  43. llms/ui/{threadStore.mjs → modules/threads/threadStore.mjs} +21 -7
  44. llms/ui/tailwind.input.css +441 -79
  45. llms/ui/utils.mjs +83 -123
  46. {llms_py-3.0.0b1.dist-info → llms_py-3.0.0b3.dist-info}/METADATA +1 -1
  47. llms_py-3.0.0b3.dist-info/RECORD +65 -0
  48. llms/ui/Avatar.mjs +0 -85
  49. llms/ui/Brand.mjs +0 -52
  50. llms/ui/ModelSelector.mjs +0 -693
  51. llms/ui/OAuthSignIn.mjs +0 -92
  52. llms/ui/ProviderIcon.mjs +0 -36
  53. llms/ui/ProviderStatus.mjs +0 -105
  54. llms/ui/SignIn.mjs +0 -64
  55. llms/ui/SystemPromptEditor.mjs +0 -31
  56. llms/ui/SystemPromptSelector.mjs +0 -56
  57. llms/ui/Welcome.mjs +0 -8
  58. llms/ui.json +0 -1069
  59. llms_py-3.0.0b1.dist-info/RECORD +0 -49
  60. {llms_py-3.0.0b1.dist-info → llms_py-3.0.0b3.dist-info}/WHEEL +0 -0
  61. {llms_py-3.0.0b1.dist-info → llms_py-3.0.0b3.dist-info}/entry_points.txt +0 -0
  62. {llms_py-3.0.0b1.dist-info → llms_py-3.0.0b3.dist-info}/licenses/LICENSE +0 -0
  63. {llms_py-3.0.0b1.dist-info → llms_py-3.0.0b3.dist-info}/top_level.txt +0 -0
llms/ui/App.mjs CHANGED
@@ -1,97 +1,190 @@
1
- import { inject, ref, onMounted, onUnmounted } from "vue"
2
- import Sidebar from "./Sidebar.mjs"
1
+ import { ref, computed, watch, inject, onMounted, onUnmounted } from "vue"
2
+ import { useRouter, useRoute } from "vue-router"
3
+ import { AppContext } from "./ctx.mjs"
4
+
5
+ // Vertical Sidebar Icons
6
+ const LeftBar = {
7
+ template: `
8
+ <div class="flex flex-col space-y-2 pt-2.5 px-1">
9
+ <div v-for="(icon, id) in $ctx.left" :key="id" class="relative flex items-center justify-center">
10
+ <component :is="icon.component"
11
+ class="size-7 p-1 cursor-pointer text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 rounded block"
12
+ :class="{ 'bg-gray-200 dark:bg-gray-700' : icon.isActive({ ...$layout }) }"
13
+ @mouseenter="tooltip = icon.id"
14
+ @mouseleave="tooltip = ''"
15
+ />
16
+ <div v-if="tooltip === icon.id && !icon.isActive({ ...$layout })"
17
+ class="absolute left-full top-1/2 -translate-y-1/2 ml-2 px-2 py-1 text-xs text-white bg-gray-900 dark:bg-gray-800 rounded shadow-md z-50 whitespace-nowrap pointer-events-none" style="z-index: 60">
18
+ {{icon.name}}
19
+ </div>
20
+ </div>
21
+ </div>
22
+ `,
23
+ setup() {
24
+ const tooltip = ref('')
25
+ return {
26
+ tooltip,
27
+ }
28
+ }
29
+ }
30
+
31
+ const LeftPanel = {
32
+ template: `
33
+ <div v-if="component" class="flex flex-col h-full border-r border-gray-200 dark:border-gray-700">
34
+ <button type="button" @click="$emit('toggle-sidebar')" class="absolute top-2 right-2 p-1 rounded-md text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-700 lg:hidden z-20">
35
+ <svg class="size-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>
36
+ </button>
37
+ <component :is="component" />
38
+ </div>
39
+ `,
40
+ setup() {
41
+ /**@type {AppContext} */
42
+ const ctx = inject('ctx')
43
+ const component = computed(() => ctx.component(ctx.layout.left))
44
+ return {
45
+ component,
46
+ }
47
+ }
48
+ }
49
+
50
+ const TopBar = {
51
+ template: `
52
+ <div class="flex space-x-2">
53
+ <div v-for="(icon, id) in $ctx.top" :key="id" class="relative flex items-center justify-center">
54
+ <component :is="icon.component"
55
+ class="size-7 p-1 cursor-pointer text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 block"
56
+ :class="{ 'bg-gray-100 dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded' : icon.isActive({ ...$layout }) }"
57
+ @mouseenter="tooltip = icon.id"
58
+ @mouseleave="tooltip = ''"
59
+ />
60
+ <div v-if="tooltip === icon.id && !icon.isActive({ ...$layout })"
61
+ class="absolute top-full mt-2 px-2 py-1 text-xs text-white bg-gray-900 dark:bg-gray-800 rounded shadow-md z-50 whitespace-nowrap pointer-events-none"
62
+ :class="last2.includes(id) ? 'right-0' : 'left-1/2 -translate-x-1/2'">
63
+ {{icon.name}}
64
+ </div>
65
+ </div>
66
+ </div>
67
+ `,
68
+ setup() {
69
+ const tooltip = ref('')
70
+ const last2 = ref(Object.keys($ctx.top).slice(-2))
71
+ return {
72
+ tooltip,
73
+ last2,
74
+ }
75
+ }
76
+ }
77
+
78
+ const TopPanel = {
79
+ template: `
80
+ <component v-if="component" :is="component" class="mb-2" />
81
+ `,
82
+ setup() {
83
+ /**@type {AppContext} */
84
+ const ctx = inject('ctx')
85
+ const component = computed(() => ctx.component(ctx.layout.top))
86
+ return {
87
+ component,
88
+ }
89
+ }
90
+ }
3
91
 
4
92
  export default {
5
93
  components: {
6
- Sidebar,
94
+ LeftBar,
95
+ LeftPanel,
96
+ TopBar,
97
+ TopPanel,
7
98
  },
8
99
  setup() {
9
- const ai = inject('ai')
100
+ const router = useRouter()
101
+ const route = useRoute()
102
+
103
+ /**@type {AppContext} */
104
+ const ctx = inject('ctx')
105
+ const ai = ctx.ai
10
106
  const isMobile = ref(false)
107
+ const modal = ref()
11
108
 
12
109
  const checkMobile = () => {
13
- const wasMobile = isMobile.value
14
- isMobile.value = window.innerWidth < 1024 // lg breakpoint
110
+ //const wasMobile = isMobile.value
111
+ isMobile.value = window.innerWidth < 640 // sm breakpoint
15
112
 
113
+ //console.log('checkMobile', wasMobile, isMobile.value)
16
114
  // Only auto-adjust sidebar state when transitioning between mobile/desktop
17
- if (wasMobile !== isMobile.value) {
18
- if (isMobile.value) {
19
- ai.isSidebarOpen = false
20
- } else {
21
- ai.isSidebarOpen = true
22
- }
23
- }
24
- }
25
-
26
- const toggleSidebar = () => {
27
- ai.isSidebarOpen = !ai.isSidebarOpen
28
- }
29
-
30
- const closeSidebar = () => {
31
115
  if (isMobile.value) {
32
- ai.isSidebarOpen = false
116
+ ctx.toggleLayout('left', false)
33
117
  }
34
118
  }
35
119
 
36
120
  onMounted(() => {
37
121
  checkMobile()
38
122
  window.addEventListener('resize', checkMobile)
123
+ if (route.query.open) {
124
+ modal.value = ctx.openModal(route.query.open)
125
+ }
39
126
  })
40
127
 
41
128
  onUnmounted(() => {
42
129
  window.removeEventListener('resize', checkMobile)
43
130
  })
44
131
 
45
- return { ai, isMobile, toggleSidebar, closeSidebar }
132
+ function closeModal() {
133
+ ctx.closeModal(route.query.open)
134
+ }
135
+
136
+ watch(() => route.query.open, (newVal) => {
137
+ modal.value = ctx.modalComponents[newVal]
138
+ console.log('open', newVal, modal.value)
139
+ })
140
+
141
+ watch(() => ctx.state.selectedModel, (newVal) => {
142
+ ctx.chat.setSelectedModel(ctx.chat.getModel(newVal))
143
+ })
144
+
145
+ return { ai, modal, isMobile, closeModal }
46
146
  },
47
147
  template: `
48
- <div class="flex h-screen bg-white dark:bg-gray-900">
148
+ <div class="flex h-screen">
49
149
  <!-- Mobile Overlay -->
50
150
  <div
51
- v-if="isMobile && ai.isSidebarOpen && !(ai.requiresAuth && !ai.auth)"
52
- @click="closeSidebar"
151
+ v-if="isMobile && $ctx.layoutVisible('left') && $ai.hasAccess"
152
+ @click="$ctx.toggleLayout('left')"
53
153
  class="fixed inset-0 bg-black/50 z-40 lg:hidden"
54
154
  ></div>
55
155
 
56
- <!-- Sidebar (hidden when auth required and not authenticated) -->
57
- <div
58
- v-if="!(ai.requiresAuth && !ai.auth) && ai.isSidebarOpen"
59
- :class="[
60
- 'transition-transform duration-300 ease-in-out z-50',
61
- 'w-72 xl:w-80 flex-shrink-0',
62
- 'lg:relative',
63
- 'fixed inset-y-0 left-0'
64
- ]"
65
- >
66
- <Sidebar @thread-selected="closeSidebar" @toggle-sidebar="toggleSidebar" />
156
+ <div id="sidebar" class="z-100 relative flex bg-gray-50 dark:bg-gray-800">
157
+ <LeftBar />
158
+ <LeftPanel
159
+ v-if="$ai.hasAccess && $ctx.layoutVisible('left')"
160
+ :class="[
161
+ 'transition-transform duration-300 ease-in-out z-50',
162
+ 'w-72 xl:w-80 flex-shrink-0',
163
+ 'lg:relative',
164
+ 'fixed inset-y-0 left-[2.25rem] lg:left-0',
165
+ 'bg-gray-50 dark:bg-gray-800'
166
+ ]"
167
+ @thread-selected="$ctx.toggleLayout('left',false)" @toggle-sidebar="$ctx.toggleLayout('left')"
168
+ />
67
169
  </div>
68
170
 
69
171
  <!-- Main Area -->
70
172
  <div class="flex-1 flex flex-col">
71
- <!-- Collapsed Sidebar Toggle Button -->
72
- <div
73
- v-if="!(ai.requiresAuth && !ai.auth) && !ai.isSidebarOpen"
74
- class="fixed top-4 left-0"
75
- >
76
- <button type="button"
77
- @click="toggleSidebar"
78
- class="group p-1 text-gray-500 dark:text-gray-400 hover:text-blue-600 dark:hover:text-blue-400 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors"
79
- title="Open sidebar"
80
- >
81
- <div class="relative w-5 h-5">
82
- <!-- Default sidebar icon -->
83
- <svg class="absolute inset-0 group-hover:hidden" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
84
- <rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect>
85
- <line x1="9" y1="3" x2="9" y2="21"></line>
86
- </svg>
87
- <!-- Hover state: |→ icon -->
88
- <svg class="absolute inset-0 hidden group-hover:block" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="currentColor" d="m17.172 11l-4.657-4.657l1.414-1.414L21 12l-7.071 7.071l-1.414-1.414L17.172 13H8v-2zM4 19V5h2v14z"/></svg>
173
+ <div class="flex flex-col h-full w-full overflow-hidden">
174
+ <div class="py-1 pr-1 flex items-center justify-between shrink-0">
175
+ <div>
176
+ <ModelSelector :models="$state.models" v-model="$state.selectedModel" />
89
177
  </div>
90
- </button>
178
+ <TopBar />
179
+ </div>
180
+ <TopPanel class="shrink-0" />
181
+ <div class="flex-1 overflow-hidden min-h-0 flex flex-col">
182
+ <RouterView class="h-full" />
183
+ </div>
91
184
  </div>
92
-
93
- <RouterView />
94
185
  </div>
186
+
187
+ <component v-if="modal" :is="modal" class="!z-[200]" @done="closeModal" />
95
188
  </div>
96
189
  `,
97
190
  }
llms/ui/ai.mjs CHANGED
@@ -1,12 +1,11 @@
1
1
  import { reactive } from "vue"
2
- import { useThreadStore } from "./threadStore.mjs"
3
2
 
4
3
  const base = ''
5
4
  const headers = { 'Accept': 'application/json' }
6
5
  const prefsKey = 'llms.prefs'
7
6
 
8
7
  export const o = {
9
- version: '3.0.0b1',
8
+ version: '3.0.0b3',
10
9
  base,
11
10
  prefsKey,
12
11
  welcome: 'Welcome to llms.py',
@@ -15,6 +14,11 @@ export const o = {
15
14
  authType: 'apikey', // 'oauth' or 'apikey' - controls which SignIn component to use
16
15
  headers,
17
16
  isSidebarOpen: true, // Shared sidebar state (default open for lg+ screens)
17
+ cacheUrlInfo: {},
18
+
19
+ get hasAccess() {
20
+ return !this.requiresAuth || this.auth
21
+ },
18
22
 
19
23
  resolveUrl(url) {
20
24
  return url.startsWith('http') || url.startsWith('/v1') ? url : base + url
@@ -25,6 +29,17 @@ export const o = {
25
29
  headers: Object.assign({}, this.headers, options?.headers),
26
30
  })
27
31
  },
32
+ async getJson(url, options) {
33
+ const res = await this.get(url, options)
34
+ let txt = ''
35
+ try {
36
+ txt = await res.text()
37
+ return JSON.parse(txt)
38
+ } catch (e) {
39
+ console.error('Failed to parse JSON from GET', url, e, txt)
40
+ return { responseStatus: { errorCode: 'Error', message: `GET failed: ${e.message ?? e}` } }
41
+ }
42
+ },
28
43
  post(url, options) {
29
44
  return fetch(this.resolveUrl(url), {
30
45
  method: 'POST',
@@ -32,6 +47,17 @@ export const o = {
32
47
  headers: Object.assign({ 'Content-Type': 'application/json' }, this.headers, options?.headers),
33
48
  })
34
49
  },
50
+ async postJson(url, options) {
51
+ const res = await this.post(url, options)
52
+ let txt = ''
53
+ try {
54
+ txt = await res.text()
55
+ return JSON.parse(txt)
56
+ } catch (e) {
57
+ console.error('Failed to parse JSON from POST', url, e, txt)
58
+ return { responseStatus: { errorCode: 'Error', message: `POST failed: ${e.message ?? e}` } }
59
+ }
60
+ },
35
61
 
36
62
  async getConfig() {
37
63
  return this.get('/config')
@@ -52,51 +78,33 @@ export const o = {
52
78
  this.auth = auth
53
79
  if (auth?.apiKey) {
54
80
  this.headers.Authorization = `Bearer ${auth.apiKey}`
55
- //localStorage.setItem('llms:auth', JSON.stringify({ apiKey: auth.apiKey }))
56
- } else if (auth?.sessionToken) {
57
- this.headers['X-Session-Token'] = auth.sessionToken
58
- localStorage.setItem('llms:auth', JSON.stringify({ sessionToken: auth.sessionToken }))
59
81
  } else {
60
82
  if (this.headers.Authorization) {
61
83
  delete this.headers.Authorization
62
84
  }
63
- if (this.headers['X-Session-Token']) {
64
- delete this.headers['X-Session-Token']
65
- }
66
85
  }
67
86
  },
68
87
  async signOut() {
69
- if (this.auth?.sessionToken) {
70
- // Call logout endpoint for OAuth sessions
71
- try {
72
- await this.post('/auth/logout', {
73
- headers: {
74
- 'X-Session-Token': this.auth.sessionToken
75
- }
76
- })
77
- } catch (error) {
78
- console.error('Logout error:', error)
79
- }
88
+ try {
89
+ await this.post('/auth/logout')
90
+ } catch (error) {
91
+ console.error('Logout error:', error)
80
92
  }
81
93
  this.auth = null
82
94
  if (this.headers.Authorization) {
83
95
  delete this.headers.Authorization
84
96
  }
85
- if (this.headers['X-Session-Token']) {
86
- delete this.headers['X-Session-Token']
87
- }
88
- localStorage.removeItem('llms:auth')
89
97
  },
90
- async init() {
98
+ async init(ctx) {
91
99
  // Load models and prompts
92
- const { initDB } = useThreadStore()
93
- const [_, configRes, modelsRes] = await Promise.all([
94
- initDB(),
100
+ const [configRes, modelsRes, extensionsRes] = await Promise.all([
95
101
  this.getConfig(),
96
102
  this.getModels(),
103
+ this.get('/ext'),
97
104
  ])
98
105
  const config = await configRes.json()
99
106
  const models = await modelsRes.json()
107
+ const extensions = await extensionsRes.json()
100
108
 
101
109
  // Update auth settings from server config
102
110
  if (config.requiresAuth != null) {
@@ -106,25 +114,6 @@ export const o = {
106
114
  this.authType = config.authType
107
115
  }
108
116
 
109
- // Try to restore session from localStorage
110
- if (this.requiresAuth) {
111
- const storedAuth = localStorage.getItem('llms:auth')
112
- if (storedAuth) {
113
- try {
114
- const authData = JSON.parse(storedAuth)
115
- if (authData.sessionToken) {
116
- this.headers['X-Session-Token'] = authData.sessionToken
117
- }
118
- // else if (authData.apiKey) {
119
- // this.headers.Authorization = `Bearer ${authData.apiKey}`
120
- // }
121
- } catch (e) {
122
- console.error('Failed to restore auth from localStorage:', e)
123
- localStorage.removeItem('llms:auth')
124
- }
125
- }
126
- }
127
-
128
117
  // Get auth status
129
118
  const authRes = await this.getAuth()
130
119
  const auth = this.requiresAuth
@@ -132,14 +121,59 @@ export const o = {
132
121
  : null
133
122
  if (auth?.responseStatus?.errorCode) {
134
123
  console.error(auth.responseStatus.errorCode, auth.responseStatus.message)
135
- // Clear invalid session from localStorage
136
- localStorage.removeItem('llms:auth')
137
124
  } else {
138
125
  this.signIn(auth)
139
126
  }
140
- return { config, models, auth }
127
+ return { config, models, extensions, auth }
128
+ },
129
+
130
+
131
+ async uploadFile(file) {
132
+ const formData = new FormData()
133
+ formData.append('file', file)
134
+ const response = await fetch(this.resolveUrl('/upload'), {
135
+ method: 'POST',
136
+ body: formData
137
+ })
138
+ if (!response.ok) {
139
+ throw new Error(`Upload failed: ${response.statusText}`)
140
+ }
141
+ return response.json()
142
+ },
143
+
144
+
145
+ getCacheInfo(url) {
146
+ return this.cacheUrlInfo[url]
147
+ },
148
+ async fetchCacheInfos(urls) {
149
+ const infos = {}
150
+ const fetchInfos = []
151
+ for (const url of urls) {
152
+ const info = this.getCacheInfo(url)
153
+ if (info) {
154
+ infos[url] = info
155
+ } else {
156
+ fetchInfos.push(fetch(this.resolveUrl(url + "?info")))
157
+ }
158
+ }
159
+ const responses = await Promise.all(fetchInfos)
160
+ for (let i = 0; i < urls.length; i++) {
161
+ try {
162
+ const info = await responses[i].json()
163
+ this.setCacheInfo(urls[i], info)
164
+ infos[urls[i]] = info
165
+ } catch (e) {
166
+ console.error('Failed to fetch info for', urls[i], e)
167
+ }
168
+ }
169
+ return infos
170
+ },
171
+ setCacheInfo(url, info) {
172
+ this.cacheUrlInfo[url] = info
141
173
  }
174
+
142
175
  }
143
176
 
177
+
144
178
  let ai = reactive(o)
145
179
  export default ai