Giter Club home page Giter Club logo

Comments (5)

dosubot avatar dosubot commented on July 20, 2024 3

Hello @sorenaakjaer! I'm here to help you with any bugs, questions, or contributions you have for the Langflow repository. Let me know how I can assist you!

The error you're encountering with the "ChatInput" and "ChatOutput" components in Langflow is due to validation issues with the Message class. Specifically, the text field in the Message class is not being recognized as a valid string, and there are additional checks for AsyncIterator and Iterator types.

To resolve this issue, ensure that the text field in the Message class is correctly formatted as a string. Here are the key points to check:

  1. Ensure text is a String: The text field should be a valid string. If it's not, you need to convert it to a string before passing it to the ChatOutput component.

  2. Validation Rules: The Message class has specific validation rules to ensure the text field is not an AsyncIterator or Iterator. Here is the relevant code snippet for the Message class:

    @field_serializer("text", mode="plain")
    def serialize_text(self, value):
        if isinstance(value, AsyncIterator):
            return ""
        elif isinstance(value, Iterator):
            return ""
        return value
  3. Correct Parameters: Ensure that the parameters passed to the build method of the ChatOutput component are correctly provided and match the expected types. Here is the relevant code snippet for the ChatOutput component:

    from typing import Optional, Union
    
    from langflow.base.io.chat import ChatComponent
    from langflow.field_typing import Text
    from langflow.schema import Record
    
    class ChatOutput(ChatComponent):
        display_name = "Chat Output"
        description = "Display a chat message in the Interaction Panel."
        icon = "ChatOutput"
    
        def build(
            self,
            sender: Optional[str] = "Machine",
            sender_name: Optional[str] = "AI",
            input_value: Optional[str] = None,
            session_id: Optional[str] = None,
            return_record: Optional[bool] = False,
            record_template: Optional[str] = "{text}",
        ) -> Union[Text, Record]:
            return super().build_with_record(
                sender=sender,
                sender_name=sender_name,
                input_value=input_value,
                session_id=session_id,
                return_record=return_record,
                record_template=record_template or "",
            )

Make sure that when you are using the ChatOutput component, you provide the necessary parameters such as sender, sender_name, input_value, session_id, return_record, and record_template correctly. If any of these parameters are missing or incorrectly typed, it could lead to validation errors [1][2].

By ensuring the text field is a valid string and correctly passing the parameters, you should be able to resolve the validation error.

To continue talking to Dosu, mention @dosu.

from langflow.

sorenaakjaer avatar sorenaakjaer commented on July 20, 2024

Hi

The problem is not on the Chat Output component as it also fails if a drag the ChatInput component to a OpenAI Model

from langflow.

sorenaakjaer avatar sorenaakjaer commented on July 20, 2024

ChatGPT suggest the follwing:

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

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]:
    if input_value is None:
        logging.error("input_value cannot be None")
        raise ValueError("input_value cannot be None")
    
    message = Message(
        text=input_value,
        sender=sender,
        sender_name=sender_name,
        timestamp=datetime.utcnow().isoformat(),
        flow_id=None
    )
    
    logging.debug(f"Built message: {message}")
    return message if return_message else input_value

`

It just seems strange that i need to make code adjustments to such a simple setup

from langflow.

sorenaakjaer avatar sorenaakjaer commented on July 20, 2024

I actually found a fix! If i add en "Text Output" in between there are not issue

image

from langflow.

manirajanvn avatar manirajanvn commented on July 20, 2024

I had same issue, after disabling return record value in chat input advanced option, issue not occurred.

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.