From c63876fcff792928b21b317ca9d3069a4b8e8df2 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 29 Jul 2024 17:28:58 -0300 Subject: [PATCH] fix: move client instantiation in AssistantsGetAssistantName and AssistantsListAssistants to inner function (#3043) The OpenAI client instantiation was removed from the `AssistantsGetAssistantName` and `AssistantsListAssistants` components. This commit fixes the issue by adding back the OpenAI client instantiation in the `process_inputs` method of both components. --- .../langflow/components/astra_assistants/get_assistant.py | 2 +- .../components/astra_assistants/list_assistants.py | 7 ++++--- .../base/langflow/components/astra_assistants/run.py | 3 +-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/backend/base/langflow/components/astra_assistants/get_assistant.py b/src/backend/base/langflow/components/astra_assistants/get_assistant.py index 8c0412fe49eb..cae81515de56 100644 --- a/src/backend/base/langflow/components/astra_assistants/get_assistant.py +++ b/src/backend/base/langflow/components/astra_assistants/get_assistant.py @@ -8,7 +8,6 @@ class AssistantsGetAssistantName(Component): - client = patch(OpenAI()) display_name = "Get Assistant name" description = "Assistant by id" @@ -30,6 +29,7 @@ class AssistantsGetAssistantName(Component): ] def process_inputs(self) -> Message: + patch(OpenAI()) assistant = self.client.beta.assistants.retrieve( assistant_id=self.assistant_id, ) diff --git a/src/backend/base/langflow/components/astra_assistants/list_assistants.py b/src/backend/base/langflow/components/astra_assistants/list_assistants.py index c9e57a9e0297..e70417c5b7c9 100644 --- a/src/backend/base/langflow/components/astra_assistants/list_assistants.py +++ b/src/backend/base/langflow/components/astra_assistants/list_assistants.py @@ -1,12 +1,12 @@ from astra_assistants import patch # type: ignore -from langflow.template.field.base import Output -from langflow.custom import Component from openai import OpenAI + +from langflow.custom import Component from langflow.schema.message import Message +from langflow.template.field.base import Output class AssistantsListAssistants(Component): - client = patch(OpenAI()) display_name = "List Assistants" description = "Returns a list of assistant id's" @@ -15,6 +15,7 @@ class AssistantsListAssistants(Component): ] def process_inputs(self) -> Message: + patch(OpenAI()) assistants = self.client.beta.assistants.list() id_list = [assistant.id for assistant in assistants] message = Message( diff --git a/src/backend/base/langflow/components/astra_assistants/run.py b/src/backend/base/langflow/components/astra_assistants/run.py index 079dc179ca82..dfde8464e36c 100644 --- a/src/backend/base/langflow/components/astra_assistants/run.py +++ b/src/backend/base/langflow/components/astra_assistants/run.py @@ -11,8 +11,6 @@ class AssistantsRun(Component): - client = patch(OpenAI()) - display_name = "Run Assistant" description = "Executes an Assistant Run against a thread" @@ -59,6 +57,7 @@ def update_build_config( outputs = [Output(display_name="Assistant Response", name="assistant_response", method="process_inputs")] def process_inputs(self) -> Message: + patch(OpenAI()) try: text = ""