Skip to content

Switch to GitHub models API for embeddings requests #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env-sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# get your pat token from: https://github.com/settings/tokens?type=beta
# if creating a new token, ensure it has `models: read` permissions
GITHUB_TOKEN="github_pat_****"
2 changes: 1 addition & 1 deletion cookbooks/python/llamaindex/rag_getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
" raise ValueError(\"GITHUB_TOKEN is not set\")\n",
"\n",
"os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"GITHUB_TOKEN\")\n",
"os.environ[\"OPENAI_BASE_URL\"] = \"https://models.inference.ai.azure.com/\""
"os.environ[\"OPENAI_BASE_URL\"] = \"https://models.github.ai/inference\""
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions samples/js/azure_ai_inference/embeddings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isUnexpected } from "@azure-rest/ai-inference";
import { AzureKeyCredential } from "@azure/core-auth";

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

/* By using the Azure AI Inference SDK, you can easily experiment with different models
by modifying the value of `modelName` in the code below. For this code sample
Expand Down Expand Up @@ -32,9 +32,9 @@ export async function main() {
for (const item of response.body.data) {
let length = item.embedding.length;
console.log(
`data[${item.index}]: length=${length}, ` +
`[${item.embedding[0]}, ${item.embedding[1]}, ` +
`..., ${item.embedding[length - 2]}, ${item.embedding[length -1]}]`);
`data[${item.index}]: length=${length}, ` +
`[${item.embedding[0]}, ${item.embedding[1]}, ` +
`..., ${item.embedding[length - 2]}, ${item.embedding[length - 1]}]`);
}
console.log(response.body.usage);
}
Expand Down
16 changes: 8 additions & 8 deletions samples/js/openai/embeddings.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import OpenAI from "openai";

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

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

const response = await client.embeddings.create({
input: ["first phrase", "second phrase", "third phrase"],
model: modelName
input: ["first phrase", "second phrase", "third phrase"],
model: modelName
});

for (const item of response.data) {
let length = item.embedding.length;
console.log(
`data[${item.index}]: length=${length}, ` +
`[${item.embedding[0]}, ${item.embedding[1]}, ` +
`..., ${item.embedding[length - 2]}, ${item.embedding[length -1]}]`);
let length = item.embedding.length;
console.log(
`data[${item.index}]: length=${length}, ` +
`[${item.embedding[0]}, ${item.embedding[1]}, ` +
`..., ${item.embedding[length - 2]}, ${item.embedding[length - 1]}]`);
}
console.log(response.usage);
}
Expand Down
4 changes: 2 additions & 2 deletions samples/python/azure_ai_inference/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from azure.core.credentials import AzureKeyCredential

token = os.environ["GITHUB_TOKEN"]
endpoint = "https://models.inference.ai.azure.com"
endpoint = "https://models.github.ai/inference"

# By using the Azure AI Inference SDK, you can easily experiment with different models
# by modifying the value of `modelName` in the code below. For this code sample
# you need an embedding model. The following embedding models are
# available in the GitHub Models service:
#
#
# Cohere: Cohere-embed-v3-english, Cohere-embed-v3-multilingual
# Azure OpenAI: text-embedding-3-small, text-embedding-3-large
model_name = "text-embedding-3-small"
Expand Down
4 changes: 2 additions & 2 deletions samples/python/azure_ai_inference/getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
" raise ValueError(\"GITHUB_TOKEN is not set\")\n",
"\n",
"github_token = os.environ[\"GITHUB_TOKEN\"]\n",
"endpoint = \"https://models.inference.ai.azure.com\"\n",
"endpoint = \"https://models.github.ai/inference\"\n",
"\n",
"\n",
"# Create a client\n",
Expand Down Expand Up @@ -117,7 +117,7 @@
" # Optional parameters\n",
" temperature=1.,\n",
" max_tokens=1000,\n",
" top_p=1. \n",
" top_p=1.\n",
")\n",
"\n",
"print(response.choices[0].message.content)"
Expand Down
4 changes: 2 additions & 2 deletions samples/python/mistralai/getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
" raise ValueError(\"GITHUB_TOKEN is not set\")\n",
"\n",
"github_token = os.environ[\"GITHUB_TOKEN\"]\n",
"endpoint = \"https://models.inference.ai.azure.com\"\n",
"endpoint = \"https://models.github.ai/inference\"\n",
"\n",
"# Pick one of the Mistral models from the GitHub Models service\n",
"model_name = \"Mistral-large\"\n",
Expand Down Expand Up @@ -99,7 +99,7 @@
" # Optional parameters\n",
" temperature=1.,\n",
" max_tokens=1000,\n",
" top_p=1. \n",
" top_p=1.\n",
")\n",
"\n",
"print(response.choices[0].message.content)"
Expand Down
2 changes: 1 addition & 1 deletion samples/python/openai/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from openai import OpenAI

token = os.environ["GITHUB_TOKEN"]
endpoint = "https://models.inference.ai.azure.com"
endpoint = "https://models.github.ai/inference"

# Pick one of the OpenAI embeddings models from the GitHub Models service
model_name = "text-embedding-3-small"
Expand Down
6 changes: 3 additions & 3 deletions samples/python/openai/embeddings_getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
" raise ValueError(\"GITHUB_TOKEN is not set\")\n",
"\n",
"os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"GITHUB_TOKEN\")\n",
"os.environ[\"OPENAI_BASE_URL\"] = \"https://models.inference.ai.azure.com/\"\n",
"os.environ[\"OPENAI_BASE_URL\"] = \"https://models.github.ai/inference\"\n",
"\n",
"client = OpenAI()\n"
]
Expand All @@ -77,7 +77,7 @@
"metadata": {},
"outputs": [],
"source": [
"model_name = \"text-embedding-3-small\" \n",
"model_name = \"text-embedding-3-small\"\n",
"\n",
"response = client.embeddings.create(\n",
" model=model_name,\n",
Expand Down Expand Up @@ -105,7 +105,7 @@
"metadata": {},
"outputs": [],
"source": [
"model_name = \"text-embedding-3-small\" \n",
"model_name = \"text-embedding-3-small\"\n",
"inputs = [\"Hello, world!\", \"How are you?\", \"What's the weather like?\"]\n",
"\n",
"response = client.embeddings.create(\n",
Expand Down
5 changes: 4 additions & 1 deletion samples/python/openai/multi_turn.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
client = OpenAI(
base_url=endpoint,
api_key=token,
default_headers={
"x-ms-useragent": "github-models-sample",
}
)

# Call the chat completion API
Expand All @@ -42,4 +45,4 @@
)

# Print the response
print(response.choices[0].message.content)
print(response.choices[0].message.content)
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy