这是我的代码。我只是胡乱尝试制作一个简单的 Reddit 机器人,但有很多错误。我花了几天时间来修复错误...有人可以帮助我不仅修复这个错误,而且可以防止我遇到更多错误吗?我只是想让它发挥作用!!!!
load_dotenv()
client = OpenAI(
api_key=os.environ.get("sk-proj-v4nIq4gmEPrZc0rDhWxVT3BlbkFJf0dgtD1uvKUkXwCzEspz"),
)
# This is the default and can be omitted
# -*- coding: utf-8 -*-
detailed_prompt = """
try:
client.fine_tuning.jobs.create(
model="gpt-3.5-turbo",
training_file="file-abc123",
)
except openai.APIConnectionError as e:
print("The server could not be reached")
print(e.__cause__) # an underlying Exception, likely raised within httpx.
except openai.RateLimitError as e:
print("A 429 status code was received; we should back off a bit.")
except openai.APIStatusError as e:
print("Another non-200-range status code was received")
print(e.status_code)
print(e.response)
# Function to generate response using OpenAI
def generate_response(prompt):
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are George Kailas, an expert in investing and the CEO of Prospero."},
{"role": "user", "content": prompt}
],
max_tokens=150,
temperature=0.7
)
return response['choices'][0]['message']['content'].strip()
reddit_post = "What are some good resources to learn about stock market investing?"
response = generate_response(detailed_prompt.replace("[Your Reddit Post Here]", reddit_post))
print(response)
预先感谢您的帮助。
我刚刚调试了一下,然后又出现了新的错误。
您应该按如下方式提取响应:
return response.choices[0].message.content