camel [功能请求] schemas子包以支持不同的结构化输出模式

btxsgosb  于 2个月前  发布在  其他
关注(0)|答案(1)|浏览(47)

必需的先决条件

动机

我们发现我们需要为不同的项目获取结构化输出。因此,创建一个 schemas 子包以使用常见的输出模式将很有帮助。

解决方案

  • 无响应*

替代方案

  • 无响应*

附加上下文

  • 无响应*
ha5z0ras

ha5z0ras1#

我认为使用 Function_call 来满足这个功能,我将展示一个关于如何使用 json 作为输出格式的简短示例。
用户应输入:

input_info = [
    "Determines the answer based on their beliefs, desires, intention",
    {
        "Belief": "The belief factor.", 
        "Desire": "The desire factor.",
        "Intention": "The intention factor.",
    },
]

输入中的第一个元素是模型结构输出的时间描述,第二个字典是用户在响应中需要的信息的详细信息。
为了适应 camel 中已经存在的 function call 函数。我们应该将用户的输入转换为一个函数:

def generate_text(Believe, Desire, Intention):
    """
Determines the answer based on their beliefs, desires, intention
Args:
Believe (any): The belief factor.
Desire (any): The desire factor.
Intention (any): The intention factor.
Returns:
Dict[str, Any]: A dictionary containing the model's answer with keys for Believe, Desire, Intention
"""
    model_answer = {
        "Believe": Believe,
        "Desire": Desire,
        "Intention": Intention,
    }
    return model_answer

它能够结构化模型输出的原因是因为函数的返回值是用户想要的输出。为了实现这种转换,我已经设计了一个函数,用于将用户的输入转换为这种类型的函数。
最后,我们可以使用 OpenAIFunction 类生成:

func_call = OpenAIFunction(
    func=generate_text,
)

因此,我将测试这种方法是否适合现在的代码,我还担心在仓库的哪个部分应该放我的代码。
感谢任何评论~

相关问题