【问题标题】:How to get Open AI API to return part of the text result?如何让Open AI API返回部分文本结果?
【发布时间】:2022-12-21 03:09:34
【问题描述】:

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

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

【问题讨论】:

    标签: python api printing artificial-intelligence openai


    【解决方案1】:

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

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

    实施少样本学习的示例提示:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-30
      • 2021-12-28
      • 1970-01-01
      相关资源
      最近更新 更多