diff --git a/src/backend/base/langflow/initial_setup/starter_projects/Langflow Blog Writer.json b/src/backend/base/langflow/initial_setup/starter_projects/Langflow Blog Writer.json index d89b20a6c..8c425e2c3 100644 --- a/src/backend/base/langflow/initial_setup/starter_projects/Langflow Blog Writer.json +++ b/src/backend/base/langflow/initial_setup/starter_projects/Langflow Blog Writer.json @@ -1,6 +1,194 @@ { - "id": "abcd5472-71fb-431c-9a08-6fd7781ffaa4", "data": { + "edges": [ + { + "className": "", + "data": { + "sourceHandle": { + "dataType": "TextInput", + "id": "TextInput-DbgJ3", + "name": "text", + "output_types": [ + "Message" + ] + }, + "targetHandle": { + "fieldName": "instructions", + "id": "Prompt-jJ1i7", + "inputTypes": [ + "Message", + "Text" + ], + "type": "str" + } + }, + "id": "reactflow__edge-TextInput-DbgJ3{œdataTypeœ:œTextInputœ,œidœ:œTextInput-DbgJ3œ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}-Prompt-jJ1i7{œfieldNameœ:œinstructionsœ,œidœ:œPrompt-jJ1i7œ,œinputTypesœ:[œMessageœ,œTextœ],œtypeœ:œstrœ}", + "source": "TextInput-DbgJ3", + "sourceHandle": "{œdataTypeœ: œTextInputœ, œidœ: œTextInput-DbgJ3œ, œnameœ: œtextœ, œoutput_typesœ: [œMessageœ]}", + "target": "Prompt-jJ1i7", + "targetHandle": "{œfieldNameœ: œinstructionsœ, œidœ: œPrompt-jJ1i7œ, œinputTypesœ: [œMessageœ, œTextœ], œtypeœ: œstrœ}" + }, + { + "className": "", + "data": { + "sourceHandle": { + "dataType": "URL", + "id": "URL-43SB8", + "name": "data", + "output_types": [ + "Data" + ] + }, + "targetHandle": { + "fieldName": "data", + "id": "ParseData-34pEF", + "inputTypes": [ + "Data" + ], + "type": "other" + } + }, + "id": "reactflow__edge-URL-43SB8{œdataTypeœ:œURLœ,œidœ:œURL-43SB8œ,œnameœ:œdataœ,œoutput_typesœ:[œDataœ]}-ParseData-34pEF{œfieldNameœ:œdataœ,œidœ:œParseData-34pEFœ,œinputTypesœ:[œDataœ],œtypeœ:œotherœ}", + "selected": false, + "source": "URL-43SB8", + "sourceHandle": "{œdataTypeœ: œURLœ, œidœ: œURL-43SB8œ, œnameœ: œdataœ, œoutput_typesœ: [œDataœ]}", + "target": "ParseData-34pEF", + "targetHandle": "{œfieldNameœ: œdataœ, œidœ: œParseData-34pEFœ, œinputTypesœ: [œDataœ], œtypeœ: œotherœ}" + }, + { + "className": "", + "data": { + "sourceHandle": { + "dataType": "URL", + "id": "URL-eFIqb", + "name": "data", + "output_types": [ + "Data" + ] + }, + "targetHandle": { + "fieldName": "data", + "id": "ParseData-iAHWq", + "inputTypes": [ + "Data" + ], + "type": "other" + } + }, + "id": "reactflow__edge-URL-eFIqb{œdataTypeœ:œURLœ,œidœ:œURL-eFIqbœ,œnameœ:œdataœ,œoutput_typesœ:[œDataœ]}-ParseData-iAHWq{œfieldNameœ:œdataœ,œidœ:œParseData-iAHWqœ,œinputTypesœ:[œDataœ],œtypeœ:œotherœ}", + "source": "URL-eFIqb", + "sourceHandle": "{œdataTypeœ: œURLœ, œidœ: œURL-eFIqbœ, œnameœ: œdataœ, œoutput_typesœ: [œDataœ]}", + "target": "ParseData-iAHWq", + "targetHandle": "{œfieldNameœ: œdataœ, œidœ: œParseData-iAHWqœ, œinputTypesœ: [œDataœ], œtypeœ: œotherœ}" + }, + { + "className": "", + "data": { + "sourceHandle": { + "dataType": "ParseData", + "id": "ParseData-34pEF", + "name": "text", + "output_types": [ + "Message" + ] + }, + "targetHandle": { + "fieldName": "reference_2", + "id": "Prompt-jJ1i7", + "inputTypes": [ + "Message", + "Text" + ], + "type": "str" + } + }, + "id": "reactflow__edge-ParseData-34pEF{œdataTypeœ:œParseDataœ,œidœ:œParseData-34pEFœ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}-Prompt-jJ1i7{œfieldNameœ:œreference_2œ,œidœ:œPrompt-jJ1i7œ,œinputTypesœ:[œMessageœ,œTextœ],œtypeœ:œstrœ}", + "source": "ParseData-34pEF", + "sourceHandle": "{œdataTypeœ: œParseDataœ, œidœ: œParseData-34pEFœ, œnameœ: œtextœ, œoutput_typesœ: [œMessageœ]}", + "target": "Prompt-jJ1i7", + "targetHandle": "{œfieldNameœ: œreference_2œ, œidœ: œPrompt-jJ1i7œ, œinputTypesœ: [œMessageœ, œTextœ], œtypeœ: œstrœ}" + }, + { + "className": "", + "data": { + "sourceHandle": { + "dataType": "ParseData", + "id": "ParseData-iAHWq", + "name": "text", + "output_types": [ + "Message" + ] + }, + "targetHandle": { + "fieldName": "reference_1", + "id": "Prompt-jJ1i7", + "inputTypes": [ + "Message", + "Text" + ], + "type": "str" + } + }, + "id": "reactflow__edge-ParseData-iAHWq{œdataTypeœ:œParseDataœ,œidœ:œParseData-iAHWqœ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}-Prompt-jJ1i7{œfieldNameœ:œreference_1œ,œidœ:œPrompt-jJ1i7œ,œinputTypesœ:[œMessageœ,œTextœ],œtypeœ:œstrœ}", + "source": "ParseData-iAHWq", + "sourceHandle": "{œdataTypeœ: œParseDataœ, œidœ: œParseData-iAHWqœ, œnameœ: œtextœ, œoutput_typesœ: [œMessageœ]}", + "target": "Prompt-jJ1i7", + "targetHandle": "{œfieldNameœ: œreference_1œ, œidœ: œPrompt-jJ1i7œ, œinputTypesœ: [œMessageœ, œTextœ], œtypeœ: œstrœ}" + }, + { + "className": "", + "data": { + "sourceHandle": { + "dataType": "OpenAIModel", + "id": "OpenAIModel-slJZS", + "name": "text_output", + "output_types": [ + "Message" + ] + }, + "targetHandle": { + "fieldName": "input_value", + "id": "ChatOutput-LkJX7", + "inputTypes": [ + "Message", + "str" + ], + "type": "str" + } + }, + "id": "reactflow__edge-OpenAIModel-slJZS{œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-slJZSœ,œnameœ:œtext_outputœ,œoutput_typesœ:[œMessageœ]}-ChatOutput-LkJX7{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-LkJX7œ,œinputTypesœ:[œMessageœ,œstrœ],œtypeœ:œstrœ}", + "source": "OpenAIModel-slJZS", + "sourceHandle": "{œdataTypeœ: œOpenAIModelœ, œidœ: œOpenAIModel-slJZSœ, œnameœ: œtext_outputœ, œoutput_typesœ: [œMessageœ]}", + "target": "ChatOutput-LkJX7", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œChatOutput-LkJX7œ, œinputTypesœ: [œMessageœ, œstrœ], œtypeœ: œstrœ}" + }, + { + "className": "", + "data": { + "sourceHandle": { + "dataType": "Prompt", + "id": "Prompt-jJ1i7", + "name": "prompt", + "output_types": [ + "Message" + ] + }, + "targetHandle": { + "fieldName": "input_value", + "id": "OpenAIModel-slJZS", + "inputTypes": [ + "Message" + ], + "type": "str" + } + }, + "id": "reactflow__edge-Prompt-jJ1i7{œdataTypeœ:œPromptœ,œidœ:œPrompt-jJ1i7œ,œnameœ:œpromptœ,œoutput_typesœ:[œMessageœ]}-OpenAIModel-slJZS{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-slJZSœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}", + "source": "Prompt-jJ1i7", + "sourceHandle": "{œdataTypeœ: œPromptœ, œidœ: œPrompt-jJ1i7œ, œnameœ: œpromptœ, œoutput_typesœ: [œMessageœ]}", + "target": "OpenAIModel-slJZS", + "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œOpenAIModel-slJZSœ, œinputTypesœ: [œMessageœ], œtypeœ: œstrœ}" + } + ], "nodes": [ { "data": { @@ -365,75 +553,75 @@ "edited": false, "id": "TextInput-DbgJ3", "node": { - "template": { - "_type": "Component", - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "from langflow.base.io.text import TextComponent\nfrom langflow.io import Output, TextInput\nfrom langflow.schema.message import Message\n\n\nclass TextInputComponent(TextComponent):\n display_name = \"Text Input\"\n description = \"Get text inputs from the Playground.\"\n icon = \"type\"\n\n inputs = [\n TextInput(\n name=\"input_value\",\n display_name=\"Text\",\n info=\"Text to be passed as input.\",\n ),\n ]\n outputs = [\n Output(display_name=\"Text\", name=\"text\", method=\"text_response\"),\n ]\n\n def text_response(self) -> Message:\n message = Message(\n text=self.input_value,\n )\n return message\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "input_value": { - "load_from_db": false, - "list": false, - "required": false, - "placeholder": "", - "show": true, - "value": "Use the references above for style to write a new blog/tutorial about prompt engineering techniques. Suggest non-covered topics.", - "name": "input_value", - "display_name": "Text", - "advanced": false, - "input_types": [ - "Message" - ], - "dynamic": false, - "info": "Text to be passed as input.", - "title_case": false, - "type": "str" - } - }, - "description": "Get text inputs from the Playground.", - "icon": "type", "base_classes": [ "Message" ], + "beta": false, + "conditional_paths": [], + "custom_fields": {}, + "description": "Get text inputs from the Playground.", "display_name": "Instructions", "documentation": "", - "custom_fields": {}, - "output_types": [], - "pinned": false, - "conditional_paths": [], - "frozen": false, - "outputs": [ - { - "types": [ - "Message" - ], - "selected": "Message", - "name": "text", - "display_name": "Text", - "method": "text_response", - "value": "__UNDEFINED__", - "cache": true - } - ], + "edited": true, "field_order": [ "input_value" ], - "beta": false, - "edited": true + "frozen": false, + "icon": "type", + "output_types": [], + "outputs": [ + { + "cache": true, + "display_name": "Text", + "method": "text_response", + "name": "text", + "selected": "Message", + "types": [ + "Message" + ], + "value": "__UNDEFINED__" + } + ], + "pinned": false, + "template": { + "_type": "Component", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "from langflow.base.io.text import TextComponent\nfrom langflow.io import Output, TextInput\nfrom langflow.schema.message import Message\n\n\nclass TextInputComponent(TextComponent):\n display_name = \"Text Input\"\n description = \"Get text inputs from the Playground.\"\n icon = \"type\"\n\n inputs = [\n TextInput(\n name=\"input_value\",\n display_name=\"Text\",\n info=\"Text to be passed as input.\",\n ),\n ]\n outputs = [\n Output(display_name=\"Text\", name=\"text\", method=\"text_response\"),\n ]\n\n def text_response(self) -> Message:\n message = Message(\n text=self.input_value,\n )\n return message\n" + }, + "input_value": { + "advanced": false, + "display_name": "Text", + "dynamic": false, + "info": "Text to be passed as input.", + "input_types": [ + "Message" + ], + "list": false, + "load_from_db": false, + "name": "input_value", + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "Use the references above for style to write a new blog/tutorial about prompt engineering techniques. Suggest non-covered topics." + } + } }, "type": "TextInput" }, @@ -696,234 +884,22 @@ }, { "data": { + "description": "Generates text using OpenAI LLMs.", + "display_name": "OpenAI", + "edited": false, "id": "OpenAIModel-slJZS", "node": { - "template": { - "_type": "Component", - "code": { - "type": "code", - "required": true, - "placeholder": "", - "list": false, - "show": true, - "multiline": true, - "value": "import operator\nfrom functools import reduce\n\nfrom langchain_openai import ChatOpenAI\nfrom pydantic.v1 import SecretStr\n\nfrom langflow.base.constants import STREAM_INFO_TEXT\nfrom langflow.base.models.model import LCModelComponent\nfrom langflow.base.models.openai_constants import MODEL_NAMES\nfrom langflow.field_typing import LanguageModel\nfrom langflow.inputs import (\n BoolInput,\n DictInput,\n DropdownInput,\n FloatInput,\n IntInput,\n MessageInput,\n SecretStrInput,\n StrInput,\n)\n\n\nclass OpenAIModelComponent(LCModelComponent):\n display_name = \"OpenAI\"\n description = \"Generates text using OpenAI LLMs.\"\n icon = \"OpenAI\"\n\n inputs = [\n MessageInput(name=\"input_value\", display_name=\"Input\"),\n IntInput(\n name=\"max_tokens\",\n display_name=\"Max Tokens\",\n advanced=True,\n info=\"The maximum number of tokens to generate. Set to 0 for unlimited tokens.\",\n ),\n DictInput(name=\"model_kwargs\", display_name=\"Model Kwargs\", advanced=True),\n DictInput(\n name=\"output_schema\",\n is_list=True,\n display_name=\"Schema\",\n advanced=True,\n info=\"The schema for the Output of the model. You must pass the word JSON in the prompt. If left blank, JSON mode will be disabled.\",\n ),\n DropdownInput(\n name=\"model_name\", display_name=\"Model Name\", advanced=False, options=MODEL_NAMES, value=MODEL_NAMES[0]\n ),\n StrInput(\n name=\"openai_api_base\",\n display_name=\"OpenAI API Base\",\n advanced=True,\n info=\"The base URL of the OpenAI API. Defaults to https://api.openai.com/v1. You can change this to use other APIs like JinaChat, LocalAI and Prem.\",\n ),\n SecretStrInput(\n name=\"openai_api_key\",\n display_name=\"OpenAI API Key\",\n info=\"The OpenAI API Key to use for the OpenAI model.\",\n advanced=False,\n value=\"OPENAI_API_KEY\",\n ),\n FloatInput(name=\"temperature\", display_name=\"Temperature\", value=0.1),\n BoolInput(name=\"stream\", display_name=\"Stream\", info=STREAM_INFO_TEXT, advanced=True),\n StrInput(\n name=\"system_message\",\n display_name=\"System Message\",\n info=\"System message to pass to the model.\",\n advanced=True,\n ),\n IntInput(\n name=\"seed\",\n display_name=\"Seed\",\n info=\"The seed controls the reproducibility of the job.\",\n advanced=True,\n value=1,\n ),\n ]\n\n def build_model(self) -> LanguageModel:\n # self.output_schea is a list of dictionaries\n # let's convert it to a dictionary\n output_schema_dict: dict[str, str] = reduce(operator.ior, self.output_schema or {}, {})\n openai_api_key = self.openai_api_key\n temperature = self.temperature\n model_name: str = self.model_name\n max_tokens = self.max_tokens\n model_kwargs = self.model_kwargs or {}\n openai_api_base = self.openai_api_base or \"https://api.openai.com/v1\"\n json_mode = bool(output_schema_dict)\n seed = self.seed\n model_kwargs[\"seed\"] = seed\n\n if openai_api_key:\n api_key = SecretStr(openai_api_key)\n else:\n api_key = None\n output = ChatOpenAI(\n max_tokens=max_tokens or None,\n model_kwargs=model_kwargs,\n model=model_name,\n base_url=openai_api_base,\n api_key=api_key,\n temperature=temperature or 0.1,\n )\n if json_mode:\n output = output.with_structured_output(schema=output_schema_dict, method=\"json_mode\") # type: ignore\n\n return output\n\n def _get_exception_message(self, e: Exception):\n \"\"\"\n Get a message from an OpenAI exception.\n\n Args:\n exception (Exception): The exception to get the message from.\n\n Returns:\n str: The message from the exception.\n \"\"\"\n\n try:\n from openai import BadRequestError\n except ImportError:\n return\n if isinstance(e, BadRequestError):\n message = e.body.get(\"message\") # type: ignore\n if message:\n return message\n return\n", - "fileTypes": [], - "file_path": "", - "password": false, - "name": "code", - "advanced": true, - "dynamic": true, - "info": "", - "load_from_db": false, - "title_case": false - }, - "input_value": { - "load_from_db": false, - "list": false, - "required": false, - "placeholder": "", - "show": true, - "value": "", - "name": "input_value", - "display_name": "Input", - "advanced": false, - "input_types": [ - "Message" - ], - "dynamic": false, - "info": "", - "title_case": false, - "type": "str" - }, - "max_tokens": { - "list": false, - "required": false, - "placeholder": "", - "show": true, - "value": "", - "name": "max_tokens", - "display_name": "Max Tokens", - "advanced": true, - "dynamic": false, - "info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.", - "title_case": false, - "type": "int" - }, - "model_kwargs": { - "list": false, - "required": false, - "placeholder": "", - "show": true, - "value": {}, - "name": "model_kwargs", - "display_name": "Model Kwargs", - "advanced": true, - "dynamic": false, - "info": "", - "title_case": false, - "type": "dict" - }, - "model_name": { - "options": [ - "gpt-4o", - "gpt-4-turbo", - "gpt-4-turbo-preview", - "gpt-3.5-turbo", - "gpt-3.5-turbo-0125" - ], - "required": false, - "placeholder": "", - "show": true, - "value": "gpt-3.5-turbo", - "name": "model_name", - "display_name": "Model Name", - "advanced": false, - "dynamic": false, - "info": "", - "title_case": false, - "type": "str" - }, - "openai_api_base": { - "load_from_db": false, - "list": false, - "required": false, - "placeholder": "", - "show": true, - "value": "", - "name": "openai_api_base", - "display_name": "OpenAI API Base", - "advanced": true, - "dynamic": false, - "info": "The base URL of the OpenAI API. Defaults to https://api.openai.com/v1. You can change this to use other APIs like JinaChat, LocalAI and Prem.", - "title_case": false, - "type": "str" - }, - "openai_api_key": { - "load_from_db": true, - "required": false, - "placeholder": "", - "show": true, - "value": "", - "name": "openai_api_key", - "display_name": "OpenAI API Key", - "advanced": false, - "input_types": [], - "dynamic": false, - "info": "The OpenAI API Key to use for the OpenAI model.", - "title_case": false, - "password": true, - "type": "str" - }, - "output_schema": { - "list": true, - "required": false, - "placeholder": "", - "show": true, - "value": {}, - "name": "output_schema", - "display_name": "Schema", - "advanced": true, - "dynamic": false, - "info": "The schema for the Output of the model. You must pass the word JSON in the prompt. If left blank, JSON mode will be disabled.", - "title_case": false, - "type": "dict" - }, - "seed": { - "list": false, - "required": false, - "placeholder": "", - "show": true, - "value": 1, - "name": "seed", - "display_name": "Seed", - "advanced": true, - "dynamic": false, - "info": "The seed controls the reproducibility of the job.", - "title_case": false, - "type": "int" - }, - "stream": { - "list": false, - "required": false, - "placeholder": "", - "show": true, - "value": false, - "name": "stream", - "display_name": "Stream", - "advanced": true, - "dynamic": false, - "info": "Stream the response from the model. Streaming works only in Chat.", - "title_case": false, - "type": "bool" - }, - "system_message": { - "load_from_db": false, - "list": false, - "required": false, - "placeholder": "", - "show": true, - "value": "", - "name": "system_message", - "display_name": "System Message", - "advanced": true, - "dynamic": false, - "info": "System message to pass to the model.", - "title_case": false, - "type": "str" - }, - "temperature": { - "list": false, - "required": false, - "placeholder": "", - "show": true, - "value": 0.1, - "name": "temperature", - "display_name": "Temperature", - "advanced": false, - "dynamic": false, - "info": "", - "title_case": false, - "type": "float" - } - }, - "description": "Generates text using OpenAI LLMs.", - "icon": "OpenAI", "base_classes": [ "LanguageModel", "Message" ], + "beta": false, + "conditional_paths": [], + "custom_fields": {}, + "description": "Generates text using OpenAI LLMs.", "display_name": "OpenAI", "documentation": "", - "custom_fields": {}, - "output_types": [], - "pinned": false, - "conditional_paths": [], - "frozen": false, - "outputs": [ - { - "types": [ - "Message" - ], - "selected": "Message", - "name": "text_output", - "display_name": "Text", - "method": "text_response", - "value": "__UNDEFINED__", - "cache": true - }, - { - "types": [ - "LanguageModel" - ], - "selected": "LanguageModel", - "name": "model_output", - "display_name": "Language Model", - "method": "build_model", - "value": "__UNDEFINED__", - "cache": true - } - ], + "edited": true, "field_order": [ "input_value", "max_tokens", @@ -937,13 +913,225 @@ "system_message", "seed" ], - "beta": false, - "edited": true + "frozen": false, + "icon": "OpenAI", + "output_types": [], + "outputs": [ + { + "cache": true, + "display_name": "Text", + "method": "text_response", + "name": "text_output", + "selected": "Message", + "types": [ + "Message" + ], + "value": "__UNDEFINED__" + }, + { + "cache": true, + "display_name": "Language Model", + "method": "build_model", + "name": "model_output", + "selected": "LanguageModel", + "types": [ + "LanguageModel" + ], + "value": "__UNDEFINED__" + } + ], + "pinned": false, + "template": { + "_type": "Component", + "code": { + "advanced": true, + "dynamic": true, + "fileTypes": [], + "file_path": "", + "info": "", + "list": false, + "load_from_db": false, + "multiline": true, + "name": "code", + "password": false, + "placeholder": "", + "required": true, + "show": true, + "title_case": false, + "type": "code", + "value": "import operator\nfrom functools import reduce\n\nfrom langchain_openai import ChatOpenAI\nfrom pydantic.v1 import SecretStr\n\nfrom langflow.base.constants import STREAM_INFO_TEXT\nfrom langflow.base.models.model import LCModelComponent\nfrom langflow.base.models.openai_constants import MODEL_NAMES\nfrom langflow.field_typing import LanguageModel\nfrom langflow.inputs import (\n BoolInput,\n DictInput,\n DropdownInput,\n FloatInput,\n IntInput,\n MessageInput,\n SecretStrInput,\n StrInput,\n)\n\n\nclass OpenAIModelComponent(LCModelComponent):\n display_name = \"OpenAI\"\n description = \"Generates text using OpenAI LLMs.\"\n icon = \"OpenAI\"\n\n inputs = [\n MessageInput(name=\"input_value\", display_name=\"Input\"),\n IntInput(\n name=\"max_tokens\",\n display_name=\"Max Tokens\",\n advanced=True,\n info=\"The maximum number of tokens to generate. Set to 0 for unlimited tokens.\",\n ),\n DictInput(name=\"model_kwargs\", display_name=\"Model Kwargs\", advanced=True),\n DictInput(\n name=\"output_schema\",\n is_list=True,\n display_name=\"Schema\",\n advanced=True,\n info=\"The schema for the Output of the model. You must pass the word JSON in the prompt. If left blank, JSON mode will be disabled.\",\n ),\n DropdownInput(\n name=\"model_name\", display_name=\"Model Name\", advanced=False, options=MODEL_NAMES, value=MODEL_NAMES[0]\n ),\n StrInput(\n name=\"openai_api_base\",\n display_name=\"OpenAI API Base\",\n advanced=True,\n info=\"The base URL of the OpenAI API. Defaults to https://api.openai.com/v1. You can change this to use other APIs like JinaChat, LocalAI and Prem.\",\n ),\n SecretStrInput(\n name=\"openai_api_key\",\n display_name=\"OpenAI API Key\",\n info=\"The OpenAI API Key to use for the OpenAI model.\",\n advanced=False,\n value=\"OPENAI_API_KEY\",\n ),\n FloatInput(name=\"temperature\", display_name=\"Temperature\", value=0.1),\n BoolInput(name=\"stream\", display_name=\"Stream\", info=STREAM_INFO_TEXT, advanced=True),\n StrInput(\n name=\"system_message\",\n display_name=\"System Message\",\n info=\"System message to pass to the model.\",\n advanced=True,\n ),\n IntInput(\n name=\"seed\",\n display_name=\"Seed\",\n info=\"The seed controls the reproducibility of the job.\",\n advanced=True,\n value=1,\n ),\n ]\n\n def build_model(self) -> LanguageModel:\n # self.output_schea is a list of dictionaries\n # let's convert it to a dictionary\n output_schema_dict: dict[str, str] = reduce(operator.ior, self.output_schema or {}, {})\n openai_api_key = self.openai_api_key\n temperature = self.temperature\n model_name: str = self.model_name\n max_tokens = self.max_tokens\n model_kwargs = self.model_kwargs or {}\n openai_api_base = self.openai_api_base or \"https://api.openai.com/v1\"\n json_mode = bool(output_schema_dict)\n seed = self.seed\n model_kwargs[\"seed\"] = seed\n\n if openai_api_key:\n api_key = SecretStr(openai_api_key)\n else:\n api_key = None\n output = ChatOpenAI(\n max_tokens=max_tokens or None,\n model_kwargs=model_kwargs,\n model=model_name,\n base_url=openai_api_base,\n api_key=api_key,\n temperature=temperature or 0.1,\n )\n if json_mode:\n output = output.with_structured_output(schema=output_schema_dict, method=\"json_mode\") # type: ignore\n\n return output\n\n def _get_exception_message(self, e: Exception):\n \"\"\"\n Get a message from an OpenAI exception.\n\n Args:\n exception (Exception): The exception to get the message from.\n\n Returns:\n str: The message from the exception.\n \"\"\"\n\n try:\n from openai import BadRequestError\n except ImportError:\n return\n if isinstance(e, BadRequestError):\n message = e.body.get(\"message\") # type: ignore\n if message:\n return message\n return\n" + }, + "input_value": { + "advanced": false, + "display_name": "Input", + "dynamic": false, + "info": "", + "input_types": [ + "Message" + ], + "list": false, + "load_from_db": false, + "name": "input_value", + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "max_tokens": { + "advanced": true, + "display_name": "Max Tokens", + "dynamic": false, + "info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.", + "list": false, + "name": "max_tokens", + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int", + "value": "" + }, + "model_kwargs": { + "advanced": true, + "display_name": "Model Kwargs", + "dynamic": false, + "info": "", + "list": false, + "name": "model_kwargs", + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "dict", + "value": {} + }, + "model_name": { + "advanced": false, + "display_name": "Model Name", + "dynamic": false, + "info": "", + "name": "model_name", + "options": [ + "gpt-4o", + "gpt-4-turbo", + "gpt-4-turbo-preview", + "gpt-3.5-turbo", + "gpt-3.5-turbo-0125" + ], + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "gpt-3.5-turbo" + }, + "openai_api_base": { + "advanced": true, + "display_name": "OpenAI API Base", + "dynamic": false, + "info": "The base URL of the OpenAI API. Defaults to https://api.openai.com/v1. You can change this to use other APIs like JinaChat, LocalAI and Prem.", + "list": false, + "load_from_db": false, + "name": "openai_api_base", + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "openai_api_key": { + "advanced": false, + "display_name": "OpenAI API Key", + "dynamic": false, + "info": "The OpenAI API Key to use for the OpenAI model.", + "input_types": [], + "load_from_db": true, + "name": "openai_api_key", + "password": true, + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "output_schema": { + "advanced": true, + "display_name": "Schema", + "dynamic": false, + "info": "The schema for the Output of the model. You must pass the word JSON in the prompt. If left blank, JSON mode will be disabled.", + "list": true, + "name": "output_schema", + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "dict", + "value": {} + }, + "seed": { + "advanced": true, + "display_name": "Seed", + "dynamic": false, + "info": "The seed controls the reproducibility of the job.", + "list": false, + "name": "seed", + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "int", + "value": 1 + }, + "stream": { + "advanced": true, + "display_name": "Stream", + "dynamic": false, + "info": "Stream the response from the model. Streaming works only in Chat.", + "list": false, + "name": "stream", + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "bool", + "value": false + }, + "system_message": { + "advanced": true, + "display_name": "System Message", + "dynamic": false, + "info": "System message to pass to the model.", + "list": false, + "load_from_db": false, + "name": "system_message", + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "str", + "value": "" + }, + "temperature": { + "advanced": false, + "display_name": "Temperature", + "dynamic": false, + "info": "", + "list": false, + "name": "temperature", + "placeholder": "", + "required": false, + "show": true, + "title_case": false, + "type": "float", + "value": 0.1 + } + } }, - "type": "OpenAIModel", - "description": "Generates text using OpenAI LLMs.", - "display_name": "OpenAI", - "edited": false + "type": "OpenAIModel" }, "dragging": false, "height": 623, @@ -1134,195 +1322,6 @@ "width": 384 } ], - "edges": [ - { - "data": { - "sourceHandle": { - "dataType": "TextInput", - "id": "TextInput-DbgJ3", - "name": "text", - "output_types": [ - "Message" - ] - }, - "targetHandle": { - "fieldName": "instructions", - "id": "Prompt-jJ1i7", - "inputTypes": [ - "Message", - "Text" - ], - "type": "str" - } - }, - "id": "reactflow__edge-TextInput-DbgJ3{œdataTypeœ:œTextInputœ,œidœ:œTextInput-DbgJ3œ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}-Prompt-jJ1i7{œfieldNameœ:œinstructionsœ,œidœ:œPrompt-jJ1i7œ,œinputTypesœ:[œMessageœ,œTextœ],œtypeœ:œstrœ}", - "source": "TextInput-DbgJ3", - "sourceHandle": "{œdataTypeœ:œTextInputœ,œidœ:œTextInput-DbgJ3œ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}", - "target": "Prompt-jJ1i7", - "targetHandle": "{œfieldNameœ:œinstructionsœ,œidœ:œPrompt-jJ1i7œ,œinputTypesœ:[œMessageœ,œTextœ],œtypeœ:œstrœ}", - "className": "" - }, - { - "data": { - "sourceHandle": { - "dataType": "URL", - "id": "URL-43SB8", - "name": "data", - "output_types": [ - "Data" - ] - }, - "targetHandle": { - "fieldName": "data", - "id": "ParseData-34pEF", - "inputTypes": [ - "Data" - ], - "type": "other" - } - }, - "id": "reactflow__edge-URL-43SB8{œdataTypeœ:œURLœ,œidœ:œURL-43SB8œ,œnameœ:œdataœ,œoutput_typesœ:[œDataœ]}-ParseData-34pEF{œfieldNameœ:œdataœ,œidœ:œParseData-34pEFœ,œinputTypesœ:[œDataœ],œtypeœ:œotherœ}", - "selected": false, - "source": "URL-43SB8", - "sourceHandle": "{œdataTypeœ:œURLœ,œidœ:œURL-43SB8œ,œnameœ:œdataœ,œoutput_typesœ:[œDataœ]}", - "target": "ParseData-34pEF", - "targetHandle": "{œfieldNameœ:œdataœ,œidœ:œParseData-34pEFœ,œinputTypesœ:[œDataœ],œtypeœ:œotherœ}", - "className": "" - }, - { - "data": { - "sourceHandle": { - "dataType": "URL", - "id": "URL-eFIqb", - "name": "data", - "output_types": [ - "Data" - ] - }, - "targetHandle": { - "fieldName": "data", - "id": "ParseData-iAHWq", - "inputTypes": [ - "Data" - ], - "type": "other" - } - }, - "id": "reactflow__edge-URL-eFIqb{œdataTypeœ:œURLœ,œidœ:œURL-eFIqbœ,œnameœ:œdataœ,œoutput_typesœ:[œDataœ]}-ParseData-iAHWq{œfieldNameœ:œdataœ,œidœ:œParseData-iAHWqœ,œinputTypesœ:[œDataœ],œtypeœ:œotherœ}", - "source": "URL-eFIqb", - "sourceHandle": "{œdataTypeœ:œURLœ,œidœ:œURL-eFIqbœ,œnameœ:œdataœ,œoutput_typesœ:[œDataœ]}", - "target": "ParseData-iAHWq", - "targetHandle": "{œfieldNameœ:œdataœ,œidœ:œParseData-iAHWqœ,œinputTypesœ:[œDataœ],œtypeœ:œotherœ}", - "className": "" - }, - { - "data": { - "sourceHandle": { - "dataType": "ParseData", - "id": "ParseData-34pEF", - "name": "text", - "output_types": [ - "Message" - ] - }, - "targetHandle": { - "fieldName": "reference_2", - "id": "Prompt-jJ1i7", - "inputTypes": [ - "Message", - "Text" - ], - "type": "str" - } - }, - "id": "reactflow__edge-ParseData-34pEF{œdataTypeœ:œParseDataœ,œidœ:œParseData-34pEFœ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}-Prompt-jJ1i7{œfieldNameœ:œreference_2œ,œidœ:œPrompt-jJ1i7œ,œinputTypesœ:[œMessageœ,œTextœ],œtypeœ:œstrœ}", - "source": "ParseData-34pEF", - "sourceHandle": "{œdataTypeœ:œParseDataœ,œidœ:œParseData-34pEFœ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}", - "target": "Prompt-jJ1i7", - "targetHandle": "{œfieldNameœ:œreference_2œ,œidœ:œPrompt-jJ1i7œ,œinputTypesœ:[œMessageœ,œTextœ],œtypeœ:œstrœ}", - "className": "" - }, - { - "data": { - "sourceHandle": { - "dataType": "ParseData", - "id": "ParseData-iAHWq", - "name": "text", - "output_types": [ - "Message" - ] - }, - "targetHandle": { - "fieldName": "reference_1", - "id": "Prompt-jJ1i7", - "inputTypes": [ - "Message", - "Text" - ], - "type": "str" - } - }, - "id": "reactflow__edge-ParseData-iAHWq{œdataTypeœ:œParseDataœ,œidœ:œParseData-iAHWqœ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}-Prompt-jJ1i7{œfieldNameœ:œreference_1œ,œidœ:œPrompt-jJ1i7œ,œinputTypesœ:[œMessageœ,œTextœ],œtypeœ:œstrœ}", - "source": "ParseData-iAHWq", - "sourceHandle": "{œdataTypeœ:œParseDataœ,œidœ:œParseData-iAHWqœ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}", - "target": "Prompt-jJ1i7", - "targetHandle": "{œfieldNameœ:œreference_1œ,œidœ:œPrompt-jJ1i7œ,œinputTypesœ:[œMessageœ,œTextœ],œtypeœ:œstrœ}", - "className": "" - }, - { - "data": { - "sourceHandle": { - "dataType": "OpenAIModel", - "id": "OpenAIModel-slJZS", - "name": "text_output", - "output_types": [ - "Message" - ] - }, - "targetHandle": { - "fieldName": "input_value", - "id": "ChatOutput-LkJX7", - "inputTypes": [ - "Message", - "str" - ], - "type": "str" - } - }, - "id": "reactflow__edge-OpenAIModel-slJZS{œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-slJZSœ,œnameœ:œtext_outputœ,œoutput_typesœ:[œMessageœ]}-ChatOutput-LkJX7{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-LkJX7œ,œinputTypesœ:[œMessageœ,œstrœ],œtypeœ:œstrœ}", - "source": "OpenAIModel-slJZS", - "sourceHandle": "{œdataTypeœ:œOpenAIModelœ,œidœ:œOpenAIModel-slJZSœ,œnameœ:œtext_outputœ,œoutput_typesœ:[œMessageœ]}", - "target": "ChatOutput-LkJX7", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-LkJX7œ,œinputTypesœ:[œMessageœ,œstrœ],œtypeœ:œstrœ}", - "className": "" - }, - { - "data": { - "sourceHandle": { - "dataType": "Prompt", - "id": "Prompt-jJ1i7", - "name": "prompt", - "output_types": [ - "Message" - ] - }, - "targetHandle": { - "fieldName": "input_value", - "id": "OpenAIModel-slJZS", - "inputTypes": [ - "Message" - ], - "type": "str" - } - }, - "id": "reactflow__edge-Prompt-jJ1i7{œdataTypeœ:œPromptœ,œidœ:œPrompt-jJ1i7œ,œnameœ:œpromptœ,œoutput_typesœ:[œMessageœ]}-OpenAIModel-slJZS{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-slJZSœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}", - "source": "Prompt-jJ1i7", - "sourceHandle": "{œdataTypeœ:œPromptœ,œidœ:œPrompt-jJ1i7œ,œnameœ:œpromptœ,œoutput_typesœ:[œMessageœ]}", - "target": "OpenAIModel-slJZS", - "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œOpenAIModel-slJZSœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}", - "className": "" - } - ], "viewport": { "x": 40.848461446679266, "y": 89.0650521913791, @@ -1330,8 +1329,9 @@ } }, "description": "This flow can be used to create a blog post following instructions from the user, using two other blogs as reference.", - "name": "Blog Writer", - "last_tested_version": "1.0.0a61", "endpoint_name": null, - "is_component": false + "id": "abcd5472-71fb-431c-9a08-6fd7781ffaa4", + "is_component": false, + "last_tested_version": "1.0.0a61", + "name": "Blog Writer" } \ No newline at end of file