promptflow [功能请求]使流程输出json转储可配置,以允许对象作为输出

ttcibm8c  于 2个月前  发布在  其他
关注(0)|答案(4)|浏览(56)

您的功能请求是否与问题相关?请描述。

我想为Python工具返回一个类作为输出,但是它显示错误:JSON转储失败。例如,对于以下代码,它将返回错误:


![](//img.saoniuhuo.com/images/202407/68611722148931604.jpg)

@dataclass
class ThoughtStep:
title: str
description: Optional[Any]
props: Optional[dict[str, Any]] = None

The inputs section will change based on the arguments of the tool function, after you save the code

Adding type to arguments and return value will help the system show the types properly

Please update the function name/signature per need

@tool
def my_python_tool(zone_instruction: str, modify_query:str, answer_question:str) -> list:
thought_steps = [
ThoughtStep(title="Look up Zone Instruction", description=zone_instruction, props=None),
ThoughtStep(title="Modify the query with history and zone instruction", description=modify_query, props=None),
ThoughtStep(title="Search relevant documentation", description=None, props=None),
ThoughtStep(title="Answer the questions", description=answer_question, props=None)
]
return thought_steps

描述您希望的解决方案

允许选项注入如何序列化复杂对象

描述您考虑过的替代方案

我目前的解决方法是在Python工具中手动使用jsonoutput = json.dumps(thought_steps, default=lambda o: o.**dict**),并返回一个字符串。

附加上下文

如果需要,我很乐意进一步详细解释。

pbwdgjma

pbwdgjma1#

对我来说,这也非常有用。在我们的项目迁移到Azure AI Studio之前,我们使用的是Instructor包,它使用pydantic来验证输出,几乎是完美的解决方案。我愿意为此做出贡献,以增强功能。

scyqe7ek

scyqe7ek2#

@duongthaiha,
感谢你的反馈,我想确认一下,你是想在流程中传递一个自定义对象(从一个节点到另一个节点)吗?如果是这样的话,你可以参考Function based flow — Prompt flow documentation,使用这种流程,你可以在流程中传递任何对象,实际上已经没有节点的概念了,也没有有向无环图(DAG)。
如果你仍然想使用DAG流程并像你的示例代码那样为节点(或流程输出)返回一个自定义对象,那么我们需要为这个功能进行全面的设计,实现这个功能可能是一个长期的任务。
@ferBV,
感谢你的评论,非常感谢。你能提供一个更详细的设计方案吗?也许是一个文档或者其他什么?我们希望社区能够为prompt flow项目做出贡献。

mctunoxg

mctunoxg3#

是的,这是个好主意。请继续。这将是一个很棒的功能,因为它可以扩展很多使用场景。

yvgpqqbh

yvgpqqbh4#

你好@duongthaiha,感谢你的反馈。我们的团队目前没有足够的带宽,我会将这个问题标记为长期项目,一旦我们有足够的带宽,就会处理这个问题。谢谢。

相关问题