ChatGPTのmodel変更の追加

pull/6/head
NON906 2023-08-05 12:01:05 +09:00
parent bb14408db2
commit d791f47e1e
3 changed files with 27 additions and 4 deletions

View File

@ -24,14 +24,20 @@ class ChatGptApi:
"required": ["prompt"],
},
}]
model = 'gpt-3.5-turbo'
def __init__(self, apikey=None):
def __init__(self, model=None, apikey=None):
if model is not None:
self.change_model(model)
if apikey is not None:
self.change_apikey(apikey)
def change_apikey(self, apikey):
openai.api_key = apikey
def change_model(self, model):
self.model = model
def load_log(self, log):
if log is None:
return False
@ -61,7 +67,7 @@ class ChatGptApi:
return None
self.chatgpt_messages.append({"role": "user", "content": content})
self.chatgpt_response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
model=self.model,
messages=self.chatgpt_messages,
functions=self.chatgpt_functions
)

View File

@ -56,10 +56,14 @@ def on_ui_tabs():
with open(os.path.join(os.path.dirname(__file__), '..', 'settings', 'chatgpt_api.txt')) as f:
apikey = f.read()
chatgpt_settings = None
with open(os.path.join(os.path.dirname(__file__), '..', 'settings', 'chatgpt_settings.json')) as f:
chatgpt_settings = json.load(f)
if apikey is None or apikey == '':
chat_gpt_api = chatgptapi.ChatGptApi()
chat_gpt_api = chatgptapi.ChatGptApi(chatgpt_settings['model'])
else:
chat_gpt_api = chatgptapi.ChatGptApi(apikey)
chat_gpt_api = chatgptapi.ChatGptApi(chatgpt_settings['model'], apikey)
def chatgpt_txt2img(request_prompt: str):
txt2img_params = copy.deepcopy(txt2img_params_base)
@ -199,6 +203,16 @@ def on_ui_tabs():
f.write(setting_api)
chat_gpt_api.change_apikey(setting_api)
btn_apikey_save.click(fn=apikey_save, inputs=txt_apikey)
with gr.Row():
txt_chatgpt_model = gr.Textbox(value=chatgpt_settings['model'], label='ChatGPT Model Name')
btn_chatgpt_model_save = gr.Button(value='Save And Reflect', variant='primary')
def chatgpt_model_save(setting_model: str):
global chat_gpt_api, chatgpt_settings
chatgpt_settings['model'] = setting_model
with open(os.path.join(os.path.dirname(__file__), '..', 'settings', 'chatgpt_settings.json'), 'w') as f:
json.dump(chatgpt_settings, f)
chat_gpt_api.change_model(setting_model)
btn_chatgpt_model_save.click(fn=chatgpt_model_save, inputs=txt_chatgpt_model)
with gr.Row():
lines = txt2img_params_json.count('\n') + 1
txt_json_settings = gr.Textbox(value=txt2img_params_json, lines=lines, max_lines=lines + 5)

View File

@ -0,0 +1,3 @@
{
"model": "gpt-3.5-turbo"
}