Skip to content

Commit

Permalink
fix: move client instantiation in AssistantsGetAssistantName and Assi…
Browse files Browse the repository at this point in the history
…stantsListAssistants to inner function (langflow-ai#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.

(cherry picked from commit c63876f)
  • Loading branch information
ogabrielluiz authored and nicoloboschi committed Jul 30, 2024
1 parent 677f2fc commit 119409a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class AssistantsGetAssistantName(Component):
client = patch(OpenAI())
display_name = "Get Assistant name"
description = "Assistant by id"

Expand All @@ -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,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions src/backend/base/langflow/components/astra_assistants/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@


class AssistantsRun(Component):
client = patch(OpenAI())

display_name = "Run Assistant"
description = "Executes an Assistant Run against a thread"

Expand Down Expand Up @@ -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 = ""

Expand Down

0 comments on commit 119409a

Please sign in to comment.