feat: Add combinatorial reasoning as a component (#4782)
* Add Icosa's Combinatorial Reasoner as component under tools * Remove temporary testing tool revert unit test script * reverting changes to locks * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes * Moved combinatorial reasoner component to separate icosacomputing folder for Icosa's bundle --------- Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
4d599590e2
commit
2a434f6844
8 changed files with 205 additions and 2 deletions
|
|
@ -0,0 +1,5 @@
|
|||
from .combinatorial_reasoner import CombinatorialReasonerComponent
|
||||
|
||||
__all__ = [
|
||||
"CombinatorialReasonerComponent",
|
||||
]
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
import requests
|
||||
from requests.auth import HTTPBasicAuth
|
||||
|
||||
from langflow.base.models.openai_constants import OPENAI_MODEL_NAMES
|
||||
from langflow.custom import Component
|
||||
from langflow.inputs import DropdownInput, SecretStrInput, StrInput
|
||||
from langflow.io import MessageTextInput, Output
|
||||
from langflow.schema import Data
|
||||
from langflow.schema.message import Message
|
||||
|
||||
|
||||
class CombinatorialReasonerComponent(Component):
|
||||
display_name = "Combinatorial Reasoner"
|
||||
description = "Uses Combinatorial Optimization to construct an optimal prompt with embedded reasons. Sign up here:\nhttps://forms.gle/oWNv2NKjBNaqqvCx6"
|
||||
icon = "Icosa"
|
||||
name = "Combinatorial Reasoner"
|
||||
|
||||
inputs = [
|
||||
MessageTextInput(name="prompt", display_name="Prompt"),
|
||||
SecretStrInput(
|
||||
name="openai_api_key",
|
||||
display_name="OpenAI API Key",
|
||||
info="The OpenAI API Key to use for the OpenAI model.",
|
||||
advanced=False,
|
||||
value="OPENAI_API_KEY",
|
||||
),
|
||||
StrInput(
|
||||
name="username",
|
||||
display_name="Username",
|
||||
info="Username to authenticate access to Icosa CR API",
|
||||
advanced=False,
|
||||
),
|
||||
SecretStrInput(
|
||||
name="password",
|
||||
display_name="Password",
|
||||
info="Password to authenticate access to Icosa CR API.",
|
||||
advanced=False,
|
||||
),
|
||||
DropdownInput(
|
||||
name="model_name",
|
||||
display_name="Model Name",
|
||||
advanced=False,
|
||||
options=OPENAI_MODEL_NAMES,
|
||||
value=OPENAI_MODEL_NAMES[0],
|
||||
),
|
||||
]
|
||||
|
||||
outputs = [
|
||||
Output(
|
||||
display_name="Optimized Prompt",
|
||||
name="optimized_prompt",
|
||||
method="build_prompt",
|
||||
),
|
||||
Output(display_name="Selected Reasons", name="reasons", method="build_reasons"),
|
||||
]
|
||||
|
||||
def build_prompt(self) -> Message:
|
||||
params = {
|
||||
"prompt": self.prompt,
|
||||
"apiKey": self.openai_api_key,
|
||||
"model": self.model_name,
|
||||
}
|
||||
|
||||
creds = HTTPBasicAuth(self.username, password=self.password)
|
||||
response = requests.post(
|
||||
"https://cr-api.icosacomputing.com/cr/langflow",
|
||||
json=params,
|
||||
auth=creds,
|
||||
timeout=100,
|
||||
)
|
||||
response.raise_for_status()
|
||||
|
||||
prompt = response.json()["prompt"]
|
||||
|
||||
self.reasons = response.json()["finalReasons"]
|
||||
return prompt
|
||||
|
||||
def build_reasons(self) -> Data:
|
||||
# list of selected reasons
|
||||
final_reasons = [reason[0] for reason in self.reasons]
|
||||
return Data(value=final_reasons)
|
||||
Loading…
Add table
Add a link
Reference in a new issue