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:
31
main/llm/llm_proxy.h
Normal file
31
main/llm/llm_proxy.h
Normal 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);
|
||||
Reference in New Issue
Block a user