From de1cc693672bd18fa8ae52c3c815c5308e586195 Mon Sep 17 00:00:00 2001 From: Jeremy Bowman Date: Tue, 24 Oct 2023 10:01:28 -0400 Subject: [PATCH] fix: Fix documentation builds Resolve import and setup issues that were causing doc builds to fail. --- docs/conf.py | 8 ++++++++ flashcards/settings/base.py | 3 +++ flashcards/utils.py | 36 +++++++++++++++++------------------- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 026cc5f..e8c6783 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -39,6 +39,14 @@ def get_version(*file_paths): VERSION = get_version('../flashcards', '__init__.py') +# Specify settings module (which will be picked up from the sandbox) +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'flashcards.settings.test') + +import django + + +django.setup() + # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. diff --git a/flashcards/settings/base.py b/flashcards/settings/base.py index c12ec6f..cd4bddb 100644 --- a/flashcards/settings/base.py +++ b/flashcards/settings/base.py @@ -241,3 +241,6 @@ def root(*path_fragments): # Set up logging for development use (logging to stdout) LOGGING = get_logger_config(debug=DEBUG) + +# OpenAI API key, to be specified in the private settings file +OPENAI_API_KEY = '' diff --git a/flashcards/utils.py b/flashcards/utils.py index f4b912f..82f2722 100644 --- a/flashcards/utils.py +++ b/flashcards/utils.py @@ -6,10 +6,9 @@ """ import openai +from django.conf import settings -from flashcards.settings.private import OPENAI_API_KEY # pylint: disable=import-error,no-name-in-module - -openai.api_key = OPENAI_API_KEY +openai.api_key = settings.OPENAI_API_KEY content_prompt = """ @@ -181,19 +180,18 @@ "content": content_prompt + course_content}, ] - -c3 = openai.ChatCompletion.create( - model="gpt-3.5-turbo", - messages=messages, - temperature=1.0, -) - -print(c3['choices'][0]['message']['content']) - -# c4 = openai.ChatCompletion.create( -# model="gpt-4", -# messages=messages, -# temperature=1.0, -# ) - -# print(c4) +if openai.api_key: + c3 = openai.ChatCompletion.create( + model="gpt-3.5-turbo", + messages=messages, + temperature=1.0, + ) + print(c3['choices'][0]['message']['content']) + + # c4 = openai.ChatCompletion.create( + # model="gpt-4", + # messages=messages, + # temperature=1.0, + # ) + + # print(c4)