llms-py 3.0.18__py3-none-any.whl → 3.0.20__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.
llms/ui/ctx.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  import { reactive, markRaw } from 'vue'
3
3
  import { EventBus, humanize, combinePaths } from "@servicestack/client"
4
- import { storageObject, isHtml } from './utils.mjs'
4
+ import { storageObject, isHtml, sanitizeHtml } from './utils.mjs'
5
5
 
6
6
  export class ExtensionScope {
7
7
  constructor(ctx, id) {
@@ -126,7 +126,7 @@ export class ExtensionScope {
126
126
  }
127
127
 
128
128
  export class AppContext {
129
- constructor({ app, routes, ai, fmt, utils, marked }) {
129
+ constructor({ app, routes, ai, fmt, utils, marked, markedFallback }) {
130
130
  this.app = app
131
131
  this.routes = routes
132
132
  this.ai = ai
@@ -134,6 +134,7 @@ export class AppContext {
134
134
  this.utils = utils
135
135
  this._components = {}
136
136
  this.marked = marked
137
+ this.markedFallback = markedFallback
137
138
 
138
139
  this.state = reactive({})
139
140
  this.events = new EventBus()
@@ -397,7 +398,19 @@ export class AppContext {
397
398
  const header = content.substring(3, headerEnd).trim()
398
399
  content = '<div class="frontmatter">' + header + '</div>\n' + content.substring(headerEnd + 3)
399
400
  }
400
- return this.marked.parse(content || '')
401
+ let html = content || ''
402
+ try {
403
+ html = this.marked.parse(content || '')
404
+ } catch (e) {
405
+ console.log('Failed to parse markdown, using fallback', e)
406
+ try {
407
+ html = this.markedFallback.parse(content || '')
408
+ } catch (e2) {
409
+ console.log('Failed to parse markdown, using raw content', e2)
410
+ html = content || ''
411
+ }
412
+ }
413
+ return sanitizeHtml(html)
401
414
  }
402
415
 
403
416
  renderContent(content) {
llms/ui/index.mjs CHANGED
@@ -9,7 +9,7 @@ import ChatModule from './modules/chat/index.mjs'
9
9
  import ModelSelectorModule from './modules/model-selector.mjs'
10
10
  import IconsModule from './modules/icons.mjs'
11
11
  import { utilsFunctions, utilsFormatters } from './utils.mjs'
12
- import { marked } from './markdown.mjs'
12
+ import { marked, markedFallback } from './markdown.mjs'
13
13
  import { AppContext } from './ctx.mjs'
14
14
 
15
15
  const Components = {
@@ -35,7 +35,7 @@ export async function createContext() {
35
35
  const utils = Object.assign({}, utilsFunctions())
36
36
  const routes = []
37
37
 
38
- const ctx = new AppContext({ app, routes, ai, fmt, utils, marked })
38
+ const ctx = new AppContext({ app, routes, ai, fmt, utils, marked, markedFallback })
39
39
  app.provide('ctx', ctx)
40
40
  await ctx.init()
41
41