我使用的是“text-davinci-003”模型,并且我从OpenAI的 playground 复制了代码,但每次机器人对简单的“hello”都会给出随机的回答。
这是我使用的代码:
response: dict = openai.Completion.create(model="text-davinci-003", prompt=prompt, temperature=0.9, max_tokens=150, top_p=1, frequency_penalty=0, presence_penalty=0.6, stop=[" Human:", " AI:"]) choices: dict = response.get('choices')[0] text = choices.get('text') print(text)
对简单的“hello”聊天三次的回应如下:
-
第一次它给了我一个Java的hello world程序
-
第二次它正确回答了 – ‘Hi there! How can I help you today?’
-
第三次:
def my_method puts "hello" end end end# To invoke this method we would call:MyModule::MyClass.my_method
我实在不明白,因为在OpenAI的playground中使用同样的简单‘hello’提示,每次都能得到准确的回应 – ‘Hi there! How can I help you today?’
回答:
正如官方OpenAI文档中所述:
温度(temperature)和top_p设置控制模型生成响应的确定性。如果你希望得到一个只有一个正确答案的回应,那么你应该将这些值设得更低。如果你希望得到更多样化的回应,那么你可能需要将它们设得更高。人们在使用这些设置时犯的最常见错误是认为它们是“聪明度”或“创造力”的控制器。
将这个…
temperature = 0.9
…改为这个。
temperature = 0