use reqwest::Client;
use serde_json::Value;
use crate::transport::{
CallOptions, ClientOptions, HttpTransport, InfraClientError, ServiceEndpoint,
};
const CHAT_COMPLETIONS_PATH: &str = "/v1/model/chat/completions";
const RESPONSES_PATH: &str = "/v1/model/responses";
const MODELS_PATH: &str = "/v1/model/models";
const SERVICE_NAME: &str = "agent-model-infra";
const AUDIENCE: &str = "agent-model-infra";
#[derive(Clone, Debug)]
pub struct ModelClient {
transport: HttpTransport,
}
impl ModelClient {
pub(crate) fn new_with_endpoint(
http: Client,
endpoint: ServiceEndpoint,
options: ClientOptions,
) -> Self {
let endpoint = endpoint.with_default_credential_audience(AUDIENCE);
Self {
transport: HttpTransport::new_with_options(http, SERVICE_NAME, endpoint, options),
}
}
pub async fn chat_completions(
&self,
request: &Value,
options: CallOptions,
) -> Result<Value, InfraClientError> {
self.transport
.post_json_with_options(CHAT_COMPLETIONS_PATH, request, options)
.await
}
pub async fn responses(
&self,
request: &Value,
options: CallOptions,
) -> Result<Value, InfraClientError> {
self.transport
.post_json_with_options(RESPONSES_PATH, request, options)
.await
}
pub async fn models(&self) -> Result<Value, InfraClientError> {
self.transport.get_json(MODELS_PATH).await
}
}