Skip to content

Commit 90c8f63

Browse files
committed
Make adjustments to API Frame methods
Add method for setting the API key and make some adjustments to other methods. This method for saving the API key does not work. I will likely have to go back to storing the key in a file to be read by the program. I was trying to export it to the environment variables but it just doesn't work.
1 parent c1a05a9 commit 90c8f63

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

openaiclient/view/frame/apiframe.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import tkinter as tk
66
from tkinter import ttk
77
import webbrowser
8+
import os
9+
import openai
810
from openaiclient.view.frame import BaseFrame
911
from tests.unit.fixture import api
1012

@@ -17,6 +19,8 @@ class APIFrame(BaseFrame):
1719

1820
def __init__(self, main, controller):
1921
super().__init__(main, controller)
22+
23+
self._api_key = tk.StringVar()
2024

2125
def create(self):
2226
col = Increment()
@@ -67,7 +71,7 @@ def create(self):
6771
tempFrame2,
6872
text="Get API Key",
6973
font=("", 10, ""),
70-
command=self.setAPI
74+
command=self.getAPI
7175
).grid(
7276
column=tempCol,
7377
row=tempRow,
@@ -115,7 +119,8 @@ def create(self):
115119

116120
tk.Entry(
117121
self,
118-
width=30
122+
width=30,
123+
textvariable=self._api_key
119124
).grid(
120125
column=col,
121126
row=row,
@@ -130,7 +135,8 @@ def create(self):
130135
self,
131136
text="Save API Key",
132137
font=("", 10, ""),
133-
width=30
138+
width=30,
139+
command=self.setAPIKey
134140
).grid(
135141
column=col,
136142
row=row,
@@ -156,13 +162,20 @@ def addHorizSeparator(self, col, row, frame):
156162

157163
+row
158164

159-
def setAPI(self):
165+
def getAPI(self):
160166
api_url = "https://platform.openai.com/account/api-keys"
161167
webbrowser.open(api_url)
162168

163169
def setTestAPI(self):
164170
self.controller._api = api
165171
self.master.destroy()
172+
173+
def setAPIKey(self):
174+
self.controller._module = openai
175+
self.controller._module.api_key = \
176+
os.environ['OPENAI_API_KEY'] = self._api_key.get()
177+
178+
self.master.destroy()
166179

167180

168181
instruction="""

0 commit comments

Comments
 (0)