langroid 0.50.9__py3-none-any.whl → 0.50.11__py3-none-any.whl
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.
- langroid/language_models/base.py +27 -6
- langroid/language_models/openai_gpt.py +46 -36
- {langroid-0.50.9.dist-info → langroid-0.50.11.dist-info}/METADATA +1 -1
- {langroid-0.50.9.dist-info → langroid-0.50.11.dist-info}/RECORD +6 -6
- {langroid-0.50.9.dist-info → langroid-0.50.11.dist-info}/WHEEL +0 -0
- {langroid-0.50.9.dist-info → langroid-0.50.11.dist-info}/licenses/LICENSE +0 -0
langroid/language_models/base.py
CHANGED
@@ -733,16 +733,37 @@ class LanguageModel(ABC):
|
|
733
733
|
history = collate_chat_history(chat_history)
|
734
734
|
|
735
735
|
prompt = f"""
|
736
|
-
|
737
|
-
|
738
|
-
|
736
|
+
You are an expert at understanding a CHAT HISTORY between an AI Assistant
|
737
|
+
and a User, and you are highly skilled in rephrasing the User's FOLLOW-UP
|
738
|
+
QUESTION/REQUEST as a STANDALONE QUESTION/REQUEST that can be understood
|
739
|
+
WITHOUT the context of the chat history.
|
739
740
|
|
740
|
-
|
741
|
+
Below is the CHAT HISTORY. When the User asks you to rephrase a
|
742
|
+
FOLLOW-UP QUESTION/REQUEST, your ONLY task is to simply return the
|
743
|
+
question REPHRASED as a STANDALONE QUESTION/REQUEST, without any additional
|
744
|
+
text or context.
|
741
745
|
|
742
|
-
|
746
|
+
<CHAT_HISTORY>
|
747
|
+
{history}
|
748
|
+
</CHAT_HISTORY>
|
743
749
|
""".strip()
|
750
|
+
|
751
|
+
follow_up_question = f"""
|
752
|
+
Please rephrase this as a stand-alone question or request:
|
753
|
+
<FOLLOW-UP-QUESTION-OR-REQUEST>
|
754
|
+
{question}
|
755
|
+
</FOLLOW-UP-QUESTION-OR-REQUEST>
|
756
|
+
""".strip()
|
757
|
+
|
744
758
|
show_if_debug(prompt, "FOLLOWUP->STANDALONE-PROMPT= ")
|
745
|
-
standalone = self.
|
759
|
+
standalone = self.chat(
|
760
|
+
messages=[
|
761
|
+
LLMMessage(role=Role.SYSTEM, content=prompt),
|
762
|
+
LLMMessage(role=Role.USER, content=follow_up_question),
|
763
|
+
],
|
764
|
+
max_tokens=1024,
|
765
|
+
).message.strip()
|
766
|
+
|
746
767
|
show_if_debug(prompt, "FOLLOWUP->STANDALONE-RESPONSE= ")
|
747
768
|
return standalone
|
748
769
|
|
@@ -157,7 +157,7 @@ class AccessWarning(Warning):
|
|
157
157
|
def gpt_3_5_warning() -> None:
|
158
158
|
warnings.warn(
|
159
159
|
f"""
|
160
|
-
{OpenAIChatModel.GPT4o} is not available,
|
160
|
+
{OpenAIChatModel.GPT4o} is not available,
|
161
161
|
falling back to {OpenAIChatModel.GPT3_5_TURBO}.
|
162
162
|
Examples may not work properly and unexpected behavior may occur.
|
163
163
|
Adjustments to prompts may be necessary.
|
@@ -435,8 +435,8 @@ class OpenAIGPT(LanguageModel):
|
|
435
435
|
self.config.formatter = formatter
|
436
436
|
logging.warning(
|
437
437
|
f"""
|
438
|
-
Using completions (not chat) endpoint with HuggingFace
|
439
|
-
chat_template for {formatter} for
|
438
|
+
Using completions (not chat) endpoint with HuggingFace
|
439
|
+
chat_template for {formatter} for
|
440
440
|
model {self.config.chat_model}
|
441
441
|
"""
|
442
442
|
)
|
@@ -758,12 +758,11 @@ class OpenAIGPT(LanguageModel):
|
|
758
758
|
return tmp
|
759
759
|
|
760
760
|
def get_stream(self) -> bool:
|
761
|
-
"""Get streaming status.
|
761
|
+
"""Get streaming status."""
|
762
762
|
return (
|
763
763
|
self.config.stream
|
764
764
|
and settings.stream
|
765
765
|
and self.info().allows_streaming
|
766
|
-
and not settings.quiet
|
767
766
|
)
|
768
767
|
|
769
768
|
@no_type_check
|
@@ -813,6 +812,7 @@ class OpenAIGPT(LanguageModel):
|
|
813
812
|
event_args = ""
|
814
813
|
event_fn_name = ""
|
815
814
|
event_tool_deltas: Optional[List[Dict[str, Any]]] = None
|
815
|
+
silent = self.config.async_stream_quiet or settings.quiet
|
816
816
|
# The first two events in the stream of Azure OpenAI is useless.
|
817
817
|
# In the 1st: choices list is empty, in the 2nd: the dict delta has null content
|
818
818
|
if chat:
|
@@ -852,25 +852,29 @@ class OpenAIGPT(LanguageModel):
|
|
852
852
|
|
853
853
|
if event_text:
|
854
854
|
completion += event_text
|
855
|
-
|
856
|
-
|
855
|
+
if not silent:
|
856
|
+
sys.stdout.write(Colors().GREEN + event_text)
|
857
|
+
sys.stdout.flush()
|
857
858
|
self.config.streamer(event_text, StreamEventType.TEXT)
|
858
859
|
if event_reasoning:
|
859
860
|
reasoning += event_reasoning
|
860
|
-
|
861
|
-
|
861
|
+
if not silent:
|
862
|
+
sys.stdout.write(Colors().GREEN_DIM + event_reasoning)
|
863
|
+
sys.stdout.flush()
|
862
864
|
self.config.streamer(event_reasoning, StreamEventType.TEXT)
|
863
865
|
if event_fn_name:
|
864
866
|
function_name = event_fn_name
|
865
867
|
has_function = True
|
866
|
-
|
867
|
-
|
868
|
+
if not silent:
|
869
|
+
sys.stdout.write(Colors().GREEN + "FUNC: " + event_fn_name + ": ")
|
870
|
+
sys.stdout.flush()
|
868
871
|
self.config.streamer(event_fn_name, StreamEventType.FUNC_NAME)
|
869
872
|
|
870
873
|
if event_args:
|
871
874
|
function_args += event_args
|
872
|
-
|
873
|
-
|
875
|
+
if not silent:
|
876
|
+
sys.stdout.write(Colors().GREEN + event_args)
|
877
|
+
sys.stdout.flush()
|
874
878
|
self.config.streamer(event_args, StreamEventType.FUNC_ARGS)
|
875
879
|
|
876
880
|
if event_tool_deltas is not None:
|
@@ -878,15 +882,17 @@ class OpenAIGPT(LanguageModel):
|
|
878
882
|
for td in event_tool_deltas:
|
879
883
|
if td["function"]["name"] is not None:
|
880
884
|
tool_fn_name = td["function"]["name"]
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
+
if not silent:
|
886
|
+
sys.stdout.write(
|
887
|
+
Colors().GREEN + "OAI-TOOL: " + tool_fn_name + ": "
|
888
|
+
)
|
889
|
+
sys.stdout.flush()
|
885
890
|
self.config.streamer(tool_fn_name, StreamEventType.TOOL_NAME)
|
886
891
|
if td["function"]["arguments"] != "":
|
887
892
|
tool_fn_args = td["function"]["arguments"]
|
888
|
-
|
889
|
-
|
893
|
+
if not silent:
|
894
|
+
sys.stdout.write(Colors().GREEN + tool_fn_args)
|
895
|
+
sys.stdout.flush()
|
890
896
|
self.config.streamer(tool_fn_args, StreamEventType.TOOL_ARGS)
|
891
897
|
|
892
898
|
# show this delta in the stream
|
@@ -953,7 +959,7 @@ class OpenAIGPT(LanguageModel):
|
|
953
959
|
event_args = ""
|
954
960
|
event_fn_name = ""
|
955
961
|
event_tool_deltas: Optional[List[Dict[str, Any]]] = None
|
956
|
-
silent = self.config.async_stream_quiet
|
962
|
+
silent = self.config.async_stream_quiet or settings.quiet
|
957
963
|
# The first two events in the stream of Azure OpenAI is useless.
|
958
964
|
# In the 1st: choices list is empty, in the 2nd: the dict delta has null content
|
959
965
|
if chat:
|
@@ -980,46 +986,48 @@ class OpenAIGPT(LanguageModel):
|
|
980
986
|
if not silent:
|
981
987
|
sys.stdout.write(Colors().GREEN + event_text)
|
982
988
|
sys.stdout.flush()
|
983
|
-
|
989
|
+
await self.config.streamer_async(event_text, StreamEventType.TEXT)
|
984
990
|
if event_reasoning:
|
985
991
|
reasoning += event_reasoning
|
986
992
|
if not silent:
|
987
993
|
sys.stdout.write(Colors().GREEN + event_reasoning)
|
988
994
|
sys.stdout.flush()
|
989
|
-
|
995
|
+
await self.config.streamer_async(event_reasoning, StreamEventType.TEXT)
|
990
996
|
if event_fn_name:
|
991
997
|
function_name = event_fn_name
|
992
998
|
has_function = True
|
993
999
|
if not silent:
|
994
1000
|
sys.stdout.write(Colors().GREEN + "FUNC: " + event_fn_name + ": ")
|
995
1001
|
sys.stdout.flush()
|
996
|
-
|
997
|
-
|
998
|
-
|
1002
|
+
await self.config.streamer_async(
|
1003
|
+
event_fn_name, StreamEventType.FUNC_NAME
|
1004
|
+
)
|
999
1005
|
|
1000
1006
|
if event_args:
|
1001
1007
|
function_args += event_args
|
1002
1008
|
if not silent:
|
1003
1009
|
sys.stdout.write(Colors().GREEN + event_args)
|
1004
1010
|
sys.stdout.flush()
|
1005
|
-
|
1011
|
+
await self.config.streamer_async(event_args, StreamEventType.FUNC_ARGS)
|
1006
1012
|
|
1007
|
-
if event_tool_deltas is not None
|
1013
|
+
if event_tool_deltas is not None:
|
1008
1014
|
# print out streaming tool calls, if not async
|
1009
1015
|
for td in event_tool_deltas:
|
1010
1016
|
if td["function"]["name"] is not None:
|
1011
1017
|
tool_fn_name = td["function"]["name"]
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1018
|
+
if not silent:
|
1019
|
+
sys.stdout.write(
|
1020
|
+
Colors().GREEN + "OAI-TOOL: " + tool_fn_name + ": "
|
1021
|
+
)
|
1022
|
+
sys.stdout.flush()
|
1016
1023
|
await self.config.streamer_async(
|
1017
1024
|
tool_fn_name, StreamEventType.TOOL_NAME
|
1018
1025
|
)
|
1019
1026
|
if td["function"]["arguments"] != "":
|
1020
1027
|
tool_fn_args = td["function"]["arguments"]
|
1021
|
-
|
1022
|
-
|
1028
|
+
if not silent:
|
1029
|
+
sys.stdout.write(Colors().GREEN + tool_fn_args)
|
1030
|
+
sys.stdout.flush()
|
1023
1031
|
await self.config.streamer_async(
|
1024
1032
|
tool_fn_args, StreamEventType.TOOL_ARGS
|
1025
1033
|
)
|
@@ -1103,7 +1111,8 @@ class OpenAIGPT(LanguageModel):
|
|
1103
1111
|
except Exception as e:
|
1104
1112
|
logging.warning("Error while processing stream response: %s", str(e))
|
1105
1113
|
|
1106
|
-
|
1114
|
+
if not settings.quiet:
|
1115
|
+
print("")
|
1107
1116
|
# TODO- get usage info in stream mode (?)
|
1108
1117
|
|
1109
1118
|
return self._create_stream_response(
|
@@ -1178,7 +1187,8 @@ class OpenAIGPT(LanguageModel):
|
|
1178
1187
|
except Exception as e:
|
1179
1188
|
logging.warning("Error while processing stream response: %s", str(e))
|
1180
1189
|
|
1181
|
-
|
1190
|
+
if not settings.quiet:
|
1191
|
+
print("")
|
1182
1192
|
# TODO- get usage info in stream mode (?)
|
1183
1193
|
|
1184
1194
|
return self._create_stream_response(
|
@@ -1300,7 +1310,7 @@ class OpenAIGPT(LanguageModel):
|
|
1300
1310
|
if not isinstance(dict_or_list, dict):
|
1301
1311
|
raise ValueError(
|
1302
1312
|
f"""
|
1303
|
-
Invalid function args: {stripped_fn_args}
|
1313
|
+
Invalid function args: {stripped_fn_args}
|
1304
1314
|
parsed as {dict_or_list},
|
1305
1315
|
which is not a valid dict.
|
1306
1316
|
"""
|
@@ -69,11 +69,11 @@ langroid/embedding_models/protoc/embeddings_pb2.pyi,sha256=UkNy7BrNsmQm0vLb3NtGX
|
|
69
69
|
langroid/embedding_models/protoc/embeddings_pb2_grpc.py,sha256=9dYQqkW3JPyBpSEjeGXTNpSqAkC-6FPtBHyteVob2Y8,2452
|
70
70
|
langroid/language_models/__init__.py,sha256=3aD2qC1lz8v12HX4B-dilv27gNxYdGdeu1QvDlkqqHs,1095
|
71
71
|
langroid/language_models/azure_openai.py,sha256=SW0Fp_y6HpERr9l6TtF6CYsKgKwjUf_hSL_2mhTV4wI,5034
|
72
|
-
langroid/language_models/base.py,sha256=
|
72
|
+
langroid/language_models/base.py,sha256=sCDC02hqIgjY73KnCvc-YGxZJm_LAs4Z1VVQpIFWLyQ,27754
|
73
73
|
langroid/language_models/config.py,sha256=9Q8wk5a7RQr8LGMT_0WkpjY8S4ywK06SalVRjXlfCiI,378
|
74
74
|
langroid/language_models/mock_lm.py,sha256=5BgHKDVRWFbUwDT_PFgTZXz9-k8wJSA2e3PZmyDgQ1k,4022
|
75
75
|
langroid/language_models/model_info.py,sha256=tfBBxL0iUf2mVN6CjcvqflzFUVg2oZqOJZexZ8jHTYA,12216
|
76
|
-
langroid/language_models/openai_gpt.py,sha256=
|
76
|
+
langroid/language_models/openai_gpt.py,sha256=o-iOvdpSnkXtvrJyhlItJwYIcZoF8vz3blUBjzOcGS0,84843
|
77
77
|
langroid/language_models/utils.py,sha256=hC5p61P_Qlrowkm5wMap1A1b5ZUCwK_XhPIzAQk1T1s,5483
|
78
78
|
langroid/language_models/prompt_formatter/__init__.py,sha256=2-5cdE24XoFDhifOLl8yiscohil1ogbP1ECkYdBlBsk,372
|
79
79
|
langroid/language_models/prompt_formatter/base.py,sha256=eDS1sgRNZVnoajwV_ZIha6cba5Dt8xjgzdRbPITwx3Q,1221
|
@@ -129,7 +129,7 @@ langroid/vector_store/pineconedb.py,sha256=otxXZNaBKb9f_H75HTaU3lMHiaR2NUp5MqwLZ
|
|
129
129
|
langroid/vector_store/postgres.py,sha256=wHPtIi2qM4fhO4pMQr95pz1ZCe7dTb2hxl4VYspGZoA,16104
|
130
130
|
langroid/vector_store/qdrantdb.py,sha256=O6dSBoDZ0jzfeVBd7LLvsXu083xs2fxXtPa9gGX3JX4,18443
|
131
131
|
langroid/vector_store/weaviatedb.py,sha256=Yn8pg139gOy3zkaPfoTbMXEEBCiLiYa1MU5d_3UA1K4,11847
|
132
|
-
langroid-0.50.
|
133
|
-
langroid-0.50.
|
134
|
-
langroid-0.50.
|
135
|
-
langroid-0.50.
|
132
|
+
langroid-0.50.11.dist-info/METADATA,sha256=oAh04rgGQXXGEe7tu3yAX7t1787xRBG85NqEh996F_0,63642
|
133
|
+
langroid-0.50.11.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
134
|
+
langroid-0.50.11.dist-info/licenses/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
|
135
|
+
langroid-0.50.11.dist-info/RECORD,,
|
File without changes
|
File without changes
|