# 응답의 content가 문자열인 경우 JSON인지 판별 if isinstance(response.content, str): try: # JSON 파싱 시도 data = json.loads(response.content) # JSON 구조일 경우 content 필드 출력 print("\n GPT-4o 응답:\n" + data["content"]) except json.JSONDecodeError: # 그냥 텍스트일 경우 그대로 출력 print("\n GPT-4o 응답:\n" + response.content) # content가 dict 타입이면 content 필드 추출 elif isinstance(response.content, dict): print("\n GPT-4o 응답:\n" + response.content.get("content", str(response.content))) else: # 그 외 타입은 문자열로 변환하여 출력 print("\n GPT-4o 응답:\n" + str(response.content)) except Exception as e: # 예외 발생 시 메시지 출력 print(f"오류 발생: {e}") # main() 비동기 함수 실행 if __name__ == "__main__": asyncio.run(main())