@@ -522,7 +522,7 @@ def generate(
522522 if tokens_or_none is not None :
523523 tokens .extend (tokens_or_none )
524524
525- def create_embedding (self , input : str ) -> Embedding :
525+ def create_embedding (self , input : str , model : Optional [ str ] = None ) -> Embedding :
526526 """Embed a string.
527527
528528 Args:
@@ -532,6 +532,7 @@ def create_embedding(self, input: str) -> Embedding:
532532 An embedding object.
533533 """
534534 assert self .ctx is not None
535+ _model : str = model if model is not None else self .model_path
535536
536537 if self .params .embedding == False :
537538 raise RuntimeError (
@@ -561,7 +562,7 @@ def create_embedding(self, input: str) -> Embedding:
561562 "index" : 0 ,
562563 }
563564 ],
564- "model" : self . model_path ,
565+ "model" : _model ,
565566 "usage" : {
566567 "prompt_tokens" : n_tokens ,
567568 "total_tokens" : n_tokens ,
@@ -598,6 +599,7 @@ def _create_completion(
598599 mirostat_mode : int = 0 ,
599600 mirostat_tau : float = 5.0 ,
600601 mirostat_eta : float = 0.1 ,
602+ model : Optional [str ] = None ,
601603 ) -> Union [Iterator [Completion ], Iterator [CompletionChunk ]]:
602604 assert self .ctx is not None
603605 completion_id : str = f"cmpl-{ str (uuid .uuid4 ())} "
@@ -610,6 +612,7 @@ def _create_completion(
610612 text : bytes = b""
611613 returned_characters : int = 0
612614 stop = stop if stop is not None else []
615+ _model : str = model if model is not None else self .model_path
613616
614617 if self .verbose :
615618 llama_cpp .llama_reset_timings (self .ctx )
@@ -708,7 +711,7 @@ def _create_completion(
708711 "id" : completion_id ,
709712 "object" : "text_completion" ,
710713 "created" : created ,
711- "model" : self . model_path ,
714+ "model" : _model ,
712715 "choices" : [
713716 {
714717 "text" : text [start :].decode ("utf-8" , errors = "ignore" ),
@@ -737,7 +740,7 @@ def _create_completion(
737740 "id" : completion_id ,
738741 "object" : "text_completion" ,
739742 "created" : created ,
740- "model" : self . model_path ,
743+ "model" : _model ,
741744 "choices" : [
742745 {
743746 "text" : text [returned_characters :].decode (
@@ -807,7 +810,7 @@ def _create_completion(
807810 "id" : completion_id ,
808811 "object" : "text_completion" ,
809812 "created" : created ,
810- "model" : self . model_path ,
813+ "model" : _model ,
811814 "choices" : [
812815 {
813816 "text" : text_str ,
@@ -842,6 +845,7 @@ def create_completion(
842845 mirostat_mode : int = 0 ,
843846 mirostat_tau : float = 5.0 ,
844847 mirostat_eta : float = 0.1 ,
848+ model : Optional [str ] = None ,
845849 ) -> Union [Completion , Iterator [CompletionChunk ]]:
846850 """Generate text from a prompt.
847851
@@ -883,6 +887,7 @@ def create_completion(
883887 mirostat_mode = mirostat_mode ,
884888 mirostat_tau = mirostat_tau ,
885889 mirostat_eta = mirostat_eta ,
890+ model = model ,
886891 )
887892 if stream :
888893 chunks : Iterator [CompletionChunk ] = completion_or_chunks
@@ -909,6 +914,7 @@ def __call__(
909914 mirostat_mode : int = 0 ,
910915 mirostat_tau : float = 5.0 ,
911916 mirostat_eta : float = 0.1 ,
917+ model : Optional [str ] = None ,
912918 ) -> Union [Completion , Iterator [CompletionChunk ]]:
913919 """Generate text from a prompt.
914920
@@ -950,6 +956,7 @@ def __call__(
950956 mirostat_mode = mirostat_mode ,
951957 mirostat_tau = mirostat_tau ,
952958 mirostat_eta = mirostat_eta ,
959+ model = model ,
953960 )
954961
955962 def _convert_text_completion_to_chat (
@@ -1026,6 +1033,7 @@ def create_chat_completion(
10261033 mirostat_mode : int = 0 ,
10271034 mirostat_tau : float = 5.0 ,
10281035 mirostat_eta : float = 0.1 ,
1036+ model : Optional [str ] = None ,
10291037 ) -> Union [ChatCompletion , Iterator [ChatCompletionChunk ]]:
10301038 """Generate a chat completion from a list of messages.
10311039
@@ -1064,6 +1072,7 @@ def create_chat_completion(
10641072 mirostat_mode = mirostat_mode ,
10651073 mirostat_tau = mirostat_tau ,
10661074 mirostat_eta = mirostat_eta ,
1075+ model = model ,
10671076 )
10681077 if stream :
10691078 chunks : Iterator [CompletionChunk ] = completion_or_chunks # type: ignore
0 commit comments