はじめに
GitHub Modelsは、GitHub資格情報のみを使用して AI モデルを実行できる、GitHubの AI 推論 API です。 OpenAI、Meta、DeepSeek など、さまざまなモデルから選択し、個別の認証プロセスなしでスクリプト、アプリ、または GitHub Actionsで使用できます。
このガイドでは、プレイグラウンドでモデルをすばやく試す方法を説明してから、API またはワークフローを使って初めてのモデルを実行する方法を示します。
ステップ 1: プレイグラウンドでモデルを試す
-
** [ https://github.com/marketplace/models ](https://github.com/marketplace/models) ** に移動します。 -
プレイグラウンドで、ドロップダウン メニューから少なくとも 1 つのモデルを選びます。
-
**[Chat]** ビューを使ってさまざまなプロンプトをテストし、異なるモデルからの応答を比較します。 -
**[Parameters]** ビューを使って、テストしているモデルのパラメーターをカスタマイズし、それらが応答にどのように影響するか確認します。メモ
GitHubにサインインしている場合、プレイグラウンドはすぐに使用できます。 アクセスには GitHub アカウントが使用されます。セットアップキーや API キーは必要ありません。
ステップ 2: API 呼び出しを行う
使用可能なフィールド、ヘッダー、および要求形式の詳細については、GitHub Modelsの API リファレンスを参照してください。
プログラムでモデルを呼び出すには、次のものが必要です。
-
GitHub のアカウント。 -
personal access token作成できる`models` スコープを持つ[](https://github.com/settings/tokens) (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フィールドの値を marketplace の値に変更します。
手順 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) ワークフローで応答を使用する方法を示します。 問題の要約、バグ レポートの不足している再現手順の検出、プル要求への応答など、より高度なユース ケースについては、GitHub Copilot での AI モデルへのaccessの構成 を参照してください。
ステップ 4: 最初のプロンプト ファイルを保存する
GitHub Models では、 `.prompt.yml` ファイルで定義されている再利用可能なプロンプトがサポートされます。 このファイルをリポジトリに追加すると、リポジトリの [Models] ページに表示され、プロンプト エディターと評価ツールで直接実行できます。 詳細については、[AUTOTITLE](/github-models/use-github-models/storing-prompts-in-github-repositories) を参照してください。
-
リポジトリで、
summarize.prompt.ymlという名前のファイルを作成します。 任意のディレクトリにそれを保存できます。 -
作成したファイルに次のプロンプト例を貼り付けます。
YAML name: Text Summarizer description: Summarizes input text concisely model: openai/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: openai/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] タブに移動します。
-
ナビゲーション メニューで、 プロンプト をクリックし、その後、プロンプト ファイルをクリックします。
-
プロンプト エディターでプロンプトが開きます。 [実行] をクリックします。 右側にサイドバーが表示され、入力テキストの入力を求められます。 入力テキストを入力し、右下隅の [Run] をもう一度クリックしてテストします。
メモ
プロンプト エディターでは、リポジトリの内容はプロンプトに自動的に渡されません。 入力は手動で指定します。
ステップ 5: 最初の評価を設定する
評価は、異なるモデルが同じ入力にどのように応答するかを測定するのに役立ち、ユース ケースに最適なものを選択できます。
-
前の手順で作成した
summarize.prompt.ymlファイルに戻ります。 -
次の例と一致するようにファイルを更新します。
YAML name: Text Summarizer description: Summarizes input text concisely model: openai/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/similarityname: Text Summarizer description: Summarizes input text concisely model: openai/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 -
ファイルをコミットしてリポジトリにプッシュします。
-
リポジトリで、[モデル] タブをクリックします。次に、[プロンプト] をクリックして、プロンプトエディターで同じプロンプトを再度開きます。
-
左上隅で、ビューを [Edit] から [Compare] に切り替えることができます。 [比較] をクリックします。
-
評価は自動的に設定されます。 [Run] をクリックして、結果を表示します。
ヒント
**[Add prompt]** をクリックすると、同じプロンプトを異なるモデルで実行したり、プロンプトの表現を変更したりして、複数のバリエーションを含む推論応答を一度に取得し、評価を並べて表示して、データ主導のモデルの決定を行うことができます。
次のステップ
-
[AUTOTITLE](/github-models/about-github-models)。 -
[モデル カタログを参照します](https://github.com/marketplace?type=models) -
[AUTOTITLE](/github-models/use-github-models/storing-prompts-in-github-repositories) -
[AUTOTITLE](/github-models/use-github-models/evaluating-ai-models) -
[AUTOTITLE](/github-models/use-github-models/integrating-ai-models-into-your-development-workflow#using-ai-models-with-github-actions)