-
Notifications
You must be signed in to change notification settings - Fork 20
/
CMD_Agent_Chat.py
39 lines (26 loc) · 1.04 KB
/
CMD_Agent_Chat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from assistant_manager.assistant_manager import OAI_Assistant
import json
#import env variables
import os
org_id = os.environ.get('ORG_ID')
api_key = os.environ.get('API_KEY')
#### Main Program ####
# Lets connect to openAI assistant Endpoints
assistant = OAI_Assistant(api_key=api_key, organization=org_id)
# Interact with the user to select an assistant
assistant_id = assistant.setup_assistant_chat()
# Interact with the user to select a thread
thread_id = assistant.user_chat_swap_Thread()
#check for messages in the thread
history = assistant.list_thread_history()
#message_user(f"History: {history}")
if history is not None:
for message in reversed(history):
assistant.message_user("------------")
data = assistant.retrieve_message(thread_id=thread_id, message_id=message)
#data.content[0].text.value
assistant.message_user(f"{data.role}: {data.content[0].text.value}")
#start the chat
assistant.message_user("------------")
assistant.message_user("Your Chat has begun")
assistant.main_run(assistant_id,thread_id)