@modular-prompt/driver 0.11.7 → 0.11.8

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.
@@ -433,8 +433,8 @@ function extractJsonObject(text, start) {
433
433
  }
434
434
  /**
435
435
  * context-1形式のtool callをパース
436
- * 出力形式(<|call|> stop tokenで切断済み):
437
- * to=functions.{name}<|channel|>commentary json<|message|>{"key": "value"}
436
+ * 出力形式:
437
+ * to=functions.{name}<|channel|>commentary json<|message|>{"key": "value"}<|call|>
438
438
  */
439
439
  function parseContext1ToolCalls(text) {
440
440
  const toolCalls = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modular-prompt/driver",
3
- "version": "0.11.7",
3
+ "version": "0.11.8",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -175,9 +175,7 @@ def handle_chat(messages, primer=None, options=None, tools=None):
175
175
  prompt = primer.join(prompt.split(primer)[0:-1]) + primer
176
176
  print(primer, end='', flush=True)
177
177
 
178
- # tools提供時、call_end を追加 stop token として渡す
179
- stop_token_ids = get_tool_stop_token_ids() if tools else None
180
- generate_text(prompt, options, stop_token_ids=stop_token_ids)
178
+ generate_text(prompt, options)
181
179
 
182
180
 
183
181
  def generate_merged_prompt(messages):
@@ -332,30 +330,7 @@ def generate_text_vlm(prompt, images, options, stop_token_ids=None):
332
330
  print('\n', end='\0', flush=True)
333
331
 
334
332
 
335
- def get_tool_stop_token_ids():
336
- """tool_call_format.call_end または special_tokens.tool_call_end を stop token ID に変換(汎用)"""
337
- stop_ids = set()
338
-
339
- # 1. tool_call_format.call_end から取得
340
- tcf = capabilities.get('features', {}).get('chat_template', {}).get('tool_call_format')
341
- call_end = tcf.get('call_end') if tcf else None
342
- if call_end:
343
- token_id = tokenizer.convert_tokens_to_ids(call_end)
344
- unk_id = getattr(tokenizer, 'unk_token_id', None)
345
- if token_id is not None and token_id != unk_id:
346
- stop_ids.add(int(token_id))
347
-
348
- # 2. special_tokens.tool_call_end から直接 ID を取得(フォールバック)
349
- tce = capabilities.get('special_tokens', {}).get('tool_call_end')
350
- if tce and isinstance(tce, dict) and 'id' in tce:
351
- stop_ids.add(int(tce['id']))
352
-
353
- if stop_ids:
354
- sys.stderr.write(f"--- tool stop token IDs: {stop_ids}\n")
355
- return stop_ids if stop_ids else None
356
-
357
-
358
- def generate_text(prompt, options, stop_token_ids=None):
333
+ def generate_text(prompt, options):
359
334
  """テキスト生成の共通処理
360
335
 
361
336
  注意: optionsはTypeScript側で事前にバリデーション済み
@@ -388,12 +363,6 @@ def generate_text(prompt, options, stop_token_ids=None):
388
363
  eos_detected = True
389
364
  print('\n', end='\0', flush=True)
390
365
  break
391
- # 追加 stop token チェック(tool call end 等)
392
- if stop_token_ids and hasattr(response, 'token') and int(response.token) in stop_token_ids:
393
- sys.stderr.write(f"--- stop token detected: {int(response.token)}\n")
394
- eos_detected = True
395
- print('\n', end='\0', flush=True)
396
- break
397
366
  if not eos_detected:
398
367
  print(response.text.replace('\0', ''), end='', flush=True)
399
368
 
@@ -53,10 +53,6 @@ def is_eod_token(response, tokenizer):
53
53
  if token_id is not None:
54
54
  end_token_ids.append(token_id)
55
55
 
56
- # フォールバック: 直接属性アクセス
57
- if hasattr(tokenizer, 'eos_token_id'):
58
- end_token_ids.append(tokenizer.eos_token_id)
59
-
60
56
  # 重複を除去してチェック
61
57
  if token in set(end_token_ids):
62
58
  return True