gpt4 book ai didi

python - 如何让Open AI API返回部分文本结果?

转载 作者:行者123 更新时间:2023-12-02 05:47:51 27 4
gpt4 key购买 nike

我正在使用 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

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

最佳答案

您可以使用“小样本学习”来训练您的模型,方法是使用更长的提示来提供您想要的示例。下面是一个将获取定义的快速粗略提示的示例。

这个返回的结果可能比您想要的要长一点,因为我使用了枚举所有定义的示例。所以它提供了更长的列表——您可以调整这个基本方法来获得您想要的。我很快就把它们组合在一起了。

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

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]":

关于python - 如何让Open AI API返回部分文本结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74719196/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com