はじめに
GitHub Models は GitHub の AI 推論 API であり、GitHub の資格情報のみを使って AI モデルを実行できます。 認証プロセスを別に行わなくても、OpenAI、Meta、DeepSeek などの多くのさまざまなモデルから選んで、スクリプト、アプリ、さらには GitHub Actions でも使用できます。
このガイドでは、プレイグラウンドでモデルをすばやく試す方法を説明してから、API またはワークフローを使って初めてのモデルを実行する方法を示します。
ステップ 1: プレイグラウンドでモデルを試す
-
「 https://github.com/marketplace/models 」を参照してください。
-
プレイグラウンドで、ドロップダウン メニューから少なくとも 1 つのモデルを選びます。
-
[Chat] ビューを使ってさまざまなプロンプトをテストし、異なるモデルからの応答を比較します。
-
[Parameters] ビューを使って、テストしているモデルのパラメーターをカスタマイズし、それらが応答にどのように影響するか確認します。
メモ
GitHub にサインインしている場合は、プレイグラウンドをすぐに使えます。 そのアクセスにはユーザーの GitHub アカウントが使われ、セットアップや API キーは必要ありません。
ステップ 2: API 呼び出しを行う
使用できるフィールド、ヘッダー、要求の形式について詳しくは、GitHub Models の API リファレンスをご覧ください。
プログラムでモデルを呼び出すには、次のものが必要です。
- GitHub アカウント。
models
スコープの personal access token (PAT)。これは、設定で作成できます。
-
次の
curl
コマンドを実行します。YOUR_GITHUB_PAT
はご自分のトークンに置き換えます。Bash curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer YOUR_GITHUB_PAT" \ -H "X-GitHub-Api-Version: 2022-11-28" \ -H "Content-Type: application/json" \ https://models.github.ai/inference/chat/completions \ -d '{"model":"openai/gpt-4.1","messages":[{"role":"user","content":"What is the capital of France?"}]}'
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer YOUR_GITHUB_PAT" \ -H "X-GitHub-Api-Version: 2022-11-28" \ -H "Content-Type: application/json" \ https://models.github.ai/inference/chat/completions \ -d '{"model":"openai/gpt-4.1","messages":[{"role":"user","content":"What is the capital of France?"}]}'
-
次のような応答を受け取ります。
{ "choices": [ { "message": { "role": "assistant", "content": "The capital of France is **Paris**." } } ], ...other fields omitted }
-
他のモデルを試すには、JSON ペイロードの
model
フィールドの値を、マーケットプレースのものに変更します。
ステップ 3: GitHub Actions でモデルを実行する
-
リポジトリで、
.github/workflows/models-demo.yml
にワークフロー ファイルを作成します。 -
作成したファイルに次のワークフローを貼り付けます。
YAML name: Use GitHub Models on: [push] permissions: models: read jobs: call-model: runs-on: ubuntu-latest steps: - name: Call AI model env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | curl "https://models.github.ai/inference/chat/completions" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $GITHUB_TOKEN" \ -d '{ "messages": [ { "role": "user", "content": "Explain the concept of recursion." } ], "model": "openai/gpt-4o" }'
name: Use GitHub Models on: [push] permissions: models: read jobs: call-model: runs-on: ubuntu-latest steps: - name: Call AI model env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | curl "https://models.github.ai/inference/chat/completions" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $GITHUB_TOKEN" \ -d '{ "messages": [ { "role": "user", "content": "Explain the concept of recursion." } ], "model": "openai/gpt-4o" }'
メモ
GitHub Models を呼び出すワークフローのアクセス許可ブロックには、
models: read
を含める必要があります。 GitHub ホステッド ランナーによって、GITHUB_TOKEN
が自動的に提供されます。 -
コミットしてプッシュし、ワークフローをトリガーします。
この例では、プロンプトをモデルに送信し、継続的インテグレーション (CI) ワークフローで応答を使用する方法を示します。 Issue の要約、バグ レポートに足りない再現手順の検出、pull request への応答など、より高度なユース ケースについては、「AI モデルを開発ワークフローに統合する」をご覧ください。
ステップ 4: 最初のプロンプト ファイルを保存する
GitHub Models では、.prompt.yml
ファイルで定義された再利用可能なプロンプトがサポートされています。 このファイルをリポジトリに追加すると、リポジトリの [Models] ページに表示され、プロンプト エディターと評価ツールで直接実行できます。 詳しくは、「Storing prompts in GitHub repositories」をご覧ください。
-
リポジトリで、
summarize.prompt.yml
という名前のファイルを作成します。 任意のディレクトリにそれを保存できます。 -
作成したファイルに次のプロンプト例を貼り付けます。
YAML name: Text Summarizer description: Summarizes input text concisely model: gpt-4o-mini modelParameters: temperature: 0.5 messages: - role: system content: You are a text summarizer. Your only job is to summarize text given to you. - role: user content: | Summarize the given text, beginning with "Summary -": <text> {{input}} </text>
name: Text Summarizer description: Summarizes input text concisely model: gpt-4o-mini modelParameters: temperature: 0.5 messages: - role: system content: You are a text summarizer. Your only job is to summarize text given to you. - role: user content: | Summarize the given text, beginning with "Summary -": <text> {{input}} </text>
-
ファイルをコミットしてリポジトリにプッシュします。
-
リポジトリの [Models] タブに移動します。
-
ナビゲーション メニューの [ Prompts] をクリックし、プロンプト ファイルをクリックします。
-
プロンプト エディターでプロンプトが開きます。 [実行] をクリックします。 右側にサイドバーが表示され、入力テキストの入力を求められます。 入力テキストを入力し、右下隅の [Run] をもう一度クリックしてテストします。
メモ
プロンプト エディターでは、リポジトリの内容はプロンプトに自動的に渡されません。 入力は手動で指定します。
ステップ 5: 最初の評価を設定する
評価は、異なるモデルが同じ入力にどのように応答するかを測定するのに役立ち、ユース ケースに最適なものを選択できます。
-
前のステップで作成した
summarize.prompt.yml
ファイルに戻ります。 -
次の例と一致するようにファイルを更新します。
YAML name: Text Summarizer description: Summarizes input text concisely model: gpt-4o-mini modelParameters: temperature: 0.5 messages: - role: system content: You are a text summarizer. Your only job is to summarize text given to you. - role: user content: | Summarize the given text, beginning with "Summary -": <text> {{input}} </text> testData: - input: | The quick brown fox jumped over the lazy dog. The dog was too tired to react. expected: Summary - A fox jumped over a lazy, unresponsive dog. - input: | The museum opened a new dinosaur exhibit this weekend. Families from all over the city came to see the life-sized fossils and interactive displays. expected: Summary - The museum's new dinosaur exhibit attracted many families with its fossils and interactive displays. evaluators: - name: Output should start with 'Summary -' string: startsWith: 'Summary -' - name: Similarity uses: github/similarity
name: Text Summarizer description: Summarizes input text concisely model: gpt-4o-mini modelParameters: temperature: 0.5 messages: - role: system content: You are a text summarizer. Your only job is to summarize text given to you. - role: user content: | Summarize the given text, beginning with "Summary -": <text> {{input}} </text> testData: - input: | The quick brown fox jumped over the lazy dog. The dog was too tired to react. expected: Summary - A fox jumped over a lazy, unresponsive dog. - input: | The museum opened a new dinosaur exhibit this weekend. Families from all over the city came to see the life-sized fossils and interactive displays. expected: Summary - The museum's new dinosaur exhibit attracted many families with its fossils and interactive displays. evaluators: - name: Output should start with 'Summary -' string: startsWith: 'Summary -' - name: Similarity uses: github/similarity
-
ファイルをコミットしてリポジトリにプッシュします。
-
リポジトリで [Models] タブをクリックします。次に、[ Prompts] をクリックして、プロンプト エディターで同じプロンプトをもう一度開きます。
-
左上隅で、ビューを [Edit] から [Compare] に切り替えることができます。 [比較] をクリックします。
-
評価は自動的に設定されます。 [Run] をクリックして、結果を表示します。
ヒント
[Add prompt] をクリックすると、同じプロンプトを異なるモデルで実行したり、プロンプトの表現を変更したりして、複数のバリエーションを含む推論応答を一度に取得し、評価を並べて表示して、データ主導のモデルの決定を行うことができます。