Skip to content

Commit

Permalink
Update chatbot
Browse files Browse the repository at this point in the history
  • Loading branch information
mdciri committed Dec 6, 2024
1 parent 63dc519 commit c9918f7
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion apps/chatbot/src/modules/chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pathlib import Path
from datetime import datetime
from logging import getLogger
from typing import Union, Tuple, Sequence, Optional, List, Any, Dict
from typing import Union, Tuple, Sequence, Optional, List, Any, Dict, Literal

from llama_index.core import PromptTemplate
from llama_index.core.llms import ChatMessage, MessageRole
Expand Down Expand Up @@ -277,6 +277,31 @@ def remove_langfuse_tag(self, trace_id: str, tag: str) -> None:
else:
logger.warning(f"Tag {tag} not present in trace {trace_id}")


def add_langfuse_score(
self,
trace_id: str,
name: str,
value: float,
data_type: Literal['NUMERIC', 'BOOLEAN'] | None = None
) -> None:

with self.instrumentor.observe(trace_id=trace_id) as trace:
trace_info = self.get_trace(trace_id, as_dict=False)
flag = True
for score in trace_info.scores:
if score.name == name:
flag = False
score_id = score.id
break

if flag:
trace.score(name=name, value=value, data_type=data_type)
logger.warning(f"Add score {name}: {value} in trace {trace_id}")
else:
trace.score(id=score_id, name=name, value=value, data_type=data_type)
logger.warning(f"Updating score {name} to {value} in trace {trace_id}")


def _mask_trace(self, data: Any) -> None:

Expand Down

0 comments on commit c9918f7

Please sign in to comment.