@@ -61,6 +61,7 @@ def __init__(self):
61
61
self .outage = False
62
62
self .start_time = None
63
63
self .translations = TRANSLATIONS
64
+ self .inlet_temp = None
64
65
65
66
def get_text (self , key : str , ** kwargs ) -> str :
66
67
"""获取指定语言的文本"""
@@ -86,7 +87,14 @@ def _prepare_body_dict(self, body: dict) -> dict:
86
87
body_dict ["metadata" ]["model" ] = body_dict ["metadata" ]["model" ].model_dump ()
87
88
88
89
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
+
90
98
def inlet (
91
99
self , body : dict , user : Optional [dict ] = None , __user__ : dict = {}
92
100
) -> dict :
@@ -98,6 +106,7 @@ def inlet(
98
106
99
107
user_dict = self ._prepare_user_dict (__user__ )
100
108
body_dict = self ._prepare_body_dict (body )
109
+ self .inlet_temp = body_dict
101
110
response = requests .post (
102
111
post_url , headers = headers , json = {"user" : user_dict , "body" : body_dict }
103
112
)
@@ -116,7 +125,6 @@ def inlet(
116
125
self .outage = response_data .get ("balance" , 0 ) <= 0
117
126
if self .outage :
118
127
raise Exception (self .get_text ("insufficient_balance" , balance = response_data ['balance' ]))
119
-
120
128
return body
121
129
122
130
except requests .exceptions .RequestException as e :
@@ -144,10 +152,11 @@ async def outlet(
144
152
headers = {"Authorization" : f"Bearer { self .valves .API_KEY } " }
145
153
146
154
user_dict = self ._prepare_user_dict (__user__ )
155
+ body_modify = self ._modify_outlet_body (body )
147
156
148
157
request_data = {
149
158
"user" : user_dict ,
150
- "body" : body ,
159
+ "body" : body_modify ,
151
160
}
152
161
153
162
response = requests .post (post_url , headers = headers , json = request_data )
0 commit comments