gmkdigitalmedia commited on
Commit
bd646b8
·
verified ·
1 Parent(s): da112b0

Upload foundation_engine.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. foundation_engine.py +51 -9
foundation_engine.py CHANGED
@@ -1041,15 +1041,36 @@ def generate_llama_response(query, rag_context, hf_token=None):
1041
  from groq import Groq
1042
  client = Groq(api_key=groq_api_key)
1043
 
1044
- # Simplified prompt for faster generation
1045
- system_prompt = """You are a medical research assistant. Answer based ONLY on the provided clinical trial data. Be concise and cite NCT IDs."""
 
1046
 
1047
- user_prompt = f"""Clinical trials:
1048
  {rag_context[:6000]}
1049
 
1050
  Question: {query}
1051
 
1052
- Provide a concise answer citing specific NCT trial IDs."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1053
 
1054
  response = client.chat.completions.create(
1055
  model="llama-3.1-70b-versatile", # Groq's optimized 70B
@@ -1057,7 +1078,7 @@ Provide a concise answer citing specific NCT trial IDs."""
1057
  {"role": "system", "content": system_prompt},
1058
  {"role": "user", "content": user_prompt}
1059
  ],
1060
- max_tokens=512, # Shorter for speed
1061
  temperature=0.3,
1062
  timeout=30
1063
  )
@@ -1070,14 +1091,35 @@ Provide a concise answer citing specific NCT trial IDs."""
1070
  from huggingface_hub import InferenceClient
1071
  client = InferenceClient(token=hf_token, timeout=120)
1072
 
1073
- system_prompt = """You are a medical research assistant. Answer based ONLY on the provided clinical trial data. Be concise and cite NCT IDs."""
 
1074
 
1075
- user_prompt = f"""Clinical trials:
1076
  {rag_context[:6000]}
1077
 
1078
  Question: {query}
1079
 
1080
- Provide a concise answer citing specific NCT trial IDs."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1081
 
1082
  messages = [
1083
  {"role": "system", "content": system_prompt},
@@ -1087,7 +1129,7 @@ Provide a concise answer citing specific NCT trial IDs."""
1087
  response = client.chat_completion(
1088
  model="meta-llama/Meta-Llama-3.1-70B-Instruct",
1089
  messages=messages,
1090
- max_tokens=512, # Reduced from 2048 for speed
1091
  temperature=0.3
1092
  )
1093
 
 
1041
  from groq import Groq
1042
  client = Groq(api_key=groq_api_key)
1043
 
1044
+ # Structured prompt for clear, organized output
1045
+ system_prompt = """You are a medical research assistant specializing in clinical trial analysis.
1046
+ Answer based ONLY on the provided trial data. Structure your responses clearly with sections."""
1047
 
1048
+ user_prompt = f"""Clinical Trial Data:
1049
  {rag_context[:6000]}
1050
 
1051
  Question: {query}
1052
 
1053
+ INSTRUCTIONS:
1054
+ Format your answer with these sections (skip sections if not applicable):
1055
+
1056
+ ## SUMMARY
1057
+ Brief 1-2 sentence overview
1058
+
1059
+ ## KEY FINDINGS
1060
+ - Drug/Treatment: [name and details]
1061
+ - Disease/Condition: [what's being treated]
1062
+ - Company/Sponsor: [who's running the trial]
1063
+ - Trial Phase: [phase I/II/III/IV]
1064
+ - Status: [recruiting/active/completed]
1065
+
1066
+ ## OUTCOMES/ENDPOINTS
1067
+ - Primary endpoints and results (if available)
1068
+ - Key efficacy/safety data
1069
+
1070
+ ## TRIAL REFERENCES
1071
+ List NCT IDs with brief descriptions
1072
+
1073
+ Only include information EXPLICITLY stated in the trial data."""
1074
 
1075
  response = client.chat.completions.create(
1076
  model="llama-3.1-70b-versatile", # Groq's optimized 70B
 
1078
  {"role": "system", "content": system_prompt},
1079
  {"role": "user", "content": user_prompt}
1080
  ],
1081
+ max_tokens=1024, # Longer for structured output
1082
  temperature=0.3,
1083
  timeout=30
1084
  )
 
1091
  from huggingface_hub import InferenceClient
1092
  client = InferenceClient(token=hf_token, timeout=120)
1093
 
1094
+ system_prompt = """You are a medical research assistant specializing in clinical trial analysis.
1095
+ Answer based ONLY on the provided trial data. Structure your responses clearly with sections."""
1096
 
1097
+ user_prompt = f"""Clinical Trial Data:
1098
  {rag_context[:6000]}
1099
 
1100
  Question: {query}
1101
 
1102
+ INSTRUCTIONS:
1103
+ Format your answer with these sections (skip sections if not applicable):
1104
+
1105
+ ## SUMMARY
1106
+ Brief 1-2 sentence overview
1107
+
1108
+ ## KEY FINDINGS
1109
+ - Drug/Treatment: [name and details]
1110
+ - Disease/Condition: [what's being treated]
1111
+ - Company/Sponsor: [who's running the trial]
1112
+ - Trial Phase: [phase I/II/III/IV]
1113
+ - Status: [recruiting/active/completed]
1114
+
1115
+ ## OUTCOMES/ENDPOINTS
1116
+ - Primary endpoints and results (if available)
1117
+ - Key efficacy/safety data
1118
+
1119
+ ## TRIAL REFERENCES
1120
+ List NCT IDs with brief descriptions
1121
+
1122
+ Only include information EXPLICITLY stated in the trial data."""
1123
 
1124
  messages = [
1125
  {"role": "system", "content": system_prompt},
 
1129
  response = client.chat_completion(
1130
  model="meta-llama/Meta-Llama-3.1-70B-Instruct",
1131
  messages=messages,
1132
+ max_tokens=1024, # Longer for structured output
1133
  temperature=0.3
1134
  )
1135