bluenevus commited on
Commit
bd8f663
·
1 Parent(s): 3f743eb

Update app.py via AI Editor

Browse files
Files changed (1) hide show
  1. app.py +14 -17
app.py CHANGED
@@ -62,19 +62,6 @@ def anthropic_stream_generate(prompt):
62
  logging.error("Error during anthropic streaming request: %s", e)
63
  return f"Error during streaming: {e}"
64
 
65
- def anthropic_sync_generate(prompt):
66
- try:
67
- response = anthropic_client.messages.create(
68
- model=CLAUDE3_SONNET_MODEL,
69
- max_tokens=CLAUDE3_MAX_OUTPUT_TOKENS,
70
- messages=[{"role": "user", "content": prompt}]
71
- )
72
- logging.info("Synchronous anthropic generation complete.")
73
- return response.content[0].text if hasattr(response, "content") else ""
74
- except Exception as e:
75
- logging.error("Error during anthropic synchronous request: %s", e)
76
- return f"Error during synchronous call: {e}"
77
-
78
  def save_shredded_as_docx(shredded_text, rfp_filename):
79
  doc = Document()
80
  doc.add_heading(f"Shredded Requirements for {rfp_filename}", 0)
@@ -190,7 +177,6 @@ def process_document(action, selected_filename=None, chat_input=None, selected_p
190
  rfp_content = uploaded_documents[selected_filename]
191
  gen_bytes = generated_documents[selected_generated]
192
  try:
193
- # Try to read as docx, fallback to decode
194
  try:
195
  docx_stream = io.BytesIO(gen_bytes)
196
  doc = Document(docx_stream)
@@ -214,9 +200,20 @@ def process_document(action, selected_filename=None, chat_input=None, selected_p
214
  prompt += f"User additional instructions: {chat_input}\n"
215
  prompt += f"\n---\nRFP/SOW/PWS/RFI ({rfp_filename}):\n{rfp_content}\n"
216
  prompt += f"\n---\nGenerated Document ({generated_docname}):\n{generated_doc_content}\n"
217
- logging.info("Sending proposal prompt to anthropic. This is a synchronous call.")
218
- result = anthropic_sync_generate(prompt)
219
- return result, None, None
 
 
 
 
 
 
 
 
 
 
 
220
 
221
  elif action == 'compliance':
222
  return "Compliance checking not implemented yet.", None, None
 
62
  logging.error("Error during anthropic streaming request: %s", e)
63
  return f"Error during streaming: {e}"
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  def save_shredded_as_docx(shredded_text, rfp_filename):
66
  doc = Document()
67
  doc.add_heading(f"Shredded Requirements for {rfp_filename}", 0)
 
177
  rfp_content = uploaded_documents[selected_filename]
178
  gen_bytes = generated_documents[selected_generated]
179
  try:
 
180
  try:
181
  docx_stream = io.BytesIO(gen_bytes)
182
  doc = Document(docx_stream)
 
200
  prompt += f"User additional instructions: {chat_input}\n"
201
  prompt += f"\n---\nRFP/SOW/PWS/RFI ({rfp_filename}):\n{rfp_content}\n"
202
  prompt += f"\n---\nGenerated Document ({generated_docname}):\n{generated_doc_content}\n"
203
+ logging.info("Sending proposal prompt to anthropic. This is a streaming call.")
204
+ result_holder = {"text": None}
205
+ def thread_proposal():
206
+ try:
207
+ result = anthropic_stream_generate(prompt)
208
+ result_holder["text"] = result
209
+ except Exception as e:
210
+ logging.error("Error during streaming proposal request: %s", e)
211
+ result_holder["text"] = f"Error during streaming: {e}"
212
+ from threading import Thread
213
+ t = Thread(target=thread_proposal)
214
+ t.start()
215
+ t.join()
216
+ return result_holder["text"], None, None
217
 
218
  elif action == 'compliance':
219
  return "Compliance checking not implemented yet.", None, None