feat: add Claude API proxy with SSE streaming parser

Anthropic Messages API integration with streaming response.
Parses content_block_delta SSE events, accumulates text tokens.
API key and model stored in NVS.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
crispyberry
2026-02-05 18:55:32 +08:00
parent 44a82520e2
commit cbd137c3fa
2 changed files with 299 additions and 0 deletions

31
main/llm/llm_proxy.h Normal file
View File

@@ -0,0 +1,31 @@
#pragma once
#include "esp_err.h"
#include <stddef.h>
/**
* Initialize the LLM proxy. Reads API key and model from NVS.
*/
esp_err_t llm_proxy_init(void);
/**
* Send a chat completion request to Anthropic Messages API (streaming).
*
* @param system_prompt System prompt string
* @param messages_json JSON array of messages: [{"role":"user","content":"..."},...]
* @param response_buf Output buffer for the complete response text
* @param buf_size Size of response_buf
* @return ESP_OK on success
*/
esp_err_t llm_chat(const char *system_prompt, const char *messages_json,
char *response_buf, size_t buf_size);
/**
* Save the Anthropic API key to NVS.
*/
esp_err_t llm_set_api_key(const char *api_key);
/**
* Save the model identifier to NVS.
*/
esp_err_t llm_set_model(const char *model);