@@ -425,6 +425,7 @@ def _displayhook_class_default(self):
425425 "Default is `'NavigableAutoSuggestFromHistory`'." ,
426426 allow_none = True ,
427427 ).tag (config = True )
428+ _autosuggestions_provider : Any
428429
429430 llm_constructor_kwargs = Dict (
430431 {},
@@ -434,6 +435,31 @@ def _displayhook_class_default(self):
434435 This is used to – for example – set the `model_id`""" ,
435436 ).tag (config = True )
436437
438+ llm_prefix_from_history = DottedObjectName (
439+ "input_history" ,
440+ help = """\
441+ Fully Qualifed name of a function that takes an IPython history manager and
442+ return a prefix to pass the llm provider in addition to the current buffer
443+ text.
444+
445+ You can use:
446+
447+ - no_prefix
448+ - input_history
449+
450+ As default value. `input_history` (default), will use all the input history
451+ of current IPython session
452+
453+ """ ,
454+ ).tag (config = True )
455+ _llm_prefix_from_history : Any
456+
457+ @observe ("llm_prefix_from_history" )
458+ def _llm_prefix_from_history_changed (self , change ):
459+ name = change .new
460+ self ._llm_prefix_from_history = name
461+ self ._set_autosuggestions ()
462+
437463 llm_provider_class = DottedObjectName (
438464 None ,
439465 allow_none = True ,
@@ -448,24 +474,17 @@ class to use for the `NavigableAutoSuggestFromHistory` to request
448474 `stream_inline_completions`
449475 """ ,
450476 ).tag (config = True )
477+ _llm_provider_class : Any = None
451478
452479 @observe ("llm_provider_class" )
453480 def _llm_provider_class_changed (self , change ):
454481 provider_class = change .new
455- if provider_class is not None :
456- warn (
457- "TerminalInteractiveShell.llm_provider_class is a provisional"
458- " API as of IPython 8.32, and may change without warnings."
459- )
460- if isinstance (self .auto_suggest , NavigableAutoSuggestFromHistory ):
461- self .auto_suggest ._llm_provider = provider_class ()
462- else :
463- self .log .warn (
464- "llm_provider_class only has effects when using"
465- "`NavigableAutoSuggestFromHistory` as auto_suggest."
466- )
482+ self ._llm_provider_class = provider_class
483+ self ._set_autosuggestions ()
467484
468- def _set_autosuggestions (self , provider ):
485+ def _set_autosuggestions (self , provider = None ):
486+ if provider is None :
487+ provider = self .autosuggestions_provider
469488 # disconnect old handler
470489 if self .auto_suggest and isinstance (
471490 self .auto_suggest , NavigableAutoSuggestFromHistory
@@ -477,14 +496,35 @@ def _set_autosuggestions(self, provider):
477496 self .auto_suggest = AutoSuggestFromHistory ()
478497 elif provider == "NavigableAutoSuggestFromHistory" :
479498 # LLM stuff are all Provisional in 8.32
480- if self .llm_provider_class :
481- llm_provider_constructor = import_item (self .llm_provider_class )
499+ if self ._llm_provider_class :
500+ llm_provider_constructor = import_item (self ._llm_provider_class )
482501 llm_provider = llm_provider_constructor (** self .llm_constructor_kwargs )
483502 else :
484503 llm_provider = None
485504 self .auto_suggest = NavigableAutoSuggestFromHistory ()
486505 # Provisinal in 8.32
487506 self .auto_suggest ._llm_provider = llm_provider
507+
508+ name = self .llm_prefix_from_history
509+
510+ if name == "no_prefix" :
511+ print ("set tofun1" , self .llm_prefix_from_history )
512+
513+ def no_prefix (history_manager ):
514+ return ""
515+
516+ fun = no_prefix
517+
518+ elif name == "input_history" :
519+
520+ def input_history (history_manager ):
521+ return "\n " .join ([s [2 ] for s in history_manager .get_range ()]) + "\n "
522+
523+ fun = input_history
524+
525+ else :
526+ fun = import_item (name )
527+ self .auto_suggest ._llm_prefixer = fun
488528 else :
489529 raise ValueError ("No valid provider." )
490530 if self .pt_app :
0 commit comments