Sar*_*rah 6 openai-api langchain
我正在尝试将 langchain 与 gpt-35-turbo 一起使用。根据链接了解如何使用 ChatGPT 和 GPT-4 模型(预览),新的 gpt3.5 Turbo 似乎不再使用某些参数
以下参数不适用于新的 ChatGPT 和 GPT-4 型号:
logprobs、best_of和echo。如果您设置任何这些参数,您将收到错误消息。
现在,每次我使用 gpt-3.5-turbo 通过 langchain 初始化 LLM 模型时,都会出现以下错误:
InvalidRequestError: logprobs, best_of and echo parameters are not available on gpt-35-turbo model. Please remove the parameter and try again. For more details, see https://go.microsoft.com/fwlink/?linkid=2227346.
Run Code Online (Sandbox Code Playgroud)
我不知道如何在 langchain 中“取消设置”这些参数。
这是我的代码:
InvalidRequestError: logprobs, best_of and echo parameters are not available on gpt-35-turbo model. Please remove the parameter and try again. For more details, see https://go.microsoft.com/fwlink/?linkid=2227346.
Run Code Online (Sandbox Code Playgroud)
请注意,我在 Azure 中使用 openAI,我也尝试了这段代码,但它仍然给我同样的错误
deployment_name = "my-deployment-name"
from langchain.llms import AzureOpenAI
llm = AzureOpenAI(deployment_name=deployment_name )
print(llm)
llm("Tell me a joke")
Run Code Online (Sandbox Code Playgroud)
因此,我终于能够通过创建 AzureOpenai 类的扩展并取消这些参数来修复它。有效的代码如下:
from langchain.llms import AzureOpenAI
from typing import List
class NewAzureOpenAI(AzureOpenAI):
stop: List[str] = None
@property
def _invocation_params(self):
params = super()._invocation_params
# fix InvalidRequestError: logprobs, best_of and echo parameters are not available on gpt-35-turbo model.
params.pop('logprobs', None)
params.pop('best_of', None)
params.pop('echo', None)
#params['stop'] = self.stop
return params
llm = NewAzureOpenAI(deployment_name=deployment_name,temperature=0.9)
llm("Tell me a joke")
Run Code Online (Sandbox Code Playgroud)
实际上可以在此链接中找到答案,并且它对我有用。
| 归档时间: |
|
| 查看次数: |
5480 次 |
| 最近记录: |