将聊天回复适配到GPT API中的列表中。

huangapple go评论92阅读模式
英文:

Fit the chat response into a list in GPT API

问题

我试图使用ChatGPT API来获取文本中的情感。

def infer_feeling(text):
    prompt = f"以下文本中包含的情感是什么?\n文本:{text}\n情感:"

    response = openai.ChatCompletion.create(
        model=model,
        messages=[
            {"role": "system", "content": "您是一个有用的助手。"},
            {"role": "user", "content": prompt}
        ]
    )

    reply = response.choices[0].message['content']


emotions = ["幸福", "悲伤", "愤怒", "恐惧", "信任", "好奇", "希望", "绝望"]

我想要的是将回复作为数组元素(情感)获得。是否可以将GPT的回复与此数组的元素匹配?我希望它只返回与该数组中最匹配的情感,没有其他内容。

提前感谢您的任何帮助。

英文:

I'm trying to get the emotion in a text using chatgpt API

def infer_feeling(text):
    prompt = f"What feeling is filled in the following text?\nText: {text}\nFeeling:"

    response = openai.ChatCompletion.create(
        model=model,
        messages=[
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": prompt}
        ]
    )

    reply = response.choices[0].message['content']


emotions = ["happiness", "sadness", "anger", "fear", "trust", "curiosity", "hope", "despair"]

What I want is getting the reply as an array element (emotions). Is it possible to match the response of gpt to the element of this array? I want it to return the best matching emotion in that array, and nothing else.

Thanks in advance for any help

答案1

得分: 1

看起来你想要做类似这样的事情,因为你希望GPT从给定的几个选项中选择一个:

https://community.openai.com/t/gpt-function-calling-function-params-enum/281946

我不是专家,但我个人会定义一个函数调用,并在参数描述中使用提示工程来强调参数必须是这些选项之一("happiness","sadness","anger",...),哪个最合适。

英文:

It looks like you are trying to do something like this, since you want GPT to choose one out of several given options:
https://community.openai.com/t/gpt-function-calling-function-params-enum/281946

I am not an expert, but personally I would define a function call and use prompt engineering in the parameter description to stress that the parameter must be one of these options ("happiness", "sadness", "anger", ...), whichever fits best.

huangapple
  • 本文由 发表于 2023年7月7日 00:43:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76630950.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定