Skip to content

eniompw/GitHubModels

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Jan 15, 2025
5e33f3c · Jan 15, 2025

History

15 Commits
Jan 15, 2025
Jan 15, 2025
Jan 15, 2025
Jan 15, 2025
Jan 15, 2025

Repository files navigation

GitHubModels

A Python package demonstrating different methods of interacting with Azure OpenAI models through both the OpenAI SDK and REST API.

Setup

  1. Install dependencies:
pip install openai requests
  1. Set your API token:
export GITHUB_TOKEN="<your-api-token-goes-here>"

Usage

Using the OpenAI SDK (sdk_client.py)

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://models.inference.ai.azure.com",
    api_key=os.environ["GITHUB_TOKEN"],
)

response = client.chat.completions.create(
    messages=[{"role": "user", "content": "Your question here"}],
    model="gpt-4o"
)

print(response.choices[0].message.content)

Using REST API (rest.py)

import requests
import os

url = "https://models.inference.ai.azure.com/chat/completions"
headers = {"Authorization": "Bearer " + str(os.environ.get("GITHUB_TOKEN"))}
data = {"messages": [{"role": "user", "content": "Your question here"}], "model": "gpt-4o"}

response = requests.post(url, headers=headers, json=data)
print(response.json()["choices"][0]["message"]["content"])

Image Analysis (images.py)

The package also supports image analysis using GPT-4o's vision capabilities. You can provide either a local image path or an image URL:

# Example usage:
python images.py
# When prompted, enter either:
# - A local file path (e.g., "images/photo.jpg")
# - An image URL (e.g., "https://example.com/image.jpg")

The script will analyze the image and provide a description of its contents.

Project Structure

  • sdk_client.py: OpenAI SDK implementation
  • rest.py: REST API implementation
  • images.py: Image analysis implementation using the REST API

References

For more information about the GPT-4o model and its capabilities, see the Azure OpenAI GPT-4o Marketplace listing.

License

This project is licensed under the MIT License - see the LICENSE file for details.