Gh_models - Github models for Rust

gh_models is a Rust crate providing a simple interface to the GitHub Models API. It enables calling GitHub-hosted AI models from Rust, similar to OpenAI’s Python client.

Installation

Add to Cargo.toml:

gh_models = "0.1.0"

Authentication

Set a GitHub personal access token with model access as an environment variable:

export GITHUB_TOKEN=your_token_here

How to generate a token:
GitHub PAT documentation

Make sure when making a token you set the Models account permission:

Usage Example

use gh_models::{GHModels, types::ChatMessage};
use std::env;

#[tokio::main]
async fn main() {
    let token = env::var("GITHUB_TOKEN").expect("GITHUB_TOKEN not set");
    let client = GHModels::new(token);

    let messages = vec![
        ChatMessage { role: "system".into(), content: "You are a helpful assistant.".into() },
        ChatMessage { role: "user".into(), content: "What is the capital of France?".into() },
    ];

    let response = client.chat_completion("openai/gpt-4o", messages, 1.0, 4096, 1.0).await.unwrap();
    println!("{}", response.choices[0].message.content);
}

Links

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.