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.
This commit is contained in:
parent
839e9737cc
commit
48345dd8dd
1 changed files with 4 additions and 6 deletions
|
|
@ -56,19 +56,17 @@ from langchain.memory import ConversationBufferMemory
|
||||||
|
|
||||||
|
|
||||||
class MyPythonClass:
|
class MyPythonClass:
|
||||||
def my_conversation(self):
|
def my_conversation(self, openai_api_key):
|
||||||
llm = OpenAI(
|
llm = OpenAI(
|
||||||
openai_api_key='',
|
openai_api_key=openai_api_key,
|
||||||
temperature=0
|
temperature=0
|
||||||
)
|
)
|
||||||
return ConversationChain(
|
return ConversationChain(
|
||||||
llm=llm, verbose=True, memory=ConversationBufferMemory()
|
llm=llm, verbose=True, memory=ConversationBufferMemory()
|
||||||
)
|
)
|
||||||
|
|
||||||
def build(self, my_custom_input: str) -> ConversationChain:
|
def build(self, openai_api_key: str) -> ConversationChain:
|
||||||
conversation = self.my_conversation()
|
return self.my_conversation(openai_api_key)
|
||||||
|
|
||||||
return conversation
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
DIRECT_TYPES = ["str", "bool", "code", "int", "float", "Any", "prompt"]
|
DIRECT_TYPES = ["str", "bool", "code", "int", "float", "Any", "prompt"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue