255#if defined(YAZE_WITH_JSON)
256 if (!std::filesystem::exists(path)) {
257 return absl::NotFoundError(
"Import file not found");
260 std::ifstream file(path);
261 if (!file.is_open()) {
262 return absl::InternalError(
"Failed to open import file");
265 std::string json_content((std::istreambuf_iterator<char>(file)),
266 std::istreambuf_iterator<char>());
269 if (!profile_or.ok()) {
270 return profile_or.status();
276 return absl::UnimplementedError(
"JSON support required");
339 const std::string& json_str)
const {
340#if defined(YAZE_WITH_JSON)
342 nlohmann::json json = nlohmann::json::parse(json_str);
345 profile.
name = json.value(
"name",
"Unnamed Profile");
346 profile.
description = json.value(
"description",
"");
348 profile.
host_id = json.value(
"host_id",
"");
349 profile.
model = json.value(
"model",
"");
350 profile.
ollama_host = json.value(
"ollama_host",
"http://localhost:11434");
355 json.value(
"openai_base_url",
"https://api.openai.com");
357 profile.
verbose = json.value(
"verbose",
false);
361 profile.
temperature = json.value(
"temperature", 0.25f);
362 profile.
top_p = json.value(
"top_p", 0.95f);
366 if (json.contains(
"tags") && json[
"tags"].is_array()) {
367 for (
const auto& tag : json[
"tags"]) {
368 profile.
tags.push_back(tag.get<std::string>());
372 if (json.contains(
"created_at")) {
374 if (absl::ParseTime(absl::RFC3339_full,
375 json[
"created_at"].get<std::string>(), &created,
381 if (json.contains(
"modified_at")) {
383 if (absl::ParseTime(absl::RFC3339_full,
384 json[
"modified_at"].get<std::string>(), &modified,
391 }
catch (
const std::exception& e) {
392 return absl::InternalError(
393 absl::StrFormat(
"Failed to parse profile JSON: %s", e.what()));
397 return absl::UnimplementedError(
"JSON support required");
431 ?
"http://localhost:11434"
436 ctx_config.openai_base_url =
450 ctx_config.provider_buffer);
453 ctx_config.ollama_host_buffer);
455 ctx_config.gemini_key_buffer);
457 ctx_config.anthropic_key_buffer);
459 ctx_config.openai_key_buffer);
461 ctx_config.openai_base_url_buffer);
474 const std::string prev_provider = ctx_config.
ai_provider;
475 const std::string prev_openai_base = ctx_config.openai_base_url;
476 const std::string prev_ollama_host = ctx_config.ollama_host;
477 ctx_config.ai_provider =
479 ctx_config.ai_model = config.
ai_model;
480 ctx_config.ollama_host = config.
ollama_host.empty() ?
"http://localhost:11434"
485 ctx_config.openai_base_url =
487 ctx_config.host_id = config.
host_id;
488 ctx_config.verbose = config.
verbose;
493 ctx_config.top_p = config.
top_p;
502 if (prev_provider != ctx_config.ai_provider ||
503 prev_openai_base != ctx_config.openai_base_url ||
504 prev_ollama_host != ctx_config.ollama_host) {
507 model_cache.model_names.clear();
508 model_cache.last_refresh = absl::InfinitePast();
509 model_cache.auto_refresh_requested =
false;
510 model_cache.last_provider = ctx_config.ai_provider;
511 model_cache.last_openai_base = ctx_config.openai_base_url;
512 model_cache.last_ollama_host = ctx_config.ollama_host;
516 ctx_config.provider_buffer);
519 ctx_config.ollama_host_buffer);
521 ctx_config.gemini_key_buffer);
523 ctx_config.anthropic_key_buffer);
525 ctx_config.openai_key_buffer);
527 ctx_config.openai_base_url_buffer);
ModelCache & model_cache()
AgentConfigState & agent_config()