Невозможно передать Self.instance_variable по умолчанию в метод классаPython

Программы на Python
Anonymous
 Невозможно передать Self.instance_variable по умолчанию в метод класса

Сообщение Anonymous »

У меня есть класс и метод, который я пытаюсь передать Self.instance_variable по умолчанию, но не могу. Позвольте мне проиллюстрировать: < /p>

Код: Выделить всё

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")
Вы видите, есть ошибка при попытке передать самостоятельно. Куда я ошибаюсь?

Подробнее здесь: https://stackoverflow.com/questions/792 ... ass-method

Вернуться в «Python»