Skip to content

Commit

Permalink
runtime init
Browse files Browse the repository at this point in the history
  • Loading branch information
lokeshk-18 committed Jul 23, 2023
1 parent b27694c commit 91398d3
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions chatgptxblock/chatgptxblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 <a href='https://platform.openai.com/account/api-keys' target='_blank'>https://platform.openai.com/account/api-keys</a>",
)
Expand All @@ -63,7 +68,7 @@ class ChatgptXBlock(StudioEditableXBlockMixin, XBlock):
'display_name',
# 'model_name',
'api_key',
# 'description',
'description',
# 'context_text',
]

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 91398d3

Please sign in to comment.