Skip to content

Commit 4e871bb

Browse files
authored
Merge pull request #28 from github/switch-to-github-models-api
Switch to GitHub models API for embeddings requests
2 parents 273874f + 393fcee commit 4e871bb

File tree

10 files changed

+28
-24
lines changed

10 files changed

+28
-24
lines changed

.env-sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# get your pat token from: https://github.com/settings/tokens?type=beta
2+
# if creating a new token, ensure it has `models: read` permissions
23
GITHUB_TOKEN="github_pat_****"

cookbooks/python/llamaindex/rag_getting_started.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
" raise ValueError(\"GITHUB_TOKEN is not set\")\n",
6161
"\n",
6262
"os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"GITHUB_TOKEN\")\n",
63-
"os.environ[\"OPENAI_BASE_URL\"] = \"https://models.inference.ai.azure.com/\""
63+
"os.environ[\"OPENAI_BASE_URL\"] = \"https://models.github.ai/inference\""
6464
]
6565
},
6666
{

samples/js/azure_ai_inference/embeddings.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { isUnexpected } from "@azure-rest/ai-inference";
33
import { AzureKeyCredential } from "@azure/core-auth";
44

55
const token = process.env["GITHUB_TOKEN"];
6-
const endpoint = "https://models.inference.ai.azure.com";
6+
const endpoint = "https://models.github.ai/inference";
77

88
/* By using the Azure AI Inference SDK, you can easily experiment with different models
99
by modifying the value of `modelName` in the code below. For this code sample
@@ -32,9 +32,9 @@ export async function main() {
3232
for (const item of response.body.data) {
3333
let length = item.embedding.length;
3434
console.log(
35-
`data[${item.index}]: length=${length}, ` +
36-
`[${item.embedding[0]}, ${item.embedding[1]}, ` +
37-
`..., ${item.embedding[length - 2]}, ${item.embedding[length -1]}]`);
35+
`data[${item.index}]: length=${length}, ` +
36+
`[${item.embedding[0]}, ${item.embedding[1]}, ` +
37+
`..., ${item.embedding[length - 2]}, ${item.embedding[length - 1]}]`);
3838
}
3939
console.log(response.body.usage);
4040
}

samples/js/openai/embeddings.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import OpenAI from "openai";
22

33
const token = process.env["GITHUB_TOKEN"];
4-
const endpoint = "https://models.inference.ai.azure.com";
4+
const endpoint = "https://models.github.ai/inference";
55

66
/* Pick one of the OpenAI embeddings models from the GitHub Models service */
77
const modelName = "text-embedding-3-small";
@@ -11,16 +11,16 @@ export async function main() {
1111
const client = new OpenAI({ baseURL: endpoint, apiKey: token });
1212

1313
const response = await client.embeddings.create({
14-
input: ["first phrase", "second phrase", "third phrase"],
15-
model: modelName
14+
input: ["first phrase", "second phrase", "third phrase"],
15+
model: modelName
1616
});
1717

1818
for (const item of response.data) {
19-
let length = item.embedding.length;
20-
console.log(
21-
`data[${item.index}]: length=${length}, ` +
22-
`[${item.embedding[0]}, ${item.embedding[1]}, ` +
23-
`..., ${item.embedding[length - 2]}, ${item.embedding[length -1]}]`);
19+
let length = item.embedding.length;
20+
console.log(
21+
`data[${item.index}]: length=${length}, ` +
22+
`[${item.embedding[0]}, ${item.embedding[1]}, ` +
23+
`..., ${item.embedding[length - 2]}, ${item.embedding[length - 1]}]`);
2424
}
2525
console.log(response.usage);
2626
}

samples/python/azure_ai_inference/embeddings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
from azure.core.credentials import AzureKeyCredential
55

66
token = os.environ["GITHUB_TOKEN"]
7-
endpoint = "https://models.inference.ai.azure.com"
7+
endpoint = "https://models.github.ai/inference"
88

99
# By using the Azure AI Inference SDK, you can easily experiment with different models
1010
# by modifying the value of `modelName` in the code below. For this code sample
1111
# you need an embedding model. The following embedding models are
1212
# available in the GitHub Models service:
13-
#
13+
#
1414
# Cohere: Cohere-embed-v3-english, Cohere-embed-v3-multilingual
1515
# Azure OpenAI: text-embedding-3-small, text-embedding-3-large
1616
model_name = "text-embedding-3-small"

samples/python/azure_ai_inference/getting_started.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
" raise ValueError(\"GITHUB_TOKEN is not set\")\n",
5959
"\n",
6060
"github_token = os.environ[\"GITHUB_TOKEN\"]\n",
61-
"endpoint = \"https://models.inference.ai.azure.com\"\n",
61+
"endpoint = \"https://models.github.ai/inference\"\n",
6262
"\n",
6363
"\n",
6464
"# Create a client\n",
@@ -117,7 +117,7 @@
117117
" # Optional parameters\n",
118118
" temperature=1.,\n",
119119
" max_tokens=1000,\n",
120-
" top_p=1. \n",
120+
" top_p=1.\n",
121121
")\n",
122122
"\n",
123123
"print(response.choices[0].message.content)"

samples/python/mistralai/getting_started.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
" raise ValueError(\"GITHUB_TOKEN is not set\")\n",
5959
"\n",
6060
"github_token = os.environ[\"GITHUB_TOKEN\"]\n",
61-
"endpoint = \"https://models.inference.ai.azure.com\"\n",
61+
"endpoint = \"https://models.github.ai/inference\"\n",
6262
"\n",
6363
"# Pick one of the Mistral models from the GitHub Models service\n",
6464
"model_name = \"Mistral-large\"\n",
@@ -99,7 +99,7 @@
9999
" # Optional parameters\n",
100100
" temperature=1.,\n",
101101
" max_tokens=1000,\n",
102-
" top_p=1. \n",
102+
" top_p=1.\n",
103103
")\n",
104104
"\n",
105105
"print(response.choices[0].message.content)"

samples/python/openai/embeddings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from openai import OpenAI
33

44
token = os.environ["GITHUB_TOKEN"]
5-
endpoint = "https://models.inference.ai.azure.com"
5+
endpoint = "https://models.github.ai/inference"
66

77
# Pick one of the OpenAI embeddings models from the GitHub Models service
88
model_name = "text-embedding-3-small"

samples/python/openai/embeddings_getting_started.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
" raise ValueError(\"GITHUB_TOKEN is not set\")\n",
5656
"\n",
5757
"os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"GITHUB_TOKEN\")\n",
58-
"os.environ[\"OPENAI_BASE_URL\"] = \"https://models.inference.ai.azure.com/\"\n",
58+
"os.environ[\"OPENAI_BASE_URL\"] = \"https://models.github.ai/inference\"\n",
5959
"\n",
6060
"client = OpenAI()\n"
6161
]
@@ -77,7 +77,7 @@
7777
"metadata": {},
7878
"outputs": [],
7979
"source": [
80-
"model_name = \"text-embedding-3-small\" \n",
80+
"model_name = \"text-embedding-3-small\"\n",
8181
"\n",
8282
"response = client.embeddings.create(\n",
8383
" model=model_name,\n",
@@ -105,7 +105,7 @@
105105
"metadata": {},
106106
"outputs": [],
107107
"source": [
108-
"model_name = \"text-embedding-3-small\" \n",
108+
"model_name = \"text-embedding-3-small\"\n",
109109
"inputs = [\"Hello, world!\", \"How are you?\", \"What's the weather like?\"]\n",
110110
"\n",
111111
"response = client.embeddings.create(\n",

samples/python/openai/multi_turn.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
client = OpenAI(
1717
base_url=endpoint,
1818
api_key=token,
19+
default_headers={
20+
"x-ms-useragent": "github-models-sample",
21+
}
1922
)
2023

2124
# Call the chat completion API
@@ -42,4 +45,4 @@
4245
)
4346

4447
# Print the response
45-
print(response.choices[0].message.content)
48+
print(response.choices[0].message.content)

0 commit comments

Comments
 (0)