File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
services/ai-bot/pod-ai-bot/src Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ import { WorkspaceInfoRecord } from '@hcengineering/server-ai-bot'
42
42
import { getAccountClient } from '@hcengineering/server-client'
43
43
import { generateToken } from '@hcengineering/server-token'
44
44
import { htmlToMarkup , jsonToHTML , jsonToMarkup , markupToJSON } from '@hcengineering/text'
45
- import { encodingForModel } from 'js-tiktoken'
45
+ import { encodingForModel , getEncoding } from 'js-tiktoken'
46
46
import OpenAI from 'openai'
47
47
48
48
import chunter from '@hcengineering/chunter'
@@ -66,7 +66,18 @@ export class AIControl {
66
66
readonly storageAdapter : StorageAdapter
67
67
68
68
private readonly openai ?: OpenAI
69
- private readonly openaiEncoding = encodingForModel ( config . OpenAIModel )
69
+
70
+ // Try to obtain the encoding for the configured model. If the model is not recognised by js-tiktoken
71
+ // (e.g. non-OpenAI models such as Together AI Llama derivatives) we gracefully fall back to the
72
+ // universal `cl100k_base` encoding. This prevents a runtime "Unknown model" error while still
73
+ // giving us a reasonable token count estimate for summaries.
74
+ private readonly openaiEncoding = ( ( ) => {
75
+ try {
76
+ return encodingForModel ( config . OpenAIModel )
77
+ } catch ( err ) {
78
+ return getEncoding ( 'cl100k_base' )
79
+ }
80
+ } ) ( )
70
81
71
82
constructor (
72
83
readonly personUuid : AccountUuid ,
You can’t perform that action at this time.
0 commit comments