Skip to content
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

Add display capabilities to python objects #594

Open
wants to merge 2 commits into
base: master
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
53 changes: 53 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mistralrs-pyo3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tokio.workspace = true
image.workspace = true
reqwest.workspace = true
base64.workspace = true
pyo3_special_method_derive = "0.4.1"

[build-dependencies]
pyo3-build-config = "0.22"
Expand Down
5 changes: 3 additions & 2 deletions mistralrs-pyo3/src/anymoe.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use pyo3::{pyclass, pymethods};
use pyo3_special_method_derive::{Dict, Dir, Getattr, Repr, Str};

#[pyclass]
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Str, Repr, Dir, Dict, Getattr)]

Check failure on line 5 in mistralrs-pyo3/src/anymoe.rs

View workflow job for this annotation

GitHub Actions / Check (macOS-latest, stable)

type annotations needed

Check failure on line 5 in mistralrs-pyo3/src/anymoe.rs

View workflow job for this annotation

GitHub Actions / Clippy

type annotations needed
pub enum AnyMoeExpertType {
FineTuned {},
LoraAdapter {
Expand All @@ -28,7 +29,7 @@
}
}

#[derive(Clone)]
#[derive(Clone, Str, Repr, Dir, Dict, Getattr)]
#[pyclass]
pub struct AnyMoeConfig {
pub(crate) hidden_size: usize,
Expand Down
6 changes: 4 additions & 2 deletions mistralrs-pyo3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use base64::{engine::general_purpose, Engine};
use candle_core::{quantized::GgmlDType, Result};
use either::Either;
use indexmap::IndexMap;
use pyo3_special_method_derive::{Dict, Dir, Getattr, Repr, Str};
use std::{
cell::RefCell,
collections::HashMap,
Expand Down Expand Up @@ -83,6 +84,7 @@ fn parse_isq(s: &str) -> std::result::Result<GgmlDType, String> {
}

#[pyclass]
#[derive(Str, Repr, Dir, Dict, Getattr)]
/// An object wrapping the underlying Rust system to handle requests and process conversations.
struct Runner {
runner: Arc<MistralRs>,
Expand Down Expand Up @@ -890,7 +892,7 @@ impl Runner {
}

#[pyclass]
#[derive(Debug)]
#[derive(Debug, Str, Repr, Dir, Dict, Getattr)]
/// An OpenAI API compatible completion request.
struct CompletionRequest {
_model: String,
Expand Down Expand Up @@ -976,7 +978,7 @@ impl CompletionRequest {
}

#[pyclass]
#[derive(Debug)]
#[derive(Debug, Str, Repr, Dir, Dict, Getattr)]
/// An OpenAI API compatible chat completion request.
struct ChatCompletionRequest {
#[allow(clippy::type_complexity)]
Expand Down
7 changes: 4 additions & 3 deletions mistralrs-pyo3/src/which.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use mistralrs_core::{NormalLoaderType, VisionLoaderType};
use pyo3::pyclass;
use pyo3_special_method_derive::{Dict, Dir, Getattr, Repr, Str};

#[pyclass(eq, eq_int)]
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, PartialEq, Clone, Str, Repr, Dir, Dict, Getattr)]
pub enum Architecture {
Mistral,
Gemma,
Expand Down Expand Up @@ -32,7 +33,7 @@ impl From<Architecture> for NormalLoaderType {
}

#[pyclass(eq, eq_int)]
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, PartialEq, Clone, Str, Repr, Dir, Dict, Getattr)]
pub enum VisionArchitecture {
Phi3V,
Idefics2,
Expand All @@ -52,7 +53,7 @@ impl From<VisionArchitecture> for VisionLoaderType {
}

#[pyclass]
#[derive(Clone)]
#[derive(Clone, Str, Repr, Dir, Dict, Getattr)]
pub enum Which {
#[pyo3(constructor = (
model_id,
Expand Down
Loading