wirejs-resources 0.1.148-llm → 0.1.149-llm

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.
@@ -13,17 +13,21 @@ export type ContinueConversationOptions = {
13
13
  onChunk?: (chunk: LLMChunk) => void | Promise<void>;
14
14
  timeoutSeconds?: number;
15
15
  systemPrompt?: string;
16
+ models?: string[];
17
+ targetContextSize?: number;
16
18
  };
17
19
  export declare class LLM extends Resource {
18
20
  models: string[];
19
21
  systemPrompt: string | undefined;
22
+ targetContextSize: number;
20
23
  constructor(scope: Resource | string, id: string, options: {
21
24
  models: string[];
22
25
  systemPrompt?: string;
26
+ targetContextSize?: number;
23
27
  });
24
28
  private stream;
25
29
  private checkOllamaAvailable;
26
30
  private checkModelExists;
27
31
  private createStreamedString;
28
- continueConversation({ history, onChunk, timeoutSeconds, systemPrompt, }: ContinueConversationOptions): Promise<LLMMessage>;
32
+ continueConversation({ history, onChunk, timeoutSeconds, systemPrompt, targetContextSize, models, }: ContinueConversationOptions): Promise<LLMMessage>;
29
33
  }
@@ -2,10 +2,12 @@ import { Resource } from '../resource.js';
2
2
  export class LLM extends Resource {
3
3
  models;
4
4
  systemPrompt;
5
+ targetContextSize;
5
6
  constructor(scope, id, options) {
6
7
  super(scope, id);
7
8
  this.models = options.models;
8
9
  this.systemPrompt = options.systemPrompt;
10
+ this.targetContextSize = options.targetContextSize ?? 16384;
9
11
  }
10
12
  async stream(response, onChunk) {
11
13
  if (!response.ok || !response.body) {
@@ -77,7 +79,7 @@ export class LLM extends Resource {
77
79
  content: message
78
80
  };
79
81
  }
80
- async continueConversation({ history, onChunk, timeoutSeconds, systemPrompt, }) {
82
+ async continueConversation({ history, onChunk, timeoutSeconds, systemPrompt, targetContextSize, models, }) {
81
83
  const ollamaAvailable = await this.checkOllamaAvailable();
82
84
  if (!ollamaAvailable) {
83
85
  return this.createStreamedString('Ollama is not running locally. Please install and start Ollama:\n\n' +
@@ -87,7 +89,7 @@ export class LLM extends Resource {
87
89
  'Models to try installing: ' + this.models.join(', '), onChunk);
88
90
  }
89
91
  // models should be in priority order. so, first one that works is the one we want.
90
- for (const model of this.models) {
92
+ for (const model of models ?? this.models) {
91
93
  const modelExists = await this.checkModelExists(model);
92
94
  if (!modelExists)
93
95
  continue;
@@ -116,6 +118,9 @@ export class LLM extends Resource {
116
118
  ...history
117
119
  ],
118
120
  stream,
121
+ options: {
122
+ num_ctx: targetContextSize ?? this.targetContextSize
123
+ }
119
124
  }),
120
125
  signal: controller.signal
121
126
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wirejs-resources",
3
- "version": "0.1.148-llm",
3
+ "version": "0.1.149-llm",
4
4
  "description": "Basic services and server-side resources for wirejs apps",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",