@@ -758,26 +758,51 @@ Customize `gptel-directives' for task-specific prompts."
758
758
:pad-keys t])
759
759
760
760
; ; ** Prefix for selecting tools
761
+ (defun gptel--tools-annotation-function (cand )
762
+ " Annotation function used in `gptel--completing-read-multiple-tools' "
763
+ (propertize
764
+ (get-text-property 0 'description cand)
765
+ 'face 'shadow ))
766
+
761
767
(defun gptel--completing-read-multiple-tools (prompt candidate-tools )
762
- (cl-loop for selection in
763
- ; ; Without this, when duplicate values are selected in
764
- ; ; `completing-read-multiple' , it will result in a circular-list error
765
- (seq-uniq
766
- (completing-read-multiple
767
- prompt
768
- (lambda (string pred action )
769
- (if (eq action 'metadata )
770
- '(metadata
771
- ; ; (annotation-function . gptel-annotation-function)
772
- (category . gptel-tool))
773
- (complete-with-action
774
- action
775
- candidate-tools
776
- string
777
- pred)))
778
- nil t )
779
- #'string-equal )
780
- nconc (alist-get selection candidate-tools nil nil #'string-equal )))
768
+ " completing-read-multiple with tools."
769
+ (let ((padded-candidate-len
770
+ (+ 3 (apply #'max (map-keys-apply #'length candidate-tools)))))
771
+ (cl-loop for selection in
772
+ ; ; Without this, when duplicate values are selected in
773
+ ; ; `completing-read-multiple' , it will result in a circular-list error
774
+ (seq-uniq
775
+ (completing-read-multiple
776
+ prompt
777
+ (lambda (string pred action )
778
+ (if (eq action 'metadata )
779
+ '(metadata
780
+ (annotation-function . gptel--tools-annotation-function)
781
+ (category . gptel-tool))
782
+ (complete-with-action
783
+ action
784
+ (cl-loop for (tool-name . tools) in candidate-tools
785
+ collect
786
+ (propertize
787
+ (string-pad tool-name padded-candidate-len)
788
+ 'description
789
+ (if (length= tools 1 )
790
+ (gptel--describe-directive
791
+ (gptel-tool-description (car tools))
792
+ (- (window-width ) 40 ))
793
+ (concat
794
+ " category: ("
795
+ (string-join (mapcar
796
+ (lambda (tool )
797
+ (gptel-tool-name tool))
798
+ tools)
799
+ " , " )
800
+ " )" ))))
801
+ string
802
+ pred)))
803
+ nil t )
804
+ #'string-equal )
805
+ nconc (alist-get (string-trim-right selection) candidate-tools nil nil #'string-equal ))))
781
806
782
807
(transient-define-infix gptel--infix-set-tools ()
783
808
" Set tools to use."
@@ -835,10 +860,10 @@ Customize `gptel-directives' for task-specific prompts."
835
860
category-candidates))))))
836
861
837
862
(transient-define-infix gptel--infix-remove-all-tools ()
838
- " Remove tools being used."
839
- :description " Remove tools"
863
+ " Remove all tools being used."
864
+ :description " Remove all tools"
840
865
:class 'gptel-lisp-variable
841
- :prompt " Remove tools: "
866
+ :prompt " Remove tools"
842
867
:display-nil " none"
843
868
:format " %k %d"
844
869
:variable 'gptel-tools
0 commit comments