mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-08-01 01:26:21 +00:00
feat(ai): implement robust JSON model parsing
Rewrote internal JSON parsing to correctly handle whitespace, escaped quotes, and strict field context extraction. This prevents incorrect field names or provider names from being added to the model list. Added `ai_parse_models_from_json` public API to facilitate testing. Changed `/ai models` default behavior to always fetch fresh models. Replaced `--refresh` flag with `--cached` to display local cache. Added comprehensive unit tests covering OpenAI and Perplexity formats, array format, empty/null JSON, escaped quotes, and whitespace handling.
This commit is contained in:
@@ -168,6 +168,18 @@ gboolean ai_fetch_models(const gchar* provider_name, gpointer user_data);
|
||||
*/
|
||||
gboolean ai_models_are_fresh(const gchar* provider_name);
|
||||
|
||||
/* ========================================================================
|
||||
* Model Parsing (for testing)
|
||||
* ======================================================================== */
|
||||
|
||||
/**
|
||||
* Parse model IDs from an OpenAI-compatible API response.
|
||||
* Expected format: {"object":"list","data":[{"id":"model1",...},...]}
|
||||
* @param provider The provider to add models to
|
||||
* @param json The JSON response from the API
|
||||
*/
|
||||
void ai_parse_models_from_json(AIProvider* provider, const gchar* json);
|
||||
|
||||
/* ========================================================================
|
||||
* Session Management
|
||||
* ======================================================================== */
|
||||
|
||||
Reference in New Issue
Block a user