From 91398d3e48077c10f7f749fefb71f1732ced081b Mon Sep 17 00:00:00 2001 From: lokeshk-incresco Date: Sun, 23 Jul 2023 15:31:00 +0530 Subject: [PATCH] runtime init --- chatgptxblock/chatgptxblock.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/chatgptxblock/chatgptxblock.py b/chatgptxblock/chatgptxblock.py index 5fb4121..53a233f 100644 --- a/chatgptxblock/chatgptxblock.py +++ b/chatgptxblock/chatgptxblock.py @@ -18,6 +18,11 @@ class ChatgptXBlock(StudioEditableXBlockMixin, XBlock): # print(settings) # d_name=settings.DISPLAY_NAME # print("hi",Scope) + def api_init(self, context=None): + xblock_config = self.runtime.handler_env['xblock'].runtime.get_user_state('XBLOCK_CONFIG') + a_key = xblock_config.get('OPENAI_KEY') + print(a_key) + api_init() display_name = String( display_name="Display Name", help="Display name for this module", @@ -38,7 +43,7 @@ class ChatgptXBlock(StudioEditableXBlockMixin, XBlock): ) api_key = String( - default="njdn3bfhbi", + default=a_key, scope=Scope.settings, help="Your OpenAI API key, which can be found at https://platform.openai.com/account/api-keys", ) @@ -63,7 +68,7 @@ class ChatgptXBlock(StudioEditableXBlockMixin, XBlock): 'display_name', # 'model_name', 'api_key', - # 'description', + 'description', # 'context_text', ] @@ -99,10 +104,7 @@ def get_answer(self, data, suffix=''): # Send the user's question to the text-davinci-002 model using the OpenAI API model = "text-davinci-003" - # openai.api_key = self.api_key - xblock_config = self.runtime.handler_env['xblock'].runtime.get_user_state('XBLOCK_CONFIG') - openai.api_key = xblock_config.get('OPENAI_KEY') - print(openai.api_key) + openai.api_key = self.api_key response = openai.Completion.create( engine=model, prompt=prompt,