返回提交历史
Modified
g4f/Provider/PollinationsAI.py
+1
-1
Modified
g4f/Provider/template/OpenaiTemplate.py
+2
-2
Modified
g4f/client/stubs.py
+1
-0
XFEstudio/gpt4free
Update cache handling in PollinationsAI and OpenaiTemplate: modify cache logic and include cache header in Usage model
d94b9bf8
代码差异
3 个文件
+4
-3
@@ -226,7 +226,7 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
226
226
**kwargs
227
227
) -> AsyncResult:
228
228
if cache is None:
229
cache = kwargs.get("action") == "next"
229
cache = kwargs.get("action") != "variant"
230
230
if extra_body is None:
231
231
extra_body = {}
232
232
if not model:
@@ -178,7 +178,7 @@ async def read_response(response: StreamResponse, stream: bool, prompt: str, pro
178
178
if model:
179
179
yield ProviderInfo(**provider_info, model=model)
180
180
if "usage" in data:
181
yield Usage(**data["usage"])
181
yield Usage(**data["usage"], cache=response.headers.get("x-cache", "MISS"))
182
182
if "conversation" in data:
183
183
yield JsonConversation.from_dict(data["conversation"])
184
184
if "choices" in data:
@@ -234,7 +234,7 @@ async def read_response(response: StreamResponse, stream: bool, prompt: str, pro
234
234
reasoning = True
235
235
yield Reasoning(reasoning_content)
236
236
if "usage" in data and data["usage"]:
237
yield Usage(**data["usage"])
237
yield Usage(**data["usage"], cache=response.headers.get("x-cache", "MISS"))
238
238
if "conversation" in data and data["conversation"]:
239
239
yield JsonConversation.from_dict(data["conversation"])
240
240
if choice and choice.get("finish_reason") is not None:
@@ -48,6 +48,7 @@ class UsageModel(BaseModel):
48
48
total_tokens: int
49
49
prompt_tokens_details: PromptTokenDetails
50
50
completion_tokens_details: CompletionTokenDetails
51
cache: Optional[str] = None
51
52
52
53
@classmethod
53
54
def model_construct(cls, prompt_tokens=0, completion_tokens=0, total_tokens=0, prompt_tokens_details=None, completion_tokens_details=None, **kwargs):