From 48345dd8dd883778fd149fd88d881b7ec1552012 Mon Sep 17 00:00:00 2001 From: gustavoschaedler Date: Wed, 5 Jul 2023 03:37:18 +0100 Subject: [PATCH] Refactor MyPythonClass `build` method to accept `openai_api_key` parameter. - The `build` method of `MyPythonClass` is modified to accept an `openai_api_key` parameter instead of using a hardcoded value. - This change allows for dynamic usage of different API keys when constructing an instance of `ConversationChain`. - The `my_conversation` method now takes `openai_api_key` as an argument and uses it to initialize the `llm` instance of `OpenAI`. - The `build` method simply delegates the `openai_api_key` argument to the `my_conversation` method and returns the resulting `ConversationChain` instance. --- src/backend/langflow/utils/constants.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/backend/langflow/utils/constants.py b/src/backend/langflow/utils/constants.py index 930cecc73..579679d29 100644 --- a/src/backend/langflow/utils/constants.py +++ b/src/backend/langflow/utils/constants.py @@ -56,19 +56,17 @@ from langchain.memory import ConversationBufferMemory class MyPythonClass: - def my_conversation(self): + def my_conversation(self, openai_api_key): llm = OpenAI( - openai_api_key='', + openai_api_key=openai_api_key, temperature=0 ) return ConversationChain( llm=llm, verbose=True, memory=ConversationBufferMemory() ) - def build(self, my_custom_input: str) -> ConversationChain: - conversation = self.my_conversation() - - return conversation + def build(self, openai_api_key: str) -> ConversationChain: + return self.my_conversation(openai_api_key) """ DIRECT_TYPES = ["str", "bool", "code", "int", "float", "Any", "prompt"]