GithubHelp home page GithubHelp logo

Comments (6)

dosubot avatar dosubot commented on August 16, 2024 3

Hello, @DevPaby! I'm here to help you with any issues or questions you have. Feel free to ask me anything!

The error you're encountering indicates that the HumanMessage content is expected to be a string, but it is being received as a list. This issue can be resolved by ensuring that the input_value in the ChatInput component is always a string before it is passed to the OpenAI model.

Your current implementation already includes a check to convert input_value to a string if it is a list or any other type. However, the error suggests that this conversion might not be happening correctly in all cases.

Here is a refined version of your ChatInput component to ensure the input_value is always a string:

from typing import Optional, Union
from langflow.base.io.chat import ChatComponent
from langflow.schema.message import Message
from langflow.field_typing import Text

class ChatInput(ChatComponent):
    display_name = "Chat Input"
    description = "Get chat inputs from the Playground."
    icon = "ChatInput"

    def build_config(self):
        build_config = super().build_config()
        build_config["input_value"] = {
            "input_types": [],
            "display_name": "Text",
            "multiline": True,
        }
        build_config["return_message"] = {
            "display_name": "Return Record",
            "advanced": True,
        }
        return build_config

    def build(
        self,
        sender: Optional[str] = "User",
        sender_name: Optional[str] = "User",
        input_value: Optional[str] = None,
        files: Optional[list[str]] = None,
        session_id: Optional[str] = None,
        return_message: Optional[bool] = True,
    ) -> Union[Message, Text]:
        
        # Ensure input_value is a string
        if isinstance(input_value, list):
            input_value = " ".join(input_value)
        elif not isinstance(input_value, str):
            input_value = str(input_value)
        
        # Debugging output
        print(f"Processed input_value: {input_value} (type: {type(input_value)})") 

        return super().build_with_record(
            sender=sender,
            sender_name=sender_name,
            input_value=input_value,
            files=files,
            session_id=session_id,
            return_message=return_message,
        )

Additionally, ensure that the OpenAI model component is correctly configured to handle the input_value as a string. The expected structure and data type for the HumanMessage content in the OpenAI model component is Text [1].

If the issue persists, double-check the flow configuration and ensure that the input_value is correctly passed as a string throughout the entire flow.

To continue talking to Dosu, mention @dosu.

from langflow.

dosubot avatar dosubot commented on August 16, 2024 2

To resolve the issue where the output of the Chat Input is not being recognized as text by the OpenAI model, you need to ensure that the value passed to the InputListComponent is always an array. The provided code already includes a check to convert a string value to an array:

if (typeof value === "string") {
  value = [value];
}

Make sure this conversion is correctly applied before the value is used. This ensures that the value is always in the expected array format, preventing the error "content str type expected (type=type_error.str) content value is not a valid list (type=type_error.list)".

Here's the relevant part of the code with the conversion:

import { useEffect } from "react";
import { InputListComponentType } from "../../types/components";

import _ from "lodash";
import { classNames } from "../../utils/utils";
import IconComponent from "../genericIconComponent";
import { Input } from "../ui/input";

export default function InputListComponent({
  value,
  onChange,
  disabled,
  editNode = false,
  componentName,
  playgroundDisabled,
}: InputListComponentType): JSX.Element {
  useEffect(() => {
    if (disabled && value.length > 0 && value[0] !== "") {
      onChange([""]);
    }
  }, [disabled]);

  // @TODO Recursive Character Text Splitter - the value might be in string format, whereas the InputListComponent specifically requires an array format. To ensure smooth operation and prevent potential errors, it's crucial that we handle the conversion from a string to an array with the string as its element.
  if (typeof value === "string") {
    value = [value];
  }

  if (!value?.length) value = [""];

  return (
    <div
      className={classNames(
        value.length > 1 && editNode ? "my-1" : "",
        "flex flex-col gap-3",
      )}
    >
      {value.map((singleValue, idx) => {
        return (
          <div key={idx} className="flex w-full gap-3">
            <Input
              disabled={disabled || playgroundDisabled}
              type="text"
              value={singleValue}
              className={editNode ? "input-edit-node" : ""}
              placeholder="Type something..."
              onChange={(event) => {
                let newInputList = _.cloneDeep(value);
                newInputList[idx] = event.target.value;
                onChange(newInputList);
              }}
              data-testid={
                `input-list-input${editNode ? "-edit" : ""}_${componentName}-` +
                idx
              }
            />
            {idx === value.length - 1 ? (
              <button
                onClick={(e) => {
                  let newInputList = _.cloneDeep(value);
                  newInputList.push("");
                  onChange(newInputList);
                  e.preventDefault();
                }}
                data-testid={
                  `input-list-plus-btn${
                    editNode ? "-edit" : ""
                  }_${componentName}-` + idx
                }
                disabled={disabled || playgroundDisabled}
              >
                <IconComponent
                  name="Plus"
                  className={"h-4 w-4 hover:text-accent-foreground"}
                />
              </button>
            ) : (
              <button
                data-testid={
                  `input-list-minus-btn${
                    editNode ? "-edit" : ""
                  }_${componentName}-` + idx
                }
                onClick={(e) => {
                  let newInputList = _.cloneDeep(value);
                  newInputList.splice(idx, 1);
                  onChange(newInputList);
                  e.preventDefault();
                }}
                disabled={disabled || playgroundDisabled}
              >
                <IconComponent
                  name="X"
                  className={`h-4 w-4 ${
                    disabled || playgroundDisabled
                      ? ""
                      : "hover:text-accent-foreground"
                  }`}
                />
              </button>
            )}
          </div>
        );
      })}
    </div>
  );
}

Ensure that this code is correctly implemented and that the value passed to the InputListComponent is properly converted to an array if it is initially a string. This should resolve the error you are encountering [1][2].

To continue talking to Dosu, mention @dosu.

from langflow.

DevPaby avatar DevPaby commented on August 16, 2024

@dosu, You provide the same code I gave you. I have tried that code and its not working. Any other way to solve this?

from langflow.

msmygit avatar msmygit commented on August 16, 2024

same as #2182

from langflow.

YamonBot avatar YamonBot commented on August 16, 2024

Please insert the API key directly instead of using a variable. There is still a bug with using the variable.

from langflow.

nicoloboschi avatar nicoloboschi commented on August 16, 2024

duplicated of #2182 and working 1.0.5

from langflow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.