Comments (6)
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.
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.
@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.
same as #2182
from langflow.
Please insert the API key directly instead of using a variable. There is still a bug with using the variable.
from langflow.
duplicated of #2182 and working 1.0.5
from langflow.
Related Issues (20)
- Playground does not fully clear chat history HOT 2
- fix:The "No suitable component" error is appearing on the OpenAI component and other components due to a missing check. HOT 7
- [Export] From json to python code. HOT 1
- problems with make and python on windows wls HOT 5
- langflow 1.0.15 import problem HOT 5
- Global variables that persist across version updates
- سلام HOT 2
- The createData component is unavailable HOT 5
- "Sorry, we found an unexpected error! " message HOT 5
- Missing transformers HOT 2
- Error - Edge between CrewAIAgentComponent HOT 2
- Low level of contrast between text and background while editing - IA Devs HOT 1
- v1.0.15 - Not able to Sign Up new users HOT 4
- Not working the IDE HOT 2
- Cannot enlarge LLM output blocks in UI HOT 1
- Langflow API error HOT 2
- Wrong docker hub version tag HOT 2
- Whole flows disappearing when opened, then disappearing from the folder completely HOT 12
- Permanent loading login page after one day from the first deployment also in the last version 1.0.15 HOT 2
- Installation error HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from langflow.