ProfessorLeVesseur commited on
Commit
596c1e2
·
verified ·
1 Parent(s): 212ea10

Update ai_analysis.py

Browse files
Files changed (1) hide show
  1. ai_analysis.py +64 -11
ai_analysis.py CHANGED
@@ -1,5 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import io
2
  import streamlit as st
 
 
3
 
4
  class AIAnalysis:
5
  def __init__(self, client):
@@ -9,18 +67,14 @@ class AIAnalysis:
9
  metrics_str = student_metrics_df.to_string(index=False)
10
  llm_input = f"""
11
  Based on the following student metrics:
12
-
13
  {metrics_str}
14
-
15
  Provide:
16
-
17
  1. Notes and Key Takeaways: Summarize the data, highlight students with the lowest and highest attendance and engagement percentages, identify students who may need adjustments to their intervention due to low attendance or engagement, and highlight students who are showing strong performance.
18
-
19
  2. Recommendations and Next Steps: Provide interpretations based on the analysis and suggest possible next steps or strategies to improve student outcomes.
20
  """
21
  return llm_input
22
 
23
- def prompt_response_from_hf_llm(self, llm_input):
24
  system_prompt = """
25
  <Persona> An expert Implementation Specialist at Michigan's Multi-Tiered System of Support Technical Assistance Center (MiMTSS TA Center) with deep expertise in SWPBIS, SEL, Structured Literacy, Science of Reading, and family engagement practices.</Persona>
26
  <Task> Analyze educational data and provide evidence-based recommendations for improving student outcomes across multiple tiers of support, drawing from established frameworks in behavioral interventions, literacy instruction, and family engagement.</Task>
@@ -28,21 +82,20 @@ Provide:
28
  <Format> Deliver insights through clear, actionable recommendations supported by data analysis, incorporating technical expertise while maintaining accessibility for educators and administrators at various levels of MTSS implementation.</Format>
29
  """
30
 
31
- response = self.client.chat.completions.create(
32
- model="meta-llama/Llama-3.3-70B-Instruct",
33
  messages=[
34
  {"role": "system", "content": system_prompt},
35
  {"role": "user", "content": llm_input}
36
  ],
37
- stream=True,
38
- temperature=0.5,
39
  max_tokens=1024,
40
  top_p=0.7
41
  )
42
 
43
  response_content = ""
44
- for message in response:
45
- response_content += message.choices[0].delta.content
46
 
47
  return response_content.strip()
48
 
 
1
+ # import io
2
+ # import streamlit as st
3
+
4
+ # class AIAnalysis:
5
+ # def __init__(self, client):
6
+ # self.client = client
7
+
8
+ # def prepare_llm_input(self, student_metrics_df):
9
+ # metrics_str = student_metrics_df.to_string(index=False)
10
+ # llm_input = f"""
11
+ # Based on the following student metrics:
12
+
13
+ # {metrics_str}
14
+
15
+ # Provide:
16
+
17
+ # 1. Notes and Key Takeaways: Summarize the data, highlight students with the lowest and highest attendance and engagement percentages, identify students who may need adjustments to their intervention due to low attendance or engagement, and highlight students who are showing strong performance.
18
+
19
+ # 2. Recommendations and Next Steps: Provide interpretations based on the analysis and suggest possible next steps or strategies to improve student outcomes.
20
+ # """
21
+ # return llm_input
22
+
23
+ # def prompt_response_from_hf_llm(self, llm_input):
24
+ # system_prompt = """
25
+ # <Persona> An expert Implementation Specialist at Michigan's Multi-Tiered System of Support Technical Assistance Center (MiMTSS TA Center) with deep expertise in SWPBIS, SEL, Structured Literacy, Science of Reading, and family engagement practices.</Persona>
26
+ # <Task> Analyze educational data and provide evidence-based recommendations for improving student outcomes across multiple tiers of support, drawing from established frameworks in behavioral interventions, literacy instruction, and family engagement.</Task>
27
+ # <Context> Operating within Michigan's educational system to support schools in implementing multi-tiered support systems, with access to student metrics data and knowledge of state-specific educational requirements and MTSS frameworks. </Context>
28
+ # <Format> Deliver insights through clear, actionable recommendations supported by data analysis, incorporating technical expertise while maintaining accessibility for educators and administrators at various levels of MTSS implementation.</Format>
29
+ # """
30
+
31
+ # response = self.client.chat.completions.create(
32
+ # model="meta-llama/Llama-3.3-70B-Instruct",
33
+ # messages=[
34
+ # {"role": "system", "content": system_prompt},
35
+ # {"role": "user", "content": llm_input}
36
+ # ],
37
+ # stream=True,
38
+ # temperature=0.5,
39
+ # max_tokens=1024,
40
+ # top_p=0.7
41
+ # )
42
+
43
+ # response_content = ""
44
+ # for message in response:
45
+ # response_content += message.choices[0].delta.content
46
+
47
+ # return response_content.strip()
48
+
49
+ # def download_llm_output(self, content, filename):
50
+ # buffer = io.BytesIO()
51
+ # buffer.write(content.encode('utf-8'))
52
+ # buffer.seek(0)
53
+ # st.download_button(label="Download AI Output", data=buffer, file_name=filename, mime='text/plain', icon="✏️", use_container_width=True)
54
+
55
+
56
+ # MISTRAL
57
  import io
58
  import streamlit as st
59
+ # from mistralai import Mistral
60
+ # import os
61
 
62
  class AIAnalysis:
63
  def __init__(self, client):
 
67
  metrics_str = student_metrics_df.to_string(index=False)
68
  llm_input = f"""
69
  Based on the following student metrics:
 
70
  {metrics_str}
 
71
  Provide:
 
72
  1. Notes and Key Takeaways: Summarize the data, highlight students with the lowest and highest attendance and engagement percentages, identify students who may need adjustments to their intervention due to low attendance or engagement, and highlight students who are showing strong performance.
 
73
  2. Recommendations and Next Steps: Provide interpretations based on the analysis and suggest possible next steps or strategies to improve student outcomes.
74
  """
75
  return llm_input
76
 
77
+ def prompt_response_from_mistral_llm(self, llm_input):
78
  system_prompt = """
79
  <Persona> An expert Implementation Specialist at Michigan's Multi-Tiered System of Support Technical Assistance Center (MiMTSS TA Center) with deep expertise in SWPBIS, SEL, Structured Literacy, Science of Reading, and family engagement practices.</Persona>
80
  <Task> Analyze educational data and provide evidence-based recommendations for improving student outcomes across multiple tiers of support, drawing from established frameworks in behavioral interventions, literacy instruction, and family engagement.</Task>
 
82
  <Format> Deliver insights through clear, actionable recommendations supported by data analysis, incorporating technical expertise while maintaining accessibility for educators and administrators at various levels of MTSS implementation.</Format>
83
  """
84
 
85
+ response = self.client.chat.stream(
86
+ model="mistral-large-latest",
87
  messages=[
88
  {"role": "system", "content": system_prompt},
89
  {"role": "user", "content": llm_input}
90
  ],
91
+ temperature=0.1,
 
92
  max_tokens=1024,
93
  top_p=0.7
94
  )
95
 
96
  response_content = ""
97
+ for chunk in response:
98
+ response_content += chunk.data.choices[0].delta.content or ""
99
 
100
  return response_content.strip()
101