Documentation Index
Fetch the complete documentation index at: https://mintlify.com/RubenDarioGuerreroNeira/Ecosistema-IA-Colombia/llms.txt
Use this file to discover all available pages before exploring further.
GenkitService is the sole LLM gateway in Salud IA Bot. It is a NestJS @Injectable() service that wraps the official openai Node.js SDK, pointed at https://openrouter.ai/api/v1, and invokes Meta LLaMA 3.1 70B Instruct by default. Every prompt sent through the bot that cannot be answered by structured data alone is routed here. The service is kept deliberately minimal: no injected dependencies, just an env-driven OpenAI client instance and a retry loop.
Configuration
GenkitService reads two environment variables at construction time. Neither has a hard runtime requirement—the service degrades gracefully if keys are absent (useful for tests).
Your OpenRouter API key. Falls back to
'test' if unset (requests will fail authentication but the service will not crash on startup).The OpenRouter model identifier to use for completions. Defaults to
'meta-llama/Meta-Llama-3.1-70B-Instruct' if not set.OpenAI client is configured with:
Class: GenkitService
Method: generateResponse
generateResponse is the only public method. It builds a single-turn user message and calls openai.chat.completions.create().
The full user-facing prompt string. Salud IA Bot assembles context (retrieved SIVIGILA facts, conversation history, system instruction) before passing it here.
The LLM’s text reply (
response.choices[0].message.content). Returns an empty string if the model returns a null content field.Retry Logic
The method uses an attempt counter (attempt = 0 … MAX_RETRIES) and only retries on transient HTTP errors.
| Attempt | Delay before retry | Retried? |
|---|---|---|
| 0 -> 1 | 1 000 ms (2^0 x 1 000) | HTTP 429 or 503 only |
| 1 -> 2 | 2 000 ms (2^1 x 1 000) | HTTP 429 or 503 only |
| 2 -> 3 | 4 000 ms (2^2 x 1 000) | HTTP 429 or 503 only |
| 3 (final) | - | Error is re-thrown |
Non-transient errors (e.g. HTTP 401 Unauthorized, 400 Bad Request) are not retried. They are logged at
error level and immediately re-thrown to the caller.Error handling
MAX_RETRIES exhausted attempts the loop exits and re-throws lastError to propagate the failure to the bot handler.
Integration with BotUpdate
BotUpdate calls GenkitService.generateResponse() only after the structured-data RAG layer fails to produce a direct answer. This keeps LLM usage minimal and guarantees that factual SIVIGILA statistics are returned without model hallucination.