类方法中无法将self.client设为默认参数的问题求助
类方法中无法将self.client设为默认参数的问题求助
我有一个类和方法,尝试把self.instance_variable作为默认参数传递,但一直做不到。我举个例子说明:
from openai import OpenAI class Example_class: def __init__(self) -> None: self.client = OpenAI(api_key='xyz') self.client2 = OpenAI(api_key='abc') def chat_completion(self, prompt, context, client=self.client, model='gpt-4o'): # Process the prompt messages = [{"role": "system", "content": context}, {"role": "user", "content": prompt}] response = client.chat.completions.create( model=model, messages=messages, temperature=0.35, # this is the degree of randomness of the model's output ) return response.choices[0].message.content def do_something(self): self.chat_completion(prompt="blah blah blah", context="fgasa")
你看,在尝试把self.client传入chat_completion方法时出现了错误,我哪里出错了?
备注:内容来源于stack exchange,提问作者Legion
相关产品推荐
相关产品推荐

