如何获得开放的AI API返回部分文本结果?



我使用Python Open AI API自动给出单词的定义并返回文本结果,但它给出了太多的文本。

response = openai.Completion.create(
model="text-davinci-003",
prompt="give a definition for "+str(definition),
temperature=0.7,
max_tokens=50,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
print( str(response['choices'][0]['text']))

但是,它会返回如下内容:

1. Definition: A statement that explains the meaning of a word or phrase.
2. High-definition Television: A type of television system that provides a much higher resolution than a standard-definition television.
3. Standard

它给了我太多的文字;我怎样才能把范围缩小到只给出第一个结果?

你可以使用" few shot learning ";通过使用较长的提示符来训练你的模型,提示符给出你想要的示例。下面是一个快速粗略提示符的示例,它将获取定义。

这个返回的结果可能比您想要的长一点,因为我使用了枚举所有定义的示例。所以它给出了更长的列表——你可以调整这个基本方法来得到你想要的。我很快就把它拼好了。

示例提示实现少镜头学习:

I am going to ask you for a definition of a word.
Here is an example of a definition for the word "tree":
noun
1. a woody perennial plant; 2.a wooden structure or part of a structure.
verb
1. force (a hunted animal) to take refuge in a tree.
Here is an example of a definition for the word "plasma":
noun 
1.the colourless fluid part of blood, lymph, or milk; 2. an ionized gas consisting of positive ions and free electrons 3. a bright green, translucent variety of quartz 4. another term for cytoplasm or protoplasm.

Here is an example of a definition for the word "there":
adverb
1. in, at, or to that place or position. 2. used in attracting someones attention or calling attention to someone or something.
exclamation
1. used to focus attention on something. 2. used to comfort someone.
[more examples here]
Here is a definition for the word "[the word you want defined]":

最新更新