Craig Pretzinger commited on
Commit
1d9da65
1 Parent(s): eb8c28b

Updated runtime

Browse files
Files changed (2) hide show
  1. app.py +18 -4
  2. runtime.txt +1 -1
app.py CHANGED
@@ -6,6 +6,18 @@ from transformers import BertTokenizer, BertForSequenceClassification
6
  import torch
7
  import faiss
8
  import numpy as np
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  # API Keys and Org ID
11
  openai.api_key = os.getenv("OPENAI_API_KEY")
@@ -52,15 +64,17 @@ def enhance_with_gpt4o(fda_response):
52
  except Exception as e:
53
  return f"Error: {str(e)}"
54
 
55
- # Main function that gets PubMedBERT output and enhances it using GPT-4o-mini
56
  def respond(message, system_message, max_tokens, temperature, top_p):
57
  try:
58
  # First retrieve info via PubMedBERT
59
  fda_response = handle_fda_query(message)
60
 
61
- # Then enhance this info via GPT-4o-mini
62
- enhanced_response = enhance_with_gpt4o(fda_response)
63
-
 
 
 
64
  # Return both the PubMedBERT result and the enhanced version
65
  return f"Original Info from PubMedBERT: {fda_response}\n\nEnhanced Info via GPT-4o-mini: {enhanced_response}"
66
 
 
6
  import torch
7
  import faiss
8
  import numpy as np
9
+ import json
10
+
11
+ def clean_payload(payload):
12
+ # Remove "data:" prefix and clean newline characters
13
+ cleaned_payload = payload.lstrip("data:").rstrip("\n")
14
+ try:
15
+ json_payload = json.loads(cleaned_payload)
16
+ except json.JSONDecodeError as e:
17
+ print(f"JSON decoding error: {e}")
18
+ json_payload = None
19
+ return json_payload
20
+
21
 
22
  # API Keys and Org ID
23
  openai.api_key = os.getenv("OPENAI_API_KEY")
 
64
  except Exception as e:
65
  return f"Error: {str(e)}"
66
 
 
67
  def respond(message, system_message, max_tokens, temperature, top_p):
68
  try:
69
  # First retrieve info via PubMedBERT
70
  fda_response = handle_fda_query(message)
71
 
72
+ # Stream the enhanced response via GPT-4o-mini using the client
73
+ enhanced_response = ""
74
+ for chat_message in client.chat_completion(...):
75
+ payload = json.loads(chat_message.lstrip("data:").rstrip("\n"))
76
+ enhanced_response += payload["content"] # Or however the payload structure works
77
+
78
  # Return both the PubMedBERT result and the enhanced version
79
  return f"Original Info from PubMedBERT: {fda_response}\n\nEnhanced Info via GPT-4o-mini: {enhanced_response}"
80
 
runtime.txt CHANGED
@@ -1 +1 @@
1
- python-3.10.15
 
1
+ python-3.10.13