llm-model-config完了

This commit is contained in:
2026-04-20 00:57:27 +09:00
parent 230936274b
commit 5aea67ff5e
19 changed files with 147 additions and 270 deletions
@@ -24,3 +24,17 @@ pub(crate) fn lookup(model_id: &str) -> Option<ModelCapability> {
})
}
/// Scheme 既定の capability。
///
/// Ollama の `/v1/messages` 流用を想定して `cache_control` を送らない
/// `CacheStrategy::Auto` にする。Anthropic 本家の未知モデル(新 Claude)
/// も tool_calling / vision を備える想定で Parallel / true を返す。
pub(crate) fn default_capability() -> ModelCapability {
ModelCapability {
tool_calling: ToolCallingSupport::Parallel,
structured_output: StructuredOutput::JsonSchema,
reasoning: None,
vision: false,
prompt_caching: CacheStrategy::Auto,
}
}
@@ -96,4 +96,8 @@ impl Scheme for AnthropicScheme {
fn capability_for(&self, model_id: &str) -> Option<ModelCapability> {
super::capability::lookup(model_id)
}
fn default_capability(&self) -> ModelCapability {
super::capability::default_capability()
}
}
@@ -4,6 +4,17 @@ use crate::llm_client::capability::{
CacheStrategy, ModelCapability, ReasoningSupport, StructuredOutput, ToolCallingSupport,
};
/// Scheme 既定の capability(未知モデル / 未明示モデル用)。
pub(crate) fn default_capability() -> ModelCapability {
ModelCapability {
tool_calling: ToolCallingSupport::Parallel,
structured_output: StructuredOutput::JsonSchema,
reasoning: None,
vision: true,
prompt_caching: CacheStrategy::Auto,
}
}
pub(crate) fn lookup(model_id: &str) -> Option<ModelCapability> {
if !model_id.starts_with("gemini-") {
return None;
@@ -50,4 +50,8 @@ impl Scheme for GeminiScheme {
fn capability_for(&self, model_id: &str) -> Option<ModelCapability> {
super::capability::lookup(model_id)
}
fn default_capability(&self) -> ModelCapability {
super::capability::default_capability()
}
}
+17 -4
View File
@@ -15,9 +15,10 @@ use serde_json::Value;
use super::auth::AuthRequirement;
use super::capability::ModelCapability;
use super::client::ConfigWarning;
use super::error::ClientError;
use super::event::Event;
use super::types::Request;
use super::types::{Request, RequestConfig};
/// wire scheme の抽象。各プロバイダの API 仕様ごとに 1 つ実装する。
///
@@ -44,7 +45,7 @@ pub trait Scheme: Clone + Send + Sync + 'static {
fn path(&self, model_id: &str) -> String;
/// この scheme が要求する認証形式。`build_client` 時に
/// [`AuthRef`](../../../manifest/enum.AuthRef.html) と照合する。
/// `manifest::AuthRef` と照合する。
fn required_auth(&self) -> AuthRequirement;
/// `Content-Type` 以外の追加ヘッダ。`anthropic-version` / `anthropic-beta` 等。
@@ -75,8 +76,20 @@ pub trait Scheme: Clone + Send + Sync + 'static {
) -> Result<Vec<Event>, ClientError>;
/// 既知モデル ID の能力テーブル引き。未知なら `None` を返す
/// ので、呼び出し側は scheme ごとの安全側デフォルト
/// [`ModelCapability::minimal`])にフォールバックする。
/// ので、呼び出し側は [`Scheme::default_capability`] に
/// フォールバックする。
fn capability_for(&self, model_id: &str) -> Option<ModelCapability>;
/// scheme 既定の capability。未知モデル ID や未明示モデルでの
/// フォールバックに使う。`capability_for` と違って必ず値を返す。
fn default_capability(&self) -> ModelCapability;
/// scheme 側でサポートしていない `RequestConfig` フィールドを
/// 警告として返す(例: OpenAI Chat は `top_k` 非対応)。
/// デフォルトは空 Vec。
fn validate_config(&self, config: &RequestConfig) -> Vec<ConfigWarning> {
let _ = config;
Vec::new()
}
}
@@ -45,3 +45,15 @@ pub(crate) fn lookup(model_id: &str) -> Option<ModelCapability> {
}
None
}
/// Scheme 既定の capability。OpenAI 互換ルーター系(xAI / Groq / OpenRouter 等)
/// で未知モデル ID を受けたときのフォールバックに使う。
pub(crate) fn default_capability() -> ModelCapability {
ModelCapability {
tool_calling: ToolCallingSupport::Parallel,
structured_output: StructuredOutput::JsonSchema,
reasoning: None,
vision: false,
prompt_caching: CacheStrategy::Auto,
}
}
@@ -4,11 +4,12 @@ use serde_json::Value;
use crate::llm_client::{
ClientError,
capability::ModelCapability,
event::Event,
auth::AuthRequirement,
capability::ModelCapability,
client::ConfigWarning,
event::Event,
scheme::Scheme,
types::Request,
types::{Request, RequestConfig},
};
use super::OpenAIScheme;
@@ -54,4 +55,17 @@ impl Scheme for OpenAIScheme {
fn capability_for(&self, model_id: &str) -> Option<ModelCapability> {
super::capability::lookup(model_id)
}
fn default_capability(&self) -> ModelCapability {
super::capability::default_capability()
}
fn validate_config(&self, config: &RequestConfig) -> Vec<ConfigWarning> {
let mut warnings = Vec::new();
// OpenAI Chat Completions API は top_k を受け付けない
if config.top_k.is_some() {
warnings.push(ConfigWarning::unsupported("top_k", "OpenAI Chat"));
}
warnings
}
}
@@ -11,13 +11,13 @@ use eventsource_stream::Eventsource;
use futures::{Stream, StreamExt, TryStreamExt};
use reqwest::header::{CONTENT_TYPE, HeaderMap, HeaderValue};
use super::auth::AuthRequirement;
use super::capability::ModelCapability;
use super::client::LlmClient;
use super::client::{ConfigWarning, LlmClient};
use super::error::ClientError;
use super::event::Event;
use super::auth::AuthRequirement;
use super::scheme::Scheme;
use super::types::Request;
use super::types::{Request, RequestConfig};
/// `AuthRef` を解決したランタイム表現。`crates/provider` が構築する。
///
@@ -155,6 +155,10 @@ impl<S: Scheme + Clone + 'static> LlmClient for HttpTransport<S> {
Box::new(self.clone())
}
fn validate_config(&self, config: &RequestConfig) -> Vec<ConfigWarning> {
self.scheme.validate_config(config)
}
async fn stream(
&self,
request: Request,