|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +API_KEY=$OPENAI_API_RSMC_KEY |
| 4 | +MODEL="gpt-4o-mini" |
| 5 | + |
| 6 | +DOCS_DIR="docs" |
| 7 | + |
| 8 | +call_gpt_api() { |
| 9 | + local prompt="$1" |
| 10 | + |
| 11 | + response=$(curl -s -X POST https://api.openai.com/v1/completions \ |
| 12 | + -H "Content-Type: application/json" \ |
| 13 | + -H "Authorization: Bearer $API_KEY" \ |
| 14 | + -d '{ |
| 15 | + "model": "'"$MODEL"'", |
| 16 | + "prompt": "'"$prompt"'", |
| 17 | + "temperature": 0.7, |
| 18 | + "max_tokens": 4096, # Adjust this according to model limits |
| 19 | + "top_p": 1, |
| 20 | + "frequency_penalty": 0.2, |
| 21 | + "presence_penalty": 0.2 |
| 22 | + }' |
| 23 | + ) |
| 24 | + |
| 25 | + echo "$response" | jq -r '.choices[0].text' |
| 26 | +} |
| 27 | + |
| 28 | +for file in "$DOCS_DIR"/*/*.md; do |
| 29 | + if [[ -f $file ]]; then |
| 30 | + file_content=$(<"$file") |
| 31 | + file_name=$(basename "$file") |
| 32 | + |
| 33 | + prompt=$(cat <<PROMPT |
| 34 | +You are provided with a markdown document corresponding to the ECS plugin \'$file_name\'. |
| 35 | +
|
| 36 | +1. Understand the document structure. |
| 37 | +2. Review the list of source files. |
| 38 | +3. Analyze the source code provided at the end to identify and describe (according to the template): |
| 39 | + - The main **Components** and their purposes. |
| 40 | + - The essential **Resources** with their roles. |
| 41 | + - Various **Systems**, categorizing them appropriately, and descriptions of their functions. |
| 42 | + - Networking aspects, if applicable. |
| 43 | +4. Create a corresponding mermaid diagram |
| 44 | +
|
| 45 | +Ensure that you don\'t miss out on any details but that the documentation serves as a nice overview and is concise. |
| 46 | +Content: |
| 47 | +$file_content |
| 48 | +PROMPT |
| 49 | +) |
| 50 | + |
| 51 | + response_text=$(call_gpt_api "$prompt") |
| 52 | + |
| 53 | + output_file="${file%.*}_processed.md" |
| 54 | + echo "$response_text" > "$output_file" |
| 55 | + echo "Processed $file and saved the response to $output_file" |
| 56 | + fi |
| 57 | +done |
| 58 | + |
0 commit comments