refactor: user config models replace client builtin models

pull/462/head
sigoden 1 month ago
parent 602494b650
commit 3a00fb283e

@ -129,8 +129,9 @@ clients:
# - anyscale: https://docs.anyscale.com/endpoints/model-serving/openai-migration-guide
# - deepinfra: https://deepinfra.com/docs/advanced/openai_api
# - fireworks: https://readme.fireworks.ai/docs/openai-compatibility
# - together: https://docs.together.ai/docs/openai-api-compatibility
# - together.ai: https://docs.together.ai/docs/openai-api-compatibility
# - huggingface: https://huggingface.co/docs/text-generation-inference/messages_api
# - OctoAI: https://octo.ai/docs/text-gen-solution/migration-from-openai
- type: openai-compatible
name: localai
api_base: http://localhost:8080/v1

@ -89,15 +89,19 @@ macro_rules! register_client {
pub fn list_models(local_config: &$config) -> Vec<Model> {
let client_name = Self::name(local_config);
for model in $crate::client::CLIENT_MODELS.iter() {
match model {
$crate::client::ClientModel::$config { models } => {
return Model::from_config(client_name, &local_config.models, models);
if local_config.models.is_empty() {
for model in $crate::client::CLIENT_MODELS.iter() {
match model {
$crate::client::ClientModel::$config { models } => {
return Model::from_config(client_name, models);
}
_ => {}
}
_ => {}
}
vec![]
} else {
Model::from_config(client_name, &local_config.models)
}
vec![]
}
pub fn name(config: &$config) -> &str {

@ -3,7 +3,6 @@ use super::message::{Message, MessageContent};
use crate::utils::count_tokens;
use anyhow::{bail, Result};
use indexmap::IndexMap;
use serde::Deserialize;
const PER_MESSAGES_TOKENS: usize = 5;
@ -37,17 +36,9 @@ impl Model {
}
}
pub fn from_config(
client_name: &str,
config_models: &[ModelConfig],
client_models: &[ModelConfig],
) -> Vec<Self> {
let mut models = IndexMap::new();
for model in client_models.iter().chain(config_models.iter()) {
models.insert(&model.name, model);
}
pub fn from_config(client_name: &str, models: &[ModelConfig]) -> Vec<Self> {
models
.values()
.iter()
.map(|v| {
Model::new(client_name, &v.name)
.set_max_input_tokens(v.max_input_tokens)

Loading…
Cancel
Save