grimzaeye commited on
Commit
e924133
·
verified ·
1 Parent(s): a578fa7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -17,7 +17,8 @@ from openai import OpenAI
17
  model_name ="gpt-4o"
18
  agent_name = "schedule_agent_0612"
19
 
20
- OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
 
21
  global client
22
 
23
  #client 생성
@@ -37,7 +38,7 @@ def get_agent_instructions(character):
37
  You are a humourous friendly assistant '마음이' to me. You talk to me as a friend do. 너는 다정하고 상냥한, 공감하는, 격려하는 스타일이어서 만약 내가 힘들거나 하기 싫다고 하는 일이 있으면, 업무나 일에 관한 게 아니면 내 기분에 맞춰서 일정을 조정해줘. 답변은 한글로 해줘.
38
  """
39
 
40
- if character == "strict_charactor":
41
  character_prompt = strict_character_prompt
42
  else:
43
  character_prompt = friendly_character_prompt
@@ -269,10 +270,13 @@ def get_agent_tools():
269
 
270
  # 기존 Assistant 가져오거나 수정하거나 생성하기
271
  def create_or_update_assistant(client, agent_name, model_name, character):
272
- if character == "strict_charactor":
273
  agent_name = "schedule_agent_strict"
274
- else:
275
  agent_name = "schedule_agent_friendly"
 
 
 
276
 
277
  # 모든 Assistants 가져오기
278
  assistants = client.beta.assistants.list()
@@ -350,7 +354,7 @@ def check_run_status(client, thread_id, run_id, calendar_service):
350
 
351
 
352
  def start_chat_friendly(user_input, chat_history):
353
-
354
  if user_input == "":
355
  return "", chat_history
356
  else:
@@ -387,7 +391,7 @@ def start_chat_friendly(user_input, chat_history):
387
  return "", chat_history
388
 
389
  def start_chat_strict(user_input, chat_history):
390
-
391
  if user_input == "":
392
  return "", chat_history
393
  else:
@@ -474,12 +478,13 @@ class CalendarService:
474
  creds.refresh(Request())
475
  else:
476
  flow = InstalledAppFlow.from_client_secrets_file(
477
- "credentials.json", self.SCOPES
478
  )
479
  creds = flow.run_local_server(port=0)
480
  # Save the credentials for the next run
481
  with open("token.json", "w") as token:
482
  token.write(creds.to_json())
 
483
  return build('calendar', 'v3', credentials=creds)
484
  except Exception as e:
485
  print(f"Error in getting calendar service: {e}")
@@ -590,8 +595,8 @@ global calendar_service
590
  calendar_service = CalendarService('primary')
591
 
592
  ### 캐릭터별 Assistant 생성
593
- assistant_strict = create_or_update_assistant(client, agent_name, model_name, "strict_charactor")
594
- assistant_friendly = create_or_update_assistant(client, agent_name, model_name, "friendly_charactor")
595
 
596
  ### 전역 변수로 쓰레드 ID, assistant ID 저장
597
  global thread
@@ -641,11 +646,11 @@ with gr.Blocks() as app:
641
  reset_btn.click(fn=chat_reset, inputs=[user_input, chat_history], outputs=[user_input, chat_history])
642
  return chat_history, user_input, cb_send_btn, reset_btn
643
  with gr.Tab("Friendly"):
644
- character = "friendly_charactor"
645
  chat_ui_friendly()
646
 
647
  with gr.Tab("Strict"):
648
- character = "strict_charactor"
649
  chat_ui_strict()
650
 
651
 
 
17
  model_name ="gpt-4o"
18
  agent_name = "schedule_agent_0612"
19
 
20
+ # OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
21
+ OPENAI_API_KEY = "sk-proj-zs3NasBIrzl4OciorQkhT3BlbkFJlxVU2LfviJKAOlyalys7"
22
  global client
23
 
24
  #client 생성
 
38
  You are a humourous friendly assistant '마음이' to me. You talk to me as a friend do. 너는 다정하고 상냥한, 공감하는, 격려하는 스타일이어서 만약 내가 힘들거나 하기 싫다고 하는 일이 있으면, 업무나 일에 관한 게 아니면 내 기분에 맞춰서 일정을 조정해줘. 답변은 한글로 해줘.
39
  """
40
 
41
+ if character == "strict_character":
42
  character_prompt = strict_character_prompt
43
  else:
44
  character_prompt = friendly_character_prompt
 
270
 
271
  # 기존 Assistant 가져오거나 수정하거나 생성하기
272
  def create_or_update_assistant(client, agent_name, model_name, character):
273
+ if character == "strict_character":
274
  agent_name = "schedule_agent_strict"
275
+ elif character == "friendly_character":
276
  agent_name = "schedule_agent_friendly"
277
+ else:
278
+ print("Character Name Error")
279
+ return None
280
 
281
  # 모든 Assistants 가져오기
282
  assistants = client.beta.assistants.list()
 
354
 
355
 
356
  def start_chat_friendly(user_input, chat_history):
357
+ print("character : Friendly")
358
  if user_input == "":
359
  return "", chat_history
360
  else:
 
391
  return "", chat_history
392
 
393
  def start_chat_strict(user_input, chat_history):
394
+ pring("Character: Strict")
395
  if user_input == "":
396
  return "", chat_history
397
  else:
 
478
  creds.refresh(Request())
479
  else:
480
  flow = InstalledAppFlow.from_client_secrets_file(
481
+ "/Users/semikwon/workplace/2024 TrynGo/Tryngo_Agent/credentials.json", self.SCOPES
482
  )
483
  creds = flow.run_local_server(port=0)
484
  # Save the credentials for the next run
485
  with open("token.json", "w") as token:
486
  token.write(creds.to_json())
487
+ print('calendar service is created')
488
  return build('calendar', 'v3', credentials=creds)
489
  except Exception as e:
490
  print(f"Error in getting calendar service: {e}")
 
595
  calendar_service = CalendarService('primary')
596
 
597
  ### 캐릭터별 Assistant 생성
598
+ assistant_strict = create_or_update_assistant(client, agent_name, model_name, "strict_character")
599
+ assistant_friendly = create_or_update_assistant(client, agent_name, model_name, "friendly_character")
600
 
601
  ### 전역 변수로 쓰레드 ID, assistant ID 저장
602
  global thread
 
646
  reset_btn.click(fn=chat_reset, inputs=[user_input, chat_history], outputs=[user_input, chat_history])
647
  return chat_history, user_input, cb_send_btn, reset_btn
648
  with gr.Tab("Friendly"):
649
+ character = "friendly_character"
650
  chat_ui_friendly()
651
 
652
  with gr.Tab("Strict"):
653
+ character = "strict_character"
654
  chat_ui_strict()
655
 
656