Skip to content

Commit b18a3b1

Browse files
update
1 parent b4299b2 commit b18a3b1

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ config/emba_updater
1010
config/emba_updater_data
1111
config/module_blacklist.txt
1212
config/jtr_wordlist.txt
13+
config/gpt_config.env

modules/F05_qs_resolver.sh

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ F05_qs_resolver() {
2020
if [[ "${GPT_OPTION}" -gt 0 ]]; then
2121
# wait for Q02 to end
2222
while ! grep -q "Q02_openai_question finished" "${LOG_DIR}"/"${MAIN_LOG_FILE}"; do
23+
if grep -q "Quest container done" "${LOG_DIR}"/"${MAIN_LOG_FILE}"; then
24+
break
25+
fi
2326
sleep 1
2427
done
2528
local _GPT_INPUT_FILE_=""

modules/Q02_openai_question.sh

+12-12
Original file line numberDiff line numberDiff line change
@@ -67,50 +67,50 @@ ask_chatgpt() {
6767
GPT_RESPONSE_="${COL7_}"
6868
GPT_INPUT_FILE_="$(basename "${SCRIPT_PATH_TMP_}")"
6969

70-
print_output "[*]trying to check inside ${LOG_DIR}/firmware" "no_log"
70+
print_output "[*] Trying to check inside ${ORANGE}${LOG_DIR}/firmware${NC}" "no_log"
7171
SCRIPT_PATH_TMP_="$(find "${LOG_DIR}/firmware" -wholename "*${SCRIPT_PATH_TMP_}")"
7272
cp "${SCRIPT_PATH_TMP_}" "${GPT_FILE_DIR_}/${GPT_INPUT_FILE_}.log"
73-
print_output "[*]trying to check ${SCRIPT_PATH_TMP_} with Question ${GPT_QUESTION_} " "no_log"
73+
print_output "[*] Trying to check ${ORANGE} ${SCRIPT_PATH_TMP_} ${NC}with Question ${ORANGE}${GPT_QUESTION_}${NC}" "no_log"
7474
print_output "[*]Prio is ${GPT_PRIO_}" "no_log"
7575

7676
if [[ -z ${GPT_ANSWER_} ]] && [[ ${GPT_PRIO_} -le ${MINIMUM_GPT_PRIO} ]]; then
7777
if [ -f "${SCRIPT_PATH_TMP_}" ]; then
7878
# add navbar-item for file
7979
sub_module_title "${GPT_INPUT_FILE_}"
80-
print_output "[*] Asking ChatGPT about $(print_path "${SCRIPT_PATH_TMP_}")" "" "${GPT_FILE_DIR_}/${GPT_INPUT_FILE_}.log"
80+
print_output "[*] Asking ChatGPT about ${ORANGE}$(print_path "${SCRIPT_PATH_TMP_}")${NC}" "" "${GPT_FILE_DIR_}/${GPT_INPUT_FILE_}.log"
8181
head -n -2 "${CONFIG_DIR}/gpt_template.json" > "${TMP_DIR}/chat.json"
8282
CHATGPT_CODE_=$(sed 's/\\//g;s/"/\\\"/g' "${SCRIPT_PATH_TMP_}" | tr -d '[:space:]')
8383
printf '"%s %s"\n}]}' "${GPT_QUESTION_}" "${CHATGPT_CODE_}" >> "${TMP_DIR}/chat.json"
84-
print_output "[*] The Combined Cost of the OpenAI request / the length is: ${#GPT_QUESTION_} + ${#CHATGPT_CODE_}" "no_log"
84+
print_output "[*] The Combined Cost of the OpenAI request / the length is: ${ORANGE}${#GPT_QUESTION_} + ${#CHATGPT_CODE_}${NC}" "no_log"
8585
HTTP_CODE_=$(curl https://api.openai.com/v1/chat/completions -H "Content-Type: application/json" \
8686
-H "Authorization: Bearer ${OPENAI_API_KEY}" \
87-
-d @"${TMP_DIR}/chat.json" -o "${TMP_DIR}/response.json" --write-out "%{http_code}")
87+
-d @"${TMP_DIR}/chat.json" -o "${TMP_DIR}/${GPT_INPUT_FILE_}_response.json" --write-out "%{http_code}")
8888
if [[ "${HTTP_CODE_}" -ne 200 ]] ; then
8989
print_output "[-] Something went wrong with the ChatGPT requests"
90-
if [ -f "${TMP_DIR}/response.json" ]; then
91-
print_output "[-] ERROR response:$(cat "${TMP_DIR}/response.json")"
90+
if [ -f "${TMP_DIR}/${GPT_INPUT_FILE_}_response.json" ]; then
91+
print_output "[-] ERROR response:$(cat "${TMP_DIR}/${GPT_INPUT_FILE_}_response.json")"
9292
fi
93-
if jq '.error.type' "${TMP_DIR}"/response.json | grep -q "insufficient_quota" ; then
93+
if jq '.error.type' "${TMP_DIR}/${GPT_INPUT_FILE_}_response.json" | grep -q "insufficient_quota" ; then
9494
CHATGPT_RESULT_CNT=-1
9595
break 2
9696
fi
9797
fi
98-
GPT_RESPONSE_=$(jq '.choices[] | .message.content' "${TMP_DIR}"/response.json)
98+
GPT_RESPONSE_=$(jq '.choices[] | .message.content' "${TMP_DIR}/${GPT_INPUT_FILE_}_response.json")
9999
GPT_RESPONSE_CLEANED_="${GPT_RESPONSE_//\;/}" #remove ; from response
100-
GPT_TOKENS_=$(jq '.usage.total_tokens' "${TMP_DIR}"/response.json)
100+
GPT_TOKENS_=$(jq '.usage.total_tokens' "${TMP_DIR}/${GPT_INPUT_FILE_}_response.json")
101101
if [[ ${GPT_TOKENS_} -ne 0 ]]; then
102102
# write new into done csv
103103
write_csv_gpt "${GPT_INPUT_FILE_}" "${GPT_ANCHOR_}" "GPT-Prio-${GPT_PRIO_}" "${GPT_QUESTION_}" "${GPT_OUTPUT_FILE_}" "cost=${GPT_TOKENS_}" "'${GPT_RESPONSE_CLEANED_//\'/}'"
104104
# print openai response
105105
print_output "CHATGPT:${GPT_RESPONSE_//\"/}"
106106
# add proper module link
107-
print_output "[+] Further results available for $GPT_INPUT_FILE_"
107+
print_output "[+] Further results available for ${ORANGE}${GPT_INPUT_FILE_}${NC}"
108108
ORIGIN_MODULE_="$(basename "$(dirname "${GPT_OUTPUT_FILE_}")" | cut -d_ -f1)"
109109
write_link "${ORIGIN_MODULE_}"
110110
((CHATGPT_RESULT_CNT++))
111111
fi
112112
else
113-
print_output "[-] Couldn't find $(print_path "${SCRIPT_PATH_TMP_}")"
113+
print_output "[-] Couldn't find ${ORANGE}$(print_path "${SCRIPT_PATH_TMP_}")${NC}"
114114
fi
115115
fi
116116
if [[ "${GPT_OPTION}" -ne 2 ]]; then

0 commit comments

Comments
 (0)