Skip to content

Commit

Permalink
refactor: update import statements in run.py (langflow-ai#2876)
Browse files Browse the repository at this point in the history
* refactor: update import statements in create_assistant.py

Refactor the import statements in the create_assistant.py file to improve readability and maintainability. Update the import order and add type hints for better code organization. This change ensures consistency with the recent repository commits and follows established conventions.

* refactor: update import statements in create_thread.py

Refactor the import statements in the create_thread.py file to improve readability and maintainability. Update the import order and add type hints for better code organization. This change ensures consistency with the recent repository commits and follows established conventions.

* refactor: improve dotenv component

Refactor the dotenv component to improve code organization and error handling. Update the import statements and add type hints for better readability and maintainability. This change ensures consistency with recent repository commits and follows established conventions.

* refactor: update import statements in get_assistant.py

Refactor the import statements in the get_assistant.py file to improve readability and maintainability. Update the import order and add type hints for better code organization. This change ensures consistency with the recent repository commits and follows established conventions.

* refactor: update import statements in list_assistants.py

Refactor the import statements in the list_assistants.py file to improve readability and maintainability. Update the import order and add type hints for better code organization. This change ensures consistency with the recent repository commits and follows established conventions.

* refactor: update import statements in run.py

Refactor the import statements in the run.py file to improve readability and maintainability. Update the import order and add type hints for better code organization. This change ensures consistency with the recent repository commits and follows established conventions.
  • Loading branch information
ogabrielluiz committed Jul 22, 2024
1 parent d8a90f6 commit 767a57d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from langflow.custom import CustomComponent
from typing import Optional

from astra_assistants import patch # type: ignore
from openai import OpenAI
from astra_assistants import patch

from langflow.custom import CustomComponent


class AssistantsCreateAssistant(CustomComponent):
Expand Down Expand Up @@ -35,8 +38,7 @@ def build_config(self):
},
}

def build(self, name: str, instructions: str, model: str, env_set: str = None) -> str:
print(f"env_set is {env_set}")
def build(self, name: str, instructions: str, model: str, env_set: Optional[str] = None) -> str:
if env_set is None:
raise Exception("Environment variables not set")
client = patch(OpenAI())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from langflow.custom import CustomComponent
from typing import Optional

from astra_assistants import patch # type: ignore
from openai import OpenAI
from astra_assistants import patch

from langflow.custom import CustomComponent


class AssistantsCreateThread(CustomComponent):
Expand All @@ -16,7 +19,7 @@ def build_config(self):
},
}

def build(self, env_set: str = None) -> str:
def build(self, env_set: Optional[str] = None) -> str:
client = patch(OpenAI())

thread = client.beta.threads.create()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import io

from dotenv import load_dotenv

from langflow.custom import CustomComponent


Expand All @@ -23,6 +25,6 @@ def build(self, dotenv_file_content: str) -> str:
try:
fake_file = io.StringIO(dotenv_file_content)
result = load_dotenv(stream=fake_file, override=True)
return result
return "Loaded .env" if result else "No variables found in .env"
except Exception as e:
raise e
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from langflow.custom import CustomComponent
from typing import Optional
from astra_assistants import patch # type: ignore
from openai import OpenAI
from astra_assistants import patch

from langflow.custom import CustomComponent


class AssistantsGetAssistantName(CustomComponent):
Expand All @@ -20,7 +22,7 @@ def build_config(self):
},
}

def build(self, assistant_id: str, env_set: str = None) -> str:
def build(self, assistant_id: str, env_set: Optional[str] = None) -> str:
client = patch(OpenAI())
assistant = client.beta.assistants.retrieve(
assistant_id=assistant_id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import List
from langflow.custom import CustomComponent

from astra_assistants import patch # type: ignore
from openai import OpenAI
from astra_assistants import patch

from langflow.custom import CustomComponent


class AssistantsListAssistants(CustomComponent):
Expand Down
10 changes: 7 additions & 3 deletions src/backend/base/langflow/components/astra_assistants/run.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from langflow.custom import CustomComponent
from typing import Optional
from astra_assistants import patch # type: ignore
from openai import OpenAI
from openai.lib.streaming import AssistantEventHandler
from astra_assistants import patch

from langflow.custom import CustomComponent


class AssistantsRun(CustomComponent):
Expand Down Expand Up @@ -35,7 +37,9 @@ def build_config(self):
},
}

def build(self, assistant_id: str, user_message: str, thread_id: str = None, env_set: str = None) -> str:
def build(
self, assistant_id: str, user_message: str, thread_id: Optional[str] = None, env_set: Optional[str] = None
) -> str:
text = ""
client = patch(OpenAI())

Expand Down

0 comments on commit 767a57d

Please sign in to comment.