Skip to content

Commit 266483c

Browse files
authored
[DERCBOT-1374] Public URL for Langfuse Observability Settings (#1856)
* Add optional public URL for langfuse * Improved logic * Documentation * English Documentation * PR Reviewed * Code comment + cleanup
1 parent 37f7559 commit 266483c

File tree

7 files changed

+54
-23
lines changed

7 files changed

+54
-23
lines changed

bot/engine/src/main/kotlin/engine/config/RAGAnswerHandler.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import ai.tock.genai.orchestratorclient.responses.TextWithFootnotes
3737
import ai.tock.genai.orchestratorclient.retrofit.GenAIOrchestratorBusinessError
3838
import ai.tock.genai.orchestratorclient.retrofit.GenAIOrchestratorValidationError
3939
import ai.tock.genai.orchestratorclient.services.RAGService
40+
import ai.tock.genai.orchestratorcore.models.observability.LangfuseObservabilitySetting
4041
import ai.tock.genai.orchestratorcore.utils.VectorStoreUtils
4142
import ai.tock.shared.*
4243
import engine.config.AbstractProactiveAnswerHandler
@@ -70,6 +71,9 @@ object RAGAnswerHandler : AbstractProactiveAnswerHandler {
7071
// Handle the RAG answer
7172
if (noAnswerStory == null && answer != null) {
7273
logger.info { "Send RAG answer." }
74+
75+
val modifiedObservabilityInfo = observabilityInfo?.let { updateObservabilityInfo(this, it) }
76+
7377
send(
7478
SendSentenceWithFootnotes(
7579
botId, connectorId, userId, text = answer.text, footnotes = answer.footnotes.map {
@@ -79,7 +83,8 @@ object RAGAnswerHandler : AbstractProactiveAnswerHandler {
7983
it.score
8084
)
8185
}.toMutableList(),
82-
metadata = ActionMetadata(isGenAiRagAnswer = true, observabilityInfo = observabilityInfo)
86+
// modifiedObservabilityInfo includes the public langfuse URL if filled.
87+
metadata = ActionMetadata(isGenAiRagAnswer = true, observabilityInfo = modifiedObservabilityInfo)
8388
)
8489
)
8590
} else {
@@ -90,6 +95,18 @@ object RAGAnswerHandler : AbstractProactiveAnswerHandler {
9095
}
9196
}
9297

98+
private fun updateObservabilityInfo(botBus: BotBus, info: ObservabilityInfo): ObservabilityInfo {
99+
val config = botBus.botDefinition.observabilityConfiguration
100+
if (config?.enabled == true && config.setting is LangfuseObservabilitySetting<*>) {
101+
val setting = config.setting as LangfuseObservabilitySetting<*>
102+
val publicUrl = setting.publicUrl
103+
if (!publicUrl.isNullOrBlank()) {
104+
return info.copy(traceUrl = info.traceUrl.replace(setting.url, publicUrl))
105+
}
106+
}
107+
return info
108+
}
109+
93110
/**
94111
* Manage story redirection when no answer redirection is filled
95112
* Use the handler of the configured story otherwise launch default unknown story

docs/docs/en/user/studio/gen-ai/features/gen-ai-feature-observability.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,30 @@
22
title: Gen AI - Observability Settings
33
---
44

5-
# Le menu *Gen AI - Observability Settings*
5+
# The _Gen AI - Observability Settings_ Menu
66

7-
- L'observabilité des modèles de langage (LLM Observability) aide à surveiller, d'analyser et de comprendre le comportement des modèles de langage à grande échelle.
8-
- Cela inclut la collecte de données sur leurs performances, la détection d'anomalies et la compréhension des erreurs qu'ils peuvent produire.
9-
- L'objectif est de garantir que ces modèles fonctionnent de manière fiable, transparente, en fournissant des informations qui permettent d'améliorer leur performance et de corriger les problèmes potentiels.
10-
- Plus précisément, nous pourrons :
11-
- Voir les différents enchainements d'appels de LLM avec le prompt d'entrée et de sortie
12-
- Analyser les portions de documents contextuels utilisés
13-
- Suivre les informations et les métriques sur les coûts, le nombre de jetons consommés, la latence, etc.
7+
- **LLM Observability** helps monitor, analyze, and understand the behavior of large-scale language models.
8+
- This includes collecting data on their performance, detecting anomalies, and understanding the errors they may produce.
9+
- The goal is to ensure that these models operate reliably and transparently, providing insights that help improve their performance and address potential issues.
10+
- Specifically, we can:
11+
- View different sequences of LLM calls, including input and output prompts.
12+
- Analyze contextual document sections used.
13+
- Track information and metrics such as costs, token consumption, latency, etc.
1414

15-
16-
> Pour accéder à cette page il faut bénéficier du rôle **_botUser_**.
17-
> <br />( plus de détails sur les rôles dans [securité]() ).
15+
> To access this page, you must have the **_botUser_** role.
16+
> <br />(More details on roles can be found in [security](../../../../../admin/securite#rôles)).
1817
1918
## Configuration
20-
Pour permettre à Tock de se connecter à un outil d'observabilité, un écran de configuration a été mis en place :
19+
To enable Tock to connect to an observability tool, a configuration screen has been set up:
20+
21+
![LLM Observability](../../../../../img/gen-ai/gen-ai-feature-observability.png "Configuration screen for the AI observability tool")
22+
23+
## Public URL Configuration
2124

22-
![LLM Observability](../../../../img/gen-ai/gen-ai-feature-observability.png "Ecran de configuration de l'outil d'observation de l'IA")
25+
- The **Public URL** field allows specifying an externally accessible URL for observability tools such as Langfuse.
26+
- This URL will be used in the frontend interface to redirect users to observability traces, replacing the internal URL, which may not be publicly accessible.
2327

24-
## Utilisation
28+
## Usage
2529

26-
- Voici la [liste des fournisseurs d'observabilité des LLM](../../../../user/studio/gen-ai/providers/gen-ai-provider-observability.md) qui sont pris en compte par Tock.
27-
- Veuillez vous référer à la documentation de chaque outil pour comprendre comment l'utiliser.
30+
- Here is the [list of LLM observability providers](../../providers/gen-ai-provider-observability) supported by Tock.
31+
- Please refer to each tool's documentation to understand how to use it.

docs/docs/fr/user/studio/gen-ai/features/gen-ai-feature-observability.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ Pour permettre à Tock de se connecter à un outil d'observabilité, un écran d
2121

2222
![LLM Observability](../../../../img/gen-ai/gen-ai-feature-observability.png "Ecran de configuration de l'outil d'observation de l'IA")
2323

24+
## Configuration d'URL Publique
25+
26+
- Le champ **Public URL** permet de spécifier une URL accessible depuis l'extérieur pour les outils d'observabilité comme Langfuse.
27+
- Cette URL sera utilisée dans l'interface frontend pour rediriger les utilisateurs vers les traces d'observabilité, remplaçant l'URL interne qui pourrait ne pas être accessible publiquement.
28+
2429
## Utilisation
2530

2631
- Voici la [liste des fournisseurs d'observabilité des LLM](../../../../user/studio/gen-ai/providers/gen-ai-provider-observability.md) qui sont pris en compte par Tock.

gen-ai/orchestrator-core/src/main/kotlin/ai/tock/genai/orchestratorcore/mappers/ObservabilitySettingMapper.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ object ObservabilitySettingMapper {
3636
when (this) {
3737
is LangfuseObservabilitySetting -> {
3838
val secretKey = SecurityUtils.fetchSecretKeyValue(secretKey)
39-
return LangfuseObservabilitySetting(secretKey, publicKey, url)
39+
return LangfuseObservabilitySetting(secretKey, publicKey, url, publicUrl)
4040
}
4141

4242
else ->
@@ -64,9 +64,8 @@ object ObservabilitySettingMapper {
6464
when (this) {
6565
is LangfuseObservabilitySetting -> {
6666
val secretKey = SecurityUtils.createSecretKey(namespace, botId, feature, secretKey, rawByForce)
67-
return LangfuseObservabilitySetting(secretKey, publicKey, url)
67+
return LangfuseObservabilitySetting(secretKey, publicKey, url, publicUrl.takeIf {!it.isNullOrBlank()})
6868
}
69-
7069
else ->
7170
throw IllegalArgumentException("Unsupported Observability Setting")
7271
}

gen-ai/orchestrator-core/src/main/kotlin/ai/tock/genai/orchestratorcore/models/observability/LangfuseObservabilitySetting.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ import ai.tock.shared.security.key.HasSecretKey
2121
data class LangfuseObservabilitySetting<T>(
2222
override val secretKey: T,
2323
val publicKey: String,
24-
val url: String
24+
val url: String,
25+
val publicUrl : String? = null,
2526
) : ObservabilitySettingBase<T>(ObservabilityProvider.Langfuse), HasSecretKey<T>

gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/models/observability/langfuse/langfuse_setting.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#
1515
"""Model for creating LangfuseObservabilitySetting."""
1616

17-
from typing import Literal
17+
from typing import Literal, Optional
1818

1919
from pydantic import AnyUrl, Field
2020

@@ -42,6 +42,11 @@ class LangfuseObservabilitySetting(BaseObservabilitySetting):
4242
url: AnyUrl = Field(
4343
description='The Langfuse server url', examples=['https://cloud.langfuse.com'], default='http://localhost:3000'
4444
)
45+
public_url: Optional[AnyUrl] = Field(
46+
default=None,
47+
description="Optional public URL for Langfuse server",
48+
examples=["https://public.langfuse.com"]
49+
)
4550
secret_key: SecretKey = Field(
4651
description='Stores the secret key used to authenticate requests to the Observability Provider API.',
4752
examples=[RawSecretKey(secret='sk-********************be8f')],

gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/routers/observability_providers_router.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ async def get_observability_provider_setting_by_id(
119119
provider=ObservabilityProvider.LANGFUSE,
120120
secret_key=RawSecretKey(secret='sk-********************be8f'),
121121
public_key='pk-lf-5e374dc6-e194-4b37-9c07-b77e68ef7d2c',
122-
url='https://cloud.langfuse.com'
122+
url='https://cloud.langfuse.com',
123123
)
124124

125125

0 commit comments

Comments
 (0)