mrwadams commited on
Commit
cbcb2f2
β€’
1 Parent(s): 139a920

Fixed import of environment variable

Browse files
Files changed (1) hide show
  1. app.py +17 -20
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from typing import Dict, Optional, Union
2
 
3
  import chainlit as cl
@@ -42,6 +43,13 @@ CONTEXT = """- Task: PoliGen specialises in creating high-quality and detailed c
42
  USER_PROXY_NAME = "User Proxy"
43
  REVIEWER = "Reviewer"
44
  WRITER = "Technical Writer"
 
 
 
 
 
 
 
45
 
46
  async def ask_helper(func, **kwargs):
47
  res = await func(**kwargs).send()
@@ -121,15 +129,6 @@ class ChainlitUserProxyAgent(UserProxyAgent):
121
  )
122
 
123
 
124
-
125
- config_list = [
126
- {
127
- "model": "gpt-4-turbo-preview",
128
- },
129
- ]
130
-
131
-
132
-
133
  @cl.action_callback("confirm_action")
134
  async def on_action(action: cl.Action):
135
  if action.value == "everything":
@@ -150,15 +149,14 @@ async def on_action(action: cl.Action):
150
 
151
  @cl.on_chat_start
152
  async def start():
153
- # OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
154
- OPENAI_API_KEY = cl.user_session.get("OPENAI_API_KEY")
155
-
 
156
 
157
  try:
158
- # app_user = cl.user_session.get("user")
159
- # await cl.Message(f"Hello {app_user.username}").send()
160
- # config_list = config_list_from_json(env_or_file="OAI_CONFIG_LIST")
161
- llm_config = {"config_list": config_list, "api_key": OPENAI_API_KEY, "seed": 42, "request_timeout": 120, "retry_wait_time": 10}
162
  reviewer = ChainlitAssistantAgent(
163
  name="Reviewer", llm_config=llm_config,
164
  system_message="""Reviewer. Reviews the policy document, focuses on the structure and clarity of the content.
@@ -187,9 +185,7 @@ Structures content with effective subheadings and bullet points to facilitate re
187
  cl.user_session.set(REVIEWER, reviewer)
188
  cl.user_session.set(WRITER, writer)
189
 
190
- msg = cl.Message(content=f"""Hi, this is the PoliGen agent team πŸ€–. Please specify a cybersecurity domain for us to write a policy about (e.g. Data Classification, Remote Access).""",
191
- disable_human_feedback=True,
192
- author="User_Proxy")
193
  await msg.send()
194
 
195
  except Exception as e:
@@ -198,6 +194,7 @@ Structures content with effective subheadings and bullet points to facilitate re
198
 
199
  @cl.on_message
200
  async def run_conversation(message: cl.Message):
 
201
  #try:
202
  MESSAGE = message.content
203
  print("Task: ", MESSAGE)
@@ -206,7 +203,7 @@ async def run_conversation(message: cl.Message):
206
  writer = cl.user_session.get(WRITER)
207
 
208
  groupchat = autogen.GroupChat(agents=[user_proxy, reviewer, writer], messages=[], max_round=10)
209
- manager = autogen.GroupChatManager(groupchat=groupchat)
210
 
211
  print("Initiated GC messages... \nGC messages length: ", len(groupchat.messages))
212
 
 
1
+ import os
2
  from typing import Dict, Optional, Union
3
 
4
  import chainlit as cl
 
43
  USER_PROXY_NAME = "User Proxy"
44
  REVIEWER = "Reviewer"
45
  WRITER = "Technical Writer"
46
+
47
+ # Config list for AutoGen
48
+ config_list = [
49
+ {
50
+ "model": "gpt-4-turbo-preview",
51
+ },
52
+ ]
53
 
54
  async def ask_helper(func, **kwargs):
55
  res = await func(**kwargs).send()
 
129
  )
130
 
131
 
 
 
 
 
 
 
 
 
 
132
  @cl.action_callback("confirm_action")
133
  async def on_action(action: cl.Action):
134
  if action.value == "everything":
 
149
 
150
  @cl.on_chat_start
151
  async def start():
152
+ # Retrieve the 'env' dictionary from the user session
153
+ env_variables = cl.user_session.get("env")
154
+ # Set OPENAI_API_KEY environment variable
155
+ os.environ["OPENAI_API_KEY"] = env_variables.get("OPENAI_API_KEY")
156
 
157
  try:
158
+ llm_config = {"config_list": config_list, "seed": 42}
159
+
 
 
160
  reviewer = ChainlitAssistantAgent(
161
  name="Reviewer", llm_config=llm_config,
162
  system_message="""Reviewer. Reviews the policy document, focuses on the structure and clarity of the content.
 
185
  cl.user_session.set(REVIEWER, reviewer)
186
  cl.user_session.set(WRITER, writer)
187
 
188
+ msg = cl.Message(content=f"""Hi, this is the PoliGen agent team πŸ€–. Please specify a cybersecurity domain for us to write a policy about (e.g. Data Classification, Remote Access).""", author="User_Proxy")
 
 
189
  await msg.send()
190
 
191
  except Exception as e:
 
194
 
195
  @cl.on_message
196
  async def run_conversation(message: cl.Message):
197
+ llm_config = {"config_list": config_list, "seed": 42}
198
  #try:
199
  MESSAGE = message.content
200
  print("Task: ", MESSAGE)
 
203
  writer = cl.user_session.get(WRITER)
204
 
205
  groupchat = autogen.GroupChat(agents=[user_proxy, reviewer, writer], messages=[], max_round=10)
206
+ manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config)
207
 
208
  print("Initiated GC messages... \nGC messages length: ", len(groupchat.messages))
209