Skip to content

Commit eded529

Browse files
committed
Improve AI inference logging
1 parent 4ba55f9 commit eded529

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

scripts/extension_ai_analysis.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
INFERENCE_RESPONSE_PER_MINUTE_LIMIT = 10 # slow down to not exceed token per minute (tpm) limit
3131
INFERENCE_MAX_CHARACTERS = 400000 # max characters in all files provided to the model, approximately 100k tokens
3232

33+
print(f"Using inference server: {INFERENCE_URL} with model: {INFERENCE_MODEL}, with API key: {'*' * (len(INFERENCE_API_KEY)-3) + INFERENCE_API_KEY[-3:]} ")
3334

3435
QUESTIONS = [
3536
["Is there a EXTENSION_DESCRIPTION variable in the CMakeLists.txt file that describes what the extension does in a few sentences that can be understood by a person knowledgeable in medical image computing?", ["cmake"]],
@@ -138,7 +139,9 @@ def collect_analyzed_files(folder):
138139
def ask_question(system_msg, question):
139140
headers = {
140141
"Content-Type": "application/json",
141-
"Authorization": f"Bearer {INFERENCE_API_KEY}"
142+
"Authorization": f"Bearer {INFERENCE_API_KEY}",
143+
"HTTP-Referer": "slicer.org", # Optional. Site URL for rankings on openrouter.ai.
144+
"X-Title": "3D Slicer", # Optional. Site title for rankings on openrouter.ai.
142145
}
143146

144147
messages = [
@@ -167,6 +170,7 @@ def ask_question(system_msg, question):
167170
except Exception as e:
168171
import traceback
169172
traceback.print_exc()
173+
print(data)
170174
raise RuntimeError(f"Error or unexpected response: {response.json()["error"]["message"]}")
171175

172176
return answer
@@ -219,8 +223,6 @@ def analyze_extension(extension_name, metadata, cloned_repository_folder):
219223
answer = ask_question(system_msg, question)
220224
answers.append(answer)
221225
except Exception as e:
222-
import traceback
223-
traceback.print_exc()
224226
answers = [f"Error or unexpected response: {e}"]
225227
break
226228

@@ -236,8 +238,6 @@ def analyze_extension(extension_name, metadata, cloned_repository_folder):
236238
try:
237239
answer = ask_question(system_msg, question)
238240
except Exception as e:
239-
import traceback
240-
traceback.print_exc()
241241
answer = f"Error or unexpected response: {e}"
242242
print(answer)
243243

0 commit comments

Comments
 (0)