@@ -61,6 +61,7 @@ def __init__(self):
6161 self .outage = False
6262 self .start_time = None
6363 self .translations = TRANSLATIONS
64+ self .inlet_temp = None
6465
6566 def get_text (self , key : str , ** kwargs ) -> str :
6667 """获取指定语言的文本"""
@@ -86,7 +87,14 @@ def _prepare_body_dict(self, body: dict) -> dict:
8687 body_dict ["metadata" ]["model" ] = body_dict ["metadata" ]["model" ].model_dump ()
8788
8889 return body_dict
89-
90+ def _modify_outlet_body (self , body : dict ) -> dict :
91+ body_modify = dict (body )
92+ last_message = body_modify ["messages" ][- 1 ]
93+
94+ if "info" not in last_message and self .inlet_temp is not None :
95+ body_modify ["messages" ][:- 1 ] = self .inlet_temp ["messages" ]
96+ return body_modify
97+
9098 def inlet (
9199 self , body : dict , user : Optional [dict ] = None , __user__ : dict = {}
92100 ) -> dict :
@@ -98,6 +106,7 @@ def inlet(
98106
99107 user_dict = self ._prepare_user_dict (__user__ )
100108 body_dict = self ._prepare_body_dict (body )
109+ self .inlet_temp = body_dict
101110 response = requests .post (
102111 post_url , headers = headers , json = {"user" : user_dict , "body" : body_dict }
103112 )
@@ -116,7 +125,6 @@ def inlet(
116125 self .outage = response_data .get ("balance" , 0 ) <= 0
117126 if self .outage :
118127 raise Exception (self .get_text ("insufficient_balance" , balance = response_data ['balance' ]))
119-
120128 return body
121129
122130 except requests .exceptions .RequestException as e :
@@ -144,10 +152,11 @@ async def outlet(
144152 headers = {"Authorization" : f"Bearer { self .valves .API_KEY } " }
145153
146154 user_dict = self ._prepare_user_dict (__user__ )
155+ body_modify = self ._modify_outlet_body (body )
147156
148157 request_data = {
149158 "user" : user_dict ,
150- "body" : body ,
159+ "body" : body_modify ,
151160 }
152161
153162 response = requests .post (post_url , headers = headers , json = request_data )
0 commit comments