import time
import openai
def call_api_with_retry(max_retries=5):
retries = 0
while retries < max_retries:
try:
response = openai.Completion.create(model="text-davinci-003", prompt="Hello!")
return response
except (openai.error.Timeout, openai.error.APIConnectionError) as e:
retries += 1
print(f"Network error: {e}. Retrying ({retries}/{max_retries})...")
time.sleep(2) # 2초 대기 후 재시도
raise Exception("API 호출이 실패하였다.")
import openai
response = openai.Completion.create(
model="text-davinci-003",
prompt="Hello!",
timeout=10 # 10초 내에 응답이 없으면 타임아웃 발생
)
response = openai.Completion.create(
model="text-davinci-003",
prompt="This is a test",
max_tokens=150 # 허용된 범위 내에서 설정
)
response = openai.Completion.create(
model="text-davinci-003",
prompt="Explain the theory of relativity.",
max_tokens=300 # 더 긴 응답을 원할 경우 이 값을 늘린다.
)
response = openai.Completion.create(
model="text-davinci-003",
prompt="Summarize the key points of the given text.",
max_tokens=100 # 응답 길이를 제한
)
response = openai.Completion.create(
model="text-davinci-003",
prompt="What is this?"
)
response = openai.Completion.create(
model="text-davinci-003",
prompt="Explain the process of photosynthesis in simple terms."
)
response = openai.Completion.create(
model="text-davinci-003",
prompt="What is the capital of France?",
temperature=0 # 창의성을 줄이고 더 일관된 답변을 기대
)
response = openai.Completion.create(
model="gpt-3.5-turbo", # 더 경량화된 모델 사용
prompt="Explain the benefits of renewable energy."
)
response = openai.Completion.create(
model="text-davinci-003", # 정확한 모델 이름 사용
prompt="What is the meaning of life?"
)
response = openai.Completion.create(
model="text-davinci-003",
prompt="Describe the major historical events of the 20th century.",
max_tokens=200 # 응답 길이 제한
)
prompt = "Summarize the previous conversation: " + previous_summary
response = openai.Completion.create(
model="text-davinci-003",
prompt="Write a Python function to add two numbers.\n```python\n"
)