mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-12-06 02:30:41 -08:00
refactor: remove cache parameter and update conversation handling
- Removed the `cache` parameter from the `PollinationsAI` class in `PollinationsAI.py`. - Added a `parent_message_id` parameter to the `chat_completion` method call in the `DeepSeekAPI` class in `DeepSeekAPI.py`. - Updated the handling of `conversation` in `DeepSeekAPI.py` to yield the `conversation` object at the end of the method. - Set `conversation.parent_id` to `chunk['message_id']` when present in the response in `DeepSeekAPI.py`. - Adjusted the method signatures in `aiohttp.py` to remove unnecessary type hints for `ClientSession` and `None`.
This commit is contained in:
parent
963c3a585e
commit
67231e8c40
3 changed files with 8 additions and 6 deletions
|
|
@ -490,7 +490,6 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
|
||||||
response_format=response_format,
|
response_format=response_format,
|
||||||
stream=stream,
|
stream=stream,
|
||||||
seed=seed,
|
seed=seed,
|
||||||
cache=cache,
|
|
||||||
**extra_body
|
**extra_body
|
||||||
)
|
)
|
||||||
headers = {"referer": referrer}
|
headers = {"referer": referrer}
|
||||||
|
|
|
||||||
|
|
@ -62,14 +62,14 @@ class DeepSeekAPI(AsyncAuthedProvider, ProviderModelMixin):
|
||||||
if conversation is None:
|
if conversation is None:
|
||||||
chat_id = api.create_chat_session()
|
chat_id = api.create_chat_session()
|
||||||
conversation = JsonConversation(chat_id=chat_id)
|
conversation = JsonConversation(chat_id=chat_id)
|
||||||
yield conversation
|
|
||||||
|
|
||||||
is_thinking = 0
|
is_thinking = 0
|
||||||
for chunk in api.chat_completion(
|
for chunk in api.chat_completion(
|
||||||
conversation.chat_id,
|
conversation.chat_id,
|
||||||
get_last_user_message(messages),
|
get_last_user_message(messages),
|
||||||
thinking_enabled=bool(model) and "deepseek-r1" in model,
|
thinking_enabled=bool(model) and "deepseek-r1" in model,
|
||||||
search_enabled=web_search
|
search_enabled=web_search,
|
||||||
|
parent_message_id=getattr(conversation, "parent_id", None)
|
||||||
):
|
):
|
||||||
if chunk['type'] == 'thinking':
|
if chunk['type'] == 'thinking':
|
||||||
if not is_thinking:
|
if not is_thinking:
|
||||||
|
|
@ -82,5 +82,8 @@ class DeepSeekAPI(AsyncAuthedProvider, ProviderModelMixin):
|
||||||
is_thinking = 0
|
is_thinking = 0
|
||||||
if chunk['content']:
|
if chunk['content']:
|
||||||
yield chunk['content']
|
yield chunk['content']
|
||||||
|
elif 'message_id' in chunk:
|
||||||
|
conversation.parent_id = chunk['message_id']
|
||||||
if chunk['finish_reason']:
|
if chunk['finish_reason']:
|
||||||
yield FinishReason(chunk['finish_reason'])
|
yield FinishReason(chunk['finish_reason'])
|
||||||
|
yield conversation
|
||||||
|
|
@ -62,10 +62,10 @@ class StreamSession():
|
||||||
headers=headers
|
headers=headers
|
||||||
)
|
)
|
||||||
|
|
||||||
async def __aenter__(self) -> "ClientSession":
|
async def __aenter__(self) -> ClientSession:
|
||||||
return self.inner
|
return self.inner
|
||||||
|
|
||||||
async def __aexit__(self, **kwargs) -> None:
|
async def __aexit__(self, *args, **kwargs) -> None:
|
||||||
await self.inner.close()
|
await self.inner.close()
|
||||||
|
|
||||||
def get_connector(connector: BaseConnector = None, proxy: str = None, rdns: bool = False) -> Optional[BaseConnector]:
|
def get_connector(connector: BaseConnector = None, proxy: str = None, rdns: bool = False) -> Optional[BaseConnector]:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue