@@ -76,41 +76,34 @@ To call models programmatically, you’ll need:
76
76
77
77
1. Paste the following workflow into the file you just created.
78
78
79
- ` ` ` yaml
80
- name: GitHub Models Demo
79
+ ` ` ` yaml copy
80
+ name: Use GitHub Models
81
81
82
82
on: [push]
83
83
84
84
permissions:
85
- contents: read
86
85
models: read
87
86
88
87
jobs:
89
- summarize-repo :
88
+ call-model :
90
89
runs-on: ubuntu-latest
91
90
steps:
92
- - name: Checkout code
93
- uses: {% data reusables.actions.action-checkout %}
94
-
95
- - name: Summarize the repository README
91
+ - name: Call AI model
92
+ env:
93
+ GITHUB_TOKEN: {% raw %}${{ secrets.GITHUB_TOKEN } }{% endraw %}
96
94
run: |
97
- SUMMARY_INPUT=$( head -c 4000 README.md)
98
- PROMPT=" Summarize this repository in one sentence. Here is the README:\n$SUMMARY_INPUT "
99
- PAYLOAD=$( jq -n --arg prompt " $PROMPT " ' {
100
- model: "openai/gpt-4.1",
101
- messages: [
102
- {role: "user", content: $prompt}
103
- ]
104
- }' )
105
- RESPONSE=$( curl -sL \
106
- -X POST \
107
- -H " Accept: application/vnd.github+json" \
108
- -H " Authorization: Bearer ${{ secrets.GITHUB_TOKEN } }" \
109
- -H " X-GitHub-Api-Version: 2022-11-28" \
110
- -H " Content-Type: application/json" \
111
- https://models.github.ai/inference/chat/completions \
112
- -d " $PAYLOAD " )
113
- echo " $RESPONSE " | jq -r ' .choices[0].message.content'
95
+ curl " https://models.github.ai/inference/chat/completions" \
96
+ -H " Content-Type: application/json" \
97
+ -H " Authorization: Bearer $GITHUB_TOKEN " \
98
+ -d ' {
99
+ "messages": [
100
+ {
101
+ "role": "user",
102
+ "content": "Explain the concept of recursion."
103
+ }
104
+ ],
105
+ "model": "openai/gpt-4o"
106
+ }'
114
107
` ` `
115
108
116
109
> [! NOTE]
@@ -128,13 +121,21 @@ This example shows how to send a prompt to a model and use the response in your
128
121
129
122
1. Paste the following example prompt into the file you just created.
130
123
131
- ` ` ` yaml
132
- name: One-line summary
133
- description: Ask the model to summarize a paragraph in one sentence.
124
+ ` ` ` yaml copy
125
+ name: Text Summarizer
126
+ description: Summarizes input text concisely
127
+ model: gpt-4o-mini
128
+ modelParameters:
129
+ temperature: 0.5
134
130
messages:
131
+ - role: system
132
+ content: You are a text summarizer. Your only job is to summarize text given to you.
135
133
- role: user
136
- content: ' Summarize the following text in one sentence: {{input}}'
137
- model: openai/gpt-4o
134
+ content: |
135
+ Summarize the given text, beginning with " Summary -" :
136
+ < text>
137
+ {% raw %}{{input}}{% endraw %}
138
+ < /text>
138
139
` ` `
139
140
140
141
1. Commit and push the file to your repository.
@@ -156,28 +157,37 @@ Evaluations help you measure how different models respond to the same inputs so
156
157
157
158
1. Update the file to match the following example.
158
159
159
- ` ` ` yaml
160
- name: One-line summary
161
- description: Ask the model to summarize a paragraph in one sentence.
162
- messages:
163
- - role: user
164
- content: ' Summarize the following text in one sentence: {{input}}'
165
- model: openai/gpt-4o
166
- testData:
167
- - input: > -
168
- The museum opened a new dinosaur exhibit this weekend. Families from all
169
- over the city came to see the life-sized fossils and interactive displays.
170
- expected: > -
171
- The museum' s new dinosaur exhibit attracted many families with its fossils
172
- and interactive displays.
173
- - input: >-
174
- Lucy baked cookies for the school fundraiser. She spent the entire evening
175
- in the kitchen to make sure there were enough for everyone.
176
- expected: Lucy baked cookies all evening to support the school fundraiser.
177
- evaluators:
178
- - name: Similarity
179
- uses: github/similarity
180
- ```
160
+ ` ` ` yaml copy
161
+ name: Text Summarizer
162
+ description: Summarizes input text concisely
163
+ model: gpt-4o-mini
164
+ modelParameters:
165
+ temperature: 0.5
166
+ messages:
167
+ - role: system
168
+ content: You are a text summarizer. Your only job is to summarize text given to you.
169
+ - role: user
170
+ content: |
171
+ Summarize the given text, beginning with " Summary -" :
172
+ < text>
173
+ {% raw %}{{input}}{% endraw %}
174
+ < /text>
175
+ testData:
176
+ - input: |
177
+ The quick brown fox jumped over the lazy dog.
178
+ The dog was too tired to react.
179
+ expected: Summary - A fox jumped over a lazy, unresponsive dog.
180
+ - input: |
181
+ The museum opened a new dinosaur exhibit this weekend. Families from all
182
+ over the city came to see the life-sized fossils and interactive displays.
183
+ expected: Summary - The museum' s new dinosaur exhibit attracted many families with its fossils and interactive displays.
184
+ evaluators:
185
+ - name: Output should start with ' Summary -'
186
+ string:
187
+ startsWith: ' Summary -'
188
+ - name: Similarity
189
+ uses: github/similarity
190
+ ```
181
191
182
192
1. Commit and push the file to your repository.
183
193
0 commit comments