mirror of
https://github.com/langgenius/dify-official-plugins.git
synced 2026-07-22 01:55:27 -04:00
fix httpx.client unexpected auto closed by the genai.client (#2007)
This commit is contained in:
@@ -34,4 +34,4 @@ resource:
|
||||
tool:
|
||||
enabled: true
|
||||
type: plugin
|
||||
version: 0.5.10
|
||||
version: 0.5.11
|
||||
|
||||
@@ -605,6 +605,7 @@ class GoogleLargeLanguageModel(LargeLanguageModel):
|
||||
credentials: dict,
|
||||
response: Iterator[types.GenerateContentResponse],
|
||||
prompt_messages: list[PromptMessage],
|
||||
genai_client: genai.Client,
|
||||
) -> Generator[LLMResultChunk]:
|
||||
"""
|
||||
Handle llm stream response
|
||||
@@ -627,8 +628,13 @@ class GoogleLargeLanguageModel(LargeLanguageModel):
|
||||
:param credentials: credentials
|
||||
:param response: response
|
||||
:param prompt_messages: prompt messages
|
||||
:param genai_client: genai client to keep alive during streaming
|
||||
:return: llm response chunk generator result
|
||||
"""
|
||||
# Keep a reference to the client to prevent it from being garbage collected
|
||||
# while the generator is still active
|
||||
_client_ref = genai_client
|
||||
|
||||
index = -1
|
||||
self.is_thinking = False
|
||||
|
||||
@@ -893,7 +899,7 @@ class GoogleLargeLanguageModel(LargeLanguageModel):
|
||||
model=model, contents=contents, config=config
|
||||
)
|
||||
return self._handle_generate_stream_response(
|
||||
model, credentials, response, prompt_messages
|
||||
model, credentials, response, prompt_messages, genai_client
|
||||
)
|
||||
|
||||
response = genai_client.models.generate_content(
|
||||
|
||||
Reference in New Issue
Block a user