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

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

必需的先决条件

动机

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

解决方案

  • 无响应*

替代方案

  • 无响应*

附加上下文

  • 无响应*
ha5z0ras

ha5z0ras1#

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

  1. input_info = [
  2. "Determines the answer based on their beliefs, desires, intention",
  3. {
  4. "Belief": "The belief factor.",
  5. "Desire": "The desire factor.",
  6. "Intention": "The intention factor.",
  7. },
  8. ]

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

  1. def generate_text(Believe, Desire, Intention):
  2. """
  3. Determines the answer based on their beliefs, desires, intention
  4. Args:
  5. Believe (any): The belief factor.
  6. Desire (any): The desire factor.
  7. Intention (any): The intention factor.
  8. Returns:
  9. Dict[str, Any]: A dictionary containing the model's answer with keys for Believe, Desire, Intention
  10. """
  11. model_answer = {
  12. "Believe": Believe,
  13. "Desire": Desire,
  14. "Intention": Intention,
  15. }
  16. return model_answer

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

  1. func_call = OpenAIFunction(
  2. func=generate_text,
  3. )

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

展开查看全部

相关问题