Add LCModelComponent class to base/model.py
This commit is contained in:
parent
2b556d5fb3
commit
6dcad54a38
2 changed files with 28 additions and 0 deletions
0
src/backend/langflow/components/models/base/__init__.py
Normal file
0
src/backend/langflow/components/models/base/__init__.py
Normal file
28
src/backend/langflow/components/models/base/model.py
Normal file
28
src/backend/langflow/components/models/base/model.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
from langchain_core.runnables import Runnable
|
||||
|
||||
from langflow import CustomComponent
|
||||
|
||||
|
||||
class LCModelComponent(CustomComponent):
|
||||
display_name: str = "Model Name"
|
||||
description: str = "Model Description"
|
||||
|
||||
def get_result(self, output: Runnable, stream: bool, input_value: str):
|
||||
"""
|
||||
Retrieves the result from the output of a Runnable object.
|
||||
|
||||
Args:
|
||||
output (Runnable): The output object to retrieve the result from.
|
||||
stream (bool): Indicates whether to use streaming or invocation mode.
|
||||
input_value (str): The input value to pass to the output object.
|
||||
|
||||
Returns:
|
||||
The result obtained from the output object.
|
||||
"""
|
||||
if stream:
|
||||
result = output.stream(input_value)
|
||||
else:
|
||||
message = output.invoke(input_value)
|
||||
result = message.content if hasattr(message, "content") else message
|
||||
self.status = result
|
||||
return result
|
||||
Loading…
Add table
Add a link
Reference in a new issue