[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/1010code/github-models-tutorial/main/basic.ipynb [Back]  [Original]

{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "975684f2-ad7a-4986-b4c4-50b8578e0223",
   "metadata": {},
   "source": [
    "## GitHub Models \n",
    " OpenAI  Chat Completion API GitHub  AI  GitHub Token \n",
    "\n",
    "### \n",
    "####   GitHub API Token\n",
    "**1. GitHub Personal Access Token (PAT)**\n",
    "-  [GitHub Settings](https://github.com/settings/personal-access-tokens)\n",
    "-  Developer settings > Personal access tokens > Fine-grained tokens\n",
    "\n",
    "![](https://cdn-images-1.medium.com/max/800/1*JhvMmQ5v3PbQzYl04plAaQ.png)\n",
    "    \n",
    "-  Generate new token Public Repositories (read-only) \n",
    "-  Token \n",
    "\n",
    "![](https://cdn-images-1.medium.com/max/800/1*JcZ2NVNRj4-ViXmIOYo6uQ.png)\n",
    "\n",
    "####   Colab Secrets\n",
    " Token Colab Secrets dotenv\n",
    "\n",
    " Google Colab  Secrets\n",
    "-  + Add new secret\n",
    "- Name  GITHUB_TOKEN\n",
    "- Value  GitHub  Token\n",
    "- access Colab \n",
    "\n",
    "![](https://cdn-images-1.medium.com/max/800/1*k4y8ac_Gyewrjf-n1PvL0w.png)\n",
    "\n",
    "##   Google Colab  API \n",
    " GitHub Token GitHub Models API  GPT-4o  LLM  Google Colab  Secrets  GITHUB_TOKEN OpenAI   GitHub Models "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d72e1069-b21f-4902-b902-716c826bf078",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import os\n",
    "from openai import OpenAI\n",
    "from google.colab import userdata\n",
    "\n",
    "#  GitHub  Personal Access Token (PAT)\n",
    "#  GitHub  PAT\n",
    "# https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens\n",
    "client = OpenAI(\n",
    "    base_url=\"https://models.inference.ai.azure.com\",  #  API  URL\n",
    "    api_key=userdata.get('GITHUB_TOKEN'),  #  Google Colab  GitHub Token\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0d454c97-abe2-459c-a37b-b3bbb391499f",
   "metadata": {},
   "source": [
    "  (chat completion request) System Prompt AI AI  ( TemperatureMax TokensTop P) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "110d8b1e-d4cb-4238-b634-39c5d8ccf794",
   "metadata": {},
   "outputs": [],
   "source": [
    "# \n",
    "response = client.chat.completions.create(\n",
    "    messages=[\n",
    "        {\n",
    "            \"role\": \"system\",\n",
    "            \"content\": \"\",  #  AI \n",
    "        },\n",
    "        {\n",
    "            \"role\": \"user\",\n",
    "            \"content\": \"\",  # \n",
    "        }\n",
    "    ],\n",
    "    model=\"gpt-4o\",  #  AI  GPT-4o\n",
    "    temperature=1,  # 1 \n",
    "    max_tokens=4096,  #  Token \n",
    "    top_p=1  #  Top-p\n",
    ")\n",
    "\n",
    "#  AI \n",
    "print(response.choices[0].message.content)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56db8f92-21b8-45f7-8dea-e2308ce70b6d",
   "metadata": {},
   "source": [
    " Colab + GitHub Models API  LLM  model  DeepSeek-R1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b9b80434-a72b-48a8-8dbc-cd7d035bbaa2",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}

Web Proxy Viewer  |  New URL  |  Original Page