68 lines
2.3 KiB
C
68 lines
2.3 KiB
C
|
|
#pragma once
|
||
|
|
|
||
|
|
#include <stdbool.h>
|
||
|
|
#include <stddef.h>
|
||
|
|
#include "esp_err.h"
|
||
|
|
|
||
|
|
#ifdef __cplusplus
|
||
|
|
extern "C" {
|
||
|
|
#endif
|
||
|
|
|
||
|
|
/* Forward declaration for esp_http_client_handle_t */
|
||
|
|
typedef struct esp_http_client* esp_http_client_handle_t;
|
||
|
|
|
||
|
|
/* Provider configuration structure */
|
||
|
|
typedef struct {
|
||
|
|
const char *name; /* Provider name, e.g., "anthropic", "openai", "siliconflow", "volcengine" */
|
||
|
|
const char *default_api_url; /* Default API URL */
|
||
|
|
const char *default_host; /* Default hostname */
|
||
|
|
const char *default_path; /* Default API path */
|
||
|
|
bool is_openai_compatible; /* Whether this provider uses OpenAI-compatible API */
|
||
|
|
} llm_provider_config_t;
|
||
|
|
|
||
|
|
/* Provider registry - all supported providers */
|
||
|
|
extern const llm_provider_config_t llm_providers[];
|
||
|
|
extern const int llm_provider_count;
|
||
|
|
|
||
|
|
/* Find provider configuration by name */
|
||
|
|
const llm_provider_config_t *llm_provider_find(const char *name);
|
||
|
|
|
||
|
|
/* Get current provider configuration */
|
||
|
|
const llm_provider_config_t *llm_provider_current(void);
|
||
|
|
|
||
|
|
/* Set current provider by name */
|
||
|
|
void llm_provider_set_current(const char *name);
|
||
|
|
|
||
|
|
/* Get current provider name */
|
||
|
|
const char *llm_provider_current_name(void);
|
||
|
|
|
||
|
|
/* Check if current provider is OpenAI-compatible */
|
||
|
|
bool llm_provider_is_openai_compatible(void);
|
||
|
|
|
||
|
|
/* Get API URL for current provider (with dynamic Base URL support) */
|
||
|
|
const char *llm_provider_api_url(void);
|
||
|
|
|
||
|
|
/* Get hostname for current provider */
|
||
|
|
const char *llm_provider_host(void);
|
||
|
|
|
||
|
|
/* Get API path for current provider */
|
||
|
|
const char *llm_provider_path(void);
|
||
|
|
|
||
|
|
/* Provider-specific API key and Base URL management */
|
||
|
|
void llm_provider_set_api_key(const char *provider_name, const char *api_key);
|
||
|
|
void llm_provider_set_base_url(const char *provider_name, const char *base_url);
|
||
|
|
const char *llm_provider_get_api_key(const char *provider_name);
|
||
|
|
const char *llm_provider_get_base_url(const char *provider_name);
|
||
|
|
|
||
|
|
/* Initialize provider system (load from NVS) */
|
||
|
|
void llm_provider_init(void);
|
||
|
|
|
||
|
|
/* Save provider configuration to NVS */
|
||
|
|
void llm_provider_save_config(const char *provider_name);
|
||
|
|
|
||
|
|
/* Common authentication header setup for OpenAI-compatible providers */
|
||
|
|
void llm_provider_set_auth_headers(esp_http_client_handle_t client, const char *api_key);
|
||
|
|
|
||
|
|
#ifdef __cplusplus
|
||
|
|
}
|
||
|
|
#endif
|