forked from mistralai/client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_examples.sh
More file actions
executable file
·133 lines (118 loc) · 4.06 KB
/
run_examples.sh
File metadata and controls
executable file
·133 lines (118 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
# Defaults
RETRY_COUNT=3
NO_EXTRA_DEP=false
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--no-extra-dep)
NO_EXTRA_DEP=true
shift
;;
--retry-count)
RETRY_COUNT="$2"
shift 2
;;
--help)
echo "Usage: $0 [--no-extra-dep] [--retry-count N]"
echo " --no-extra-dep: Exclude files that require extra dependencies"
echo " --retry-count N: Number of retries for each test (default: 3)"
echo " --help: Show this help message"
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
# List of files to always exclude
exclude_files=(
"examples/mistral/chat/chatbot_with_streaming.py"
"examples/mistral/agents/async_conversation_run_mcp_remote_auth.py"
"examples/mistral/jobs/async_fine_tuning.py"
"examples/mistral/jobs/async_fine_tuning_chat.py"
"examples/mistral/jobs/fine_tuning.py"
"examples/mistral/jobs/fine_tuning_dry_run.py"
"examples/mistral/jobs/async_jobs_ocr_batch_annotation.py"
"examples/mistral/classifier/async_classifier.py"
"examples/mistral/mcp_servers/sse_server.py"
"examples/mistral/mcp_servers/stdio_server.py"
"examples/mistral/agents/async_conversation_run_code_interpreter.py"
"examples/mistral/agents/async_conversation_run_stream.py"
"examples/mistral/agents/async_conversation_run_mcp.py"
"examples/mistral/agents/async_conversation_run_mcp_remote.py"
"examples/mistral/agents/async_agents_no_streaming.py"
"examples/mistral/audio/async_realtime_transcription_microphone.py"
"examples/mistral/audio/async_realtime_transcription_stream.py"
"examples/mistral/audio/async_realtime_transcription_dual_delay_microphone.py"
"examples/mistral/workflows/workflow_execute_and_wait.py"
"examples/mistral/workflows/async_workflow_execute_and_wait.py"
"examples/mistral/workflows/workflow_execute.py"
"examples/mistral/workflows/async_workflow_execute.py"
)
# Files that require extra dependencies (agents, mcp, audio, etc.)
extra_dep_files=(
"examples/mistral/agents/"
"examples/mistral/mcp_servers/"
"examples/mistral/audio/"
)
if [ "$NO_EXTRA_DEP" = true ]; then
for pattern in "${extra_dep_files[@]}"; do
for f in ${pattern}*.py; do
[ -f "$f" ] && exclude_files+=("$f")
done
done
fi
failed=0
echo "Skipping scripts"
for file in "${exclude_files[@]}"; do
echo "$file"
done
# Function to run a test with retries
run_test_with_retries() {
local file="$1"
local attempt=1
local error_outputs=()
while [ $attempt -le $RETRY_COUNT ]; do
echo "Running $file (attempt $attempt/$RETRY_COUNT)"
# Run the script and capture both exit status and error output
current_output=$(python3 "$file" 2>&1)
exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "Success"
return 0
else
# Store the error output from this attempt
error_outputs+=("Attempt $attempt: $current_output")
if [ $attempt -lt $RETRY_COUNT ]; then
echo "Failed (attempt $attempt/$RETRY_COUNT), retrying..."
sleep 1 # Brief pause before retry
else
echo "Failed after $RETRY_COUNT attempts"
echo "Error outputs from all attempts:"
for error_output in "${error_outputs[@]}"; do
echo "$error_output"
echo "---"
done
return 1
fi
fi
attempt=$((attempt + 1))
done
}
for file in examples/mistral/**/*.py; do
# Check if the file is not in the exclude list
if [ -f "$file" ] && [[ ! " ${exclude_files[@]} " =~ " $file " ]]; then
if ! run_test_with_retries "$file"; then
failed=1
fi
else
echo "Skipped $file"
fi
done
# If one of the example scripts failed, then exit
if [ $failed -ne 0 ]; then
exit 1
fi