ambrosfitz commited on
Commit
fb69473
·
verified ·
1 Parent(s): 2616cc8

Update question_generator.py

Browse files
Files changed (1) hide show
  1. question_generator.py +10 -15
question_generator.py CHANGED
@@ -5,7 +5,8 @@ import logging
5
  import hashlib
6
  from typing import List, Dict
7
  from datetime import datetime
8
- from mistralai import Mistral
 
9
 
10
  # Set up logging
11
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@@ -19,7 +20,7 @@ if not api_key:
19
  model = "mistral-large-latest"
20
 
21
  # Initialize Mistral client
22
- client = Mistral(api_key=api_key)
23
 
24
  def load_csv_data(file_path: str) -> List[Dict[str, str]]:
25
  """Load data from a CSV file."""
@@ -135,32 +136,26 @@ def generate_microbiology_question() -> Dict[str, str]:
135
 
136
  Format the response as a JSON object with the following keys:
137
 
138
- {
139
  "question": "The question text",
140
- "options": {
141
  "A": "Option A text",
142
  "B": "Option B text",
143
  "C": "Option C text",
144
  "D": "Option D text",
145
  "E": "Option E text"
146
- },
147
  "correct_answer": "The letter of the correct answer (A, B, C, D, or E)",
148
  "explanation": "The explanation text",
149
  "medical_reasoning": "The detailed medical reasoning text"
150
- }
151
  """
152
 
153
- chat_response = client.chat.complete(
154
  model=model,
155
  messages=[
156
- {
157
- "role": "system",
158
- "content": "You are a medical educator creating unique microbiology questions for the NBME exam. Ensure each question is distinct from previously generated ones and follows the specified template."
159
- },
160
- {
161
- "role": "user",
162
- "content": prompt
163
- }
164
  ]
165
  )
166
 
 
5
  import hashlib
6
  from typing import List, Dict
7
  from datetime import datetime
8
+ from mistralai.client import MistralClient
9
+ from mistralai.models.chat_completion import ChatMessage
10
 
11
  # Set up logging
12
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
 
20
  model = "mistral-large-latest"
21
 
22
  # Initialize Mistral client
23
+ client = MistralClient(api_key=api_key)
24
 
25
  def load_csv_data(file_path: str) -> List[Dict[str, str]]:
26
  """Load data from a CSV file."""
 
136
 
137
  Format the response as a JSON object with the following keys:
138
 
139
+ {{
140
  "question": "The question text",
141
+ "options": {{
142
  "A": "Option A text",
143
  "B": "Option B text",
144
  "C": "Option C text",
145
  "D": "Option D text",
146
  "E": "Option E text"
147
+ }},
148
  "correct_answer": "The letter of the correct answer (A, B, C, D, or E)",
149
  "explanation": "The explanation text",
150
  "medical_reasoning": "The detailed medical reasoning text"
151
+ }}
152
  """
153
 
154
+ chat_response = client.chat(
155
  model=model,
156
  messages=[
157
+ ChatMessage(role="system", content="You are a medical educator creating unique microbiology questions for the NBME exam. Ensure each question is distinct from previously generated ones and follows the specified template."),
158
+ ChatMessage(role="user", content=prompt)
 
 
 
 
 
 
159
  ]
160
  )
161