cmagganas commited on
Commit
9e2d22b
·
verified ·
1 Parent(s): 4ba5753

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -26
app.py CHANGED
@@ -1,8 +1,16 @@
1
  import chainlit as cl
2
  from pydantic import BaseModel, Field
 
3
  import instructor
4
  from openai import OpenAI
5
  import os
 
 
 
 
 
 
 
6
 
7
  # Patch the OpenAI client with Instructor
8
  client = instructor.from_openai(OpenAI(api_key=os.environ['OPENAI_API_KEY']))
@@ -48,41 +56,45 @@ def revise_architecture(proposed_architecture: str) -> PropositionWithRevision:
48
  ],
49
  )
50
 
51
-
52
  # Define the Chainlit message handler
53
  @cl.on_message
54
  async def main(message: cl.Message):
 
 
55
 
56
- user_proposal = message.content
57
-
58
- user_proposal_details = extract_user_proposal_details(user_proposal)
59
-
60
- proposed_architecture = generate_proposed_architecture(user_proposal_details.proposal)
61
-
62
- await cl.Message(
63
- content=f"Proposed Architecture:\n{proposed_architecture.proposed_architecture}"
64
- ).send()
65
-
66
- feedback_message = await cl.AskUserMessage(content="What do you think about this proposed plan and alleged architecture?", timeout=60).send()
67
- if feedback_message:
68
- human_feedback_of_proposed_plan = feedback_message["output"]
69
-
70
- revised_architecture = revise_architecture(proposed_architecture.proposed_architecture)
71
-
72
  await cl.Message(
73
- content=f"Revised Architecture:\n{revised_architecture.revised_proposed_architecture}"
74
  ).send()
75
 
76
- with open("output.md", "w") as output_file:
77
- output_file.write("# User Proposal\n")
78
- output_file.write(user_proposal_details.proposal + "\n\n")
79
- output_file.write("# Proposed Architecture\n")
80
- output_file.write(proposed_architecture.proposed_architecture + "\n\n")
81
- output_file.write("# Revised Architecture\n")
82
- output_file.write(revised_architecture.revised_proposed_architecture + "\n")
 
 
 
 
 
 
 
 
 
 
83
 
 
 
 
 
 
84
  await cl.Message(
85
- content="The results have been saved to output.md"
86
  ).send()
87
 
88
  # Load the starters
 
1
  import chainlit as cl
2
  from pydantic import BaseModel, Field
3
+ from dotenv import load_dotenv
4
  import instructor
5
  from openai import OpenAI
6
  import os
7
+ import logging
8
+
9
+ load_dotenv()
10
+
11
+ # Set up logging
12
+ logging.basicConfig(level=logging.INFO)
13
+ logger = logging.getLogger(__name__)
14
 
15
  # Patch the OpenAI client with Instructor
16
  client = instructor.from_openai(OpenAI(api_key=os.environ['OPENAI_API_KEY']))
 
56
  ],
57
  )
58
 
 
59
  # Define the Chainlit message handler
60
  @cl.on_message
61
  async def main(message: cl.Message):
62
+ try:
63
+ user_proposal = message.content
64
 
65
+ user_proposal_details = extract_user_proposal_details(user_proposal)
66
+
67
+ proposed_architecture = generate_proposed_architecture(user_proposal_details.proposal)
68
+
 
 
 
 
 
 
 
 
 
 
 
 
69
  await cl.Message(
70
+ content=f"Proposed Architecture:\n{proposed_architecture.proposed_architecture}"
71
  ).send()
72
 
73
+ feedback_message = await cl.AskUserMessage(content="What do you think about this proposed plan and alleged architecture?", timeout=60).send()
74
+ if feedback_message:
75
+ human_feedback_of_proposed_plan = feedback_message["output"]
76
+
77
+ revised_architecture = revise_architecture(proposed_architecture.proposed_architecture)
78
+
79
+ await cl.Message(
80
+ content=f"Revised Architecture:\n{revised_architecture.revised_proposed_architecture}"
81
+ ).send()
82
+
83
+ with open("output.md", "w") as output_file:
84
+ output_file.write("# User Proposal\n")
85
+ output_file.write(user_proposal_details.proposal + "\n\n")
86
+ output_file.write("# Proposed Architecture\n")
87
+ output_file.write(proposed_architecture.proposed_architecture + "\n\n")
88
+ output_file.write("# Revised Architecture\n")
89
+ output_file.write(revised_architecture.revised_proposed_architecture + "\n")
90
 
91
+ await cl.Message(
92
+ content="The results have been saved to output.md"
93
+ ).send()
94
+ except Exception as e:
95
+ logger.error(f"An error occurred: {e}")
96
  await cl.Message(
97
+ content="An error occurred while processing your request. Please try again later."
98
  ).send()
99
 
100
  # Load the starters