-
Notifications
You must be signed in to change notification settings - Fork 0
116 lines (104 loc) · 4.2 KB
/
createGuide.yml
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
name: Generate Guide with ChatGPT API
on:
workflow_dispatch:
inputs:
title:
description: 'Title of the Guide'
required: true
description:
description: 'Description of the Guide'
required: true
jobs:
generate-guide:
runs-on: ubuntu-latest
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
ASSISTANT_ID: 'asst_401AkHGtgCQEtJBJQecK01Cb' # Replace with your actual assistant ID
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up variables
run: |
echo "TITLE=${{ github.event.inputs.title }}" >> $GITHUB_ENV
echo "DESCRIPTION=${{ github.event.inputs.description }}" >> $GITHUB_ENV
- name: Install jq
run: sudo apt-get install -y jq
- name: Create a thread
id: create_thread
run: |
THREAD_RESPONSE=$(curl -s https://api.openai.com/v1/threads \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "OpenAI-Beta: assistants=v2" \
-d '')
THREAD_ID=$(echo "$THREAD_RESPONSE" | jq -r '.id')
echo "THREAD_ID=$THREAD_ID" >> $GITHUB_ENV
shell: bash
- name: Add a message to the thread
run: |
MESSAGE_CONTENT="${{ env.TITLE }}: ${{ env.DESCRIPTION }}"
curl -s https://api.openai.com/v1/threads/${{ env.THREAD_ID }}/messages \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "OpenAI-Beta: assistants=v2" \
-d "{\"role\": \"user\", \"content\": \"$MESSAGE_CONTENT\"}"
shell: bash
- name: Create a run
id: create_run
run: |
RUN_RESPONSE=$(curl -s https://api.openai.com/v1/threads/${{ env.THREAD_ID }}/runs \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-H "OpenAI-Beta: assistants=v2" \
-d "{
\"assistant_id\": \"${{ env.ASSISTANT_ID }}\",
\"instructions\": \"Please assist with the provided title and description.\"
}")
echo "Run Response: $RUN_RESPONSE"
RUN_ID=$(echo "$RUN_RESPONSE" | jq -r '.id')
echo "RUN_ID=$RUN_ID" >> $GITHUB_ENV
shell: bash
- name: Wait for run completion
run: |
STATUS="running"
while [[ "$STATUS" == "running" || "$STATUS" == "queued" || "$STATUS" == "in_progress" ]]; do
sleep 5
RUN_STATUS_RESPONSE=$(curl -s https://api.openai.com/v1/threads/${{ env.THREAD_ID }}/runs/${{ env.RUN_ID }} \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "OpenAI-Beta: assistants=v2")
STATUS=$(echo "$RUN_STATUS_RESPONSE" | jq -r '.status')
echo "Current run status: $STATUS"
done
if [[ "$STATUS" != "succeeded" && "$STATUS" != "completed" ]]; then
echo "Run failed with status: $STATUS"
exit 1
fi
shell: bash
- name: Retrieve assistant's response
run: |
MESSAGES=$(curl -s https://api.openai.com/v1/threads/${{ env.THREAD_ID }}/messages \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "OpenAI-Beta: assistants=v2")
ASSISTANT_MESSAGE=$(echo "$MESSAGES" | jq -r '.data[] | select(.role=="assistant") | .content')
echo "Assistant's Response:"
echo "$ASSISTANT_MESSAGE" > guide.md
shell: bash
- name: Configure Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Create and Push Branch with Guide
run: |
git checkout -b generate-guide-branch
git add guide.md
git commit -m "Add generated guide: ${{ github.event.inputs.title }}"
git push origin generate-guide-branch
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
branch: generate-guide-branch
title: "Add Generated Guide: ${{ github.event.inputs.title }}"
body: "This PR adds a new guide generated based on the provided title and description."
base: main
labels: "documentation,auto-generated"