我们发现我们需要为不同的项目获取结构化输出。因此,创建一个 schemas 子包以使用常见的输出模式将很有帮助。
schemas
ha5z0ras1#
我认为使用 Function_call 来满足这个功能,我将展示一个关于如何使用 json 作为输出格式的简短示例。用户应输入:
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.", },]
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 函数。我们应该将用户的输入转换为一个函数:
camel
function call
def generate_text(Believe, Desire, Intention): """Determines the answer based on their beliefs, desires, intentionArgs: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
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 类生成:
OpenAIFunction
func_call = OpenAIFunction( func=generate_text,)
func_call = OpenAIFunction(
func=generate_text,
)
因此,我将测试这种方法是否适合现在的代码,我还担心在仓库的哪个部分应该放我的代码。感谢任何评论~
1条答案
按热度按时间ha5z0ras1#
我认为使用
Function_call
来满足这个功能,我将展示一个关于如何使用json
作为输出格式的简短示例。用户应输入:
输入中的第一个元素是模型结构输出的时间描述,第二个字典是用户在响应中需要的信息的详细信息。
为了适应
camel
中已经存在的function call
函数。我们应该将用户的输入转换为一个函数:它能够结构化模型输出的原因是因为函数的返回值是用户想要的输出。为了实现这种转换,我已经设计了一个函数,用于将用户的输入转换为这种类型的函数。
最后,我们可以使用
OpenAIFunction
类生成:因此,我将测试这种方法是否适合现在的代码,我还担心在仓库的哪个部分应该放我的代码。
感谢任何评论~