ws-bom-robot-app 0.0.55__py3-none-any.whl → 0.0.57__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  from typing import Annotated, Any, Mapping
2
- from fastapi import APIRouter, HTTPException, Request, Header
2
+ from fastapi import APIRouter, HTTPException, Request, Header, Body
3
3
  from fastapi.responses import StreamingResponse
4
4
  from ws_bom_robot_app.llm.agent_description import AgentDescriptor
5
5
  from ws_bom_robot_app.llm.models.api import InvokeRequest, StreamRequest, RulesRequest, KbRequest, VectorDbResponse
@@ -9,6 +9,7 @@ from ws_bom_robot_app.llm.vector_store.generator import kb, rules, kb_stream_fil
9
9
  from ws_bom_robot_app.llm.tools.tool_manager import ToolManager
10
10
  from ws_bom_robot_app.llm.vector_store.integration.manager import IntegrationManager
11
11
  from ws_bom_robot_app.task_manager import task_manager, TaskHeader
12
+ from ws_bom_robot_app.llm.feedbacks.feedback_manager import FeedbackConfig, FeedbackManager, FeedbackInterface
12
13
  from uuid import uuid4
13
14
  router = APIRouter(prefix="/api/llm", tags=["llm"])
14
15
 
@@ -89,3 +90,16 @@ def _llm_models(provider: str, secrets: dict[str, Any]):
89
90
  except Exception as e:
90
91
  raise HTTPException(status_code=400, detail=str(e))
91
92
 
93
+ @router.post("/feedback", tags=["feedback"])
94
+ async def _send_feedback(feedback: FeedbackConfig):
95
+ """
96
+ Invia un feedback usando lo strategy FeedbackManager.
97
+ """
98
+ provider = feedback.provider
99
+ strategy_cls = FeedbackManager._list.get(provider)
100
+ if not strategy_cls:
101
+ from fastapi import HTTPException
102
+ raise HTTPException(status_code=400, detail=f"Provider '{provider}' non supportato")
103
+ strategy: FeedbackInterface = strategy_cls(feedback)
104
+ result = strategy.send_feedback()
105
+ return {"result": result}
File without changes
@@ -0,0 +1,74 @@
1
+ from ws_bom_robot_app.llm.models.feedback import NebulyFeedbackPayload, NebulyFeedbackAction, NebulyFeedbackMetadata
2
+ from ws_bom_robot_app.config import config
3
+ from pydantic import BaseModel, Field
4
+ from typing import Optional
5
+ import requests
6
+
7
+ class FeedbackConfig(BaseModel):
8
+ """
9
+ FeedbackConfig is a model that represents the configuration for feedback management.
10
+ It includes the API key and the URL for the feedback service.
11
+ """
12
+ api_key: str = Field(..., description="The API key for authentication")
13
+ provider: str = Field(..., description="The provider of the feedback service")
14
+ user_id: str = Field(..., description="The user ID for the feedback service")
15
+ message_input: Optional[str] = Field(default=None, description="The input message to which the feedback refers")
16
+ message_output: Optional[str] = Field(default=None, description="The output message to which the feedback refers")
17
+ comment: str = Field(..., description="The comment provided by the user")
18
+ rating: int = Field(..., description="The rating given by the user (from 1 to 5)", ge=1, le=5)
19
+ anonymize: bool = Field(False, description="Boolean flag. If set to true, PII will be removed from the text field")
20
+ timestamp: str = Field(..., description="The timestamp of the feedback event")
21
+ message_id: Optional[str] = Field(default=None, description="The message ID for the feedback")
22
+
23
+ class FeedbackInterface:
24
+ def __init__(self, config: FeedbackConfig):
25
+ self.config = config
26
+
27
+ def send_feedback(self):
28
+ raise NotImplementedError
29
+
30
+ class NebulyFeedback(FeedbackInterface):
31
+ def __init__(self, config: FeedbackConfig):
32
+ super().__init__(config)
33
+ self.config = config
34
+
35
+ def send_feedback(self) -> str:
36
+ if not self.config.api_key:
37
+ return "Error sending feedback: API key is required for Nebuly feedback"
38
+ headers = {
39
+ "Authorization": f"Bearer {self.config.api_key}",
40
+ "Content-Type": "application/json"
41
+ }
42
+ action = NebulyFeedbackAction(
43
+ slug="rating",
44
+ text=self.config.comment,
45
+ value=self.config.rating
46
+ )
47
+ metadata = NebulyFeedbackMetadata(
48
+ end_user=self.config.user_id,
49
+ timestamp=self.config.timestamp,
50
+ anonymize=self.config.anonymize
51
+ )
52
+ payload = NebulyFeedbackPayload(
53
+ action=action,
54
+ metadata=metadata
55
+ )
56
+ url = f"{config.NEBULY_API_URL}/event-ingestion/api/v1/events/feedback"
57
+ response = requests.request("POST", url, json=payload.model_dump(), headers=headers)
58
+ if response.status_code != 200:
59
+ raise Exception(f"Error sending feedback: {response.status_code} - {response.text}")
60
+ return response.text
61
+
62
+ def __buildAiMessage(self) -> str:
63
+ message = eval(self.config.message_output)
64
+ message_output = ""
65
+ for chunk in message:
66
+ if isinstance(chunk, dict) and "text" in chunk:
67
+ message_output += chunk["text"]
68
+ return message_output
69
+
70
+ class FeedbackManager:
71
+ #class variables (static)
72
+ _list: dict[str,FeedbackInterface] = {
73
+ "nebuly": NebulyFeedback,
74
+ }
@@ -0,0 +1,30 @@
1
+ from pydantic import BaseModel, Field
2
+
3
+ class NebulyFeedbackAction(BaseModel):
4
+ """
5
+ FeedbackAction is a model that represents the action taken by the user
6
+ in response to the feedback provided by the LLM.
7
+ """
8
+ slug: str = Field("rating", description="A string identifier for the feedback action",
9
+ enum=["thumbs_up", "thumbs_down", "copy_input", "copy_output", "paste", "rating"])
10
+ text: str = Field(..., description="The text content of the feedback")
11
+ value: int = Field(..., description="A numeric value associated with the feedback")
12
+
13
+ class NebulyFeedbackMetadata(BaseModel):
14
+ """
15
+ FeedbackMetadata is a model that represents the metadata associated with user feedback.
16
+ This includes information about the interaction and the user who provided feedback.
17
+ """
18
+ input: str = Field(None, description="The input of the interactions to which the action refers to")
19
+ output: str = Field(None, description="The output of the interactions to which the action refers to")
20
+ end_user: str = Field(..., description="The identifier used for the end-user")
21
+ timestamp: str = Field(..., description="The timestamp of the action event")
22
+ anonymize: bool = Field(False, description="Boolean flag. If set to true, PII will be removed from the text field")
23
+
24
+ class NebulyFeedbackPayload(BaseModel):
25
+ """
26
+ NebulyFeedback is a model that combines feedback action and metadata.
27
+ It represents a complete feedback entry from a user interaction with the LLM.
28
+ """
29
+ action: NebulyFeedbackAction = Field(..., description="The action taken by the user as feedback")
30
+ metadata: NebulyFeedbackMetadata = Field(..., description="Metadata associated with the feedback")
@@ -44,6 +44,7 @@ class NebulyHandler(AsyncCallbackHandler):
44
44
  self.interaction.input = self.__parse_multimodal_input(message_list[-1].content)
45
45
  else:
46
46
  self.interaction.input = message_list[-1].content
47
+ self.interaction.tags["generated"] = self.__is_message_generated(message_list)
47
48
  else:
48
49
  raise ValueError("Last message is not a HumanMessage")
49
50
  self.interaction.time_start = datetime.now().astimezone().isoformat()
@@ -161,3 +162,12 @@ class NebulyHandler(AsyncCallbackHandler):
161
162
  })
162
163
  return parsed_history
163
164
 
165
+ def __is_message_generated(self, messages: list[BaseMessage]) -> bool:
166
+ # Check if the last message is generated by the model
167
+ if len(messages) == 0:
168
+ return False
169
+ last_user_message = f'<div class="llm__pill">{messages[-1].content}</div>'
170
+ last_ai_message = messages[-2].content
171
+ if last_user_message in last_ai_message:
172
+ return "true"
173
+ return "false"
@@ -127,8 +127,9 @@ class Gvertex(LlmInterface):
127
127
 
128
128
  #see https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#united-states for available models
129
129
  return [
130
- {"id":"gemini-2.0-flash-001"},
131
- {"id":"gemini-2.0-flash-lite-001"},
130
+ {"id":"gemini-2.5-pro-preview-05-06"},
131
+ {"id":"gemini-2.0-flash"},
132
+ {"id":"gemini-2.0-flash-lite"},
132
133
  {"id":"gemini-1.5-pro-002"}
133
134
  ]
134
135
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ws_bom_robot_app
3
- Version: 0.0.55
3
+ Version: 0.0.57
4
4
  Summary: A FastAPI application serving ws bom/robot/llm platform ai.
5
5
  Home-page: https://github.com/websolutespa/bom
6
6
  Author: Websolute Spa
@@ -10,17 +10,20 @@ ws_bom_robot_app/llm/agent_context.py,sha256=uatHJ8wcRly6h0S762BgfzDMpmcwCHwNzwo
10
10
  ws_bom_robot_app/llm/agent_description.py,sha256=5IP0qFSJvaE3zjGS7f0W1DuiegP0RHXRMBoDC5pCofA,4779
11
11
  ws_bom_robot_app/llm/agent_handler.py,sha256=_mh2anSdkSnXncXBYnKars7zPd-PVewnk8O8du1s4do,7756
12
12
  ws_bom_robot_app/llm/agent_lcel.py,sha256=8d10b43BXqE4rfXE5uh8YGT67o1bw0q0l7QXFT6wPKA,2320
13
- ws_bom_robot_app/llm/api.py,sha256=RW_zt986WfyJFY697z5yFbTwPjlHYHVPqcc8J1_JcBE,4034
13
+ ws_bom_robot_app/llm/api.py,sha256=1nzQ7g2n_DlX6Ixo5ecS10UvyyKJ42qZQ6aD8-EI7BE,4709
14
14
  ws_bom_robot_app/llm/defaut_prompt.py,sha256=D9dn8yPveu0bVwGM1wQWLYftmBs5O76o0R_caLLll8w,1121
15
15
  ws_bom_robot_app/llm/main.py,sha256=UK33yI_0zDCdM5zKe9h7c_qzM41PIANvRFCxjGlAzlI,5140
16
- ws_bom_robot_app/llm/nebuly_handler.py,sha256=2UUcWQjOgcqlfPNphvtnnHFRl9whitYPW0NpN8yJs_I,7010
16
+ ws_bom_robot_app/llm/nebuly_handler.py,sha256=1HaBeBNzEhyTsgz9v-15Tt7oAc6UBGtqB_DBujpFIcw,7534
17
17
  ws_bom_robot_app/llm/settings.py,sha256=DCLaGZwxlw0xE46LpfUgin_FHD8_XJIthCgI6r2UDlM,121
18
+ ws_bom_robot_app/llm/feedbacks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
+ ws_bom_robot_app/llm/feedbacks/feedback_manager.py,sha256=bnP0FEJTyrzT0YzqCVE73EC07Eu_4FLxVu3Cy-5Si0o,3211
18
20
  ws_bom_robot_app/llm/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
21
  ws_bom_robot_app/llm/models/api.py,sha256=266f5jc1ikfX9HnK5Ms4NxXowNRfxFEH8GPlQcDvN5Y,10709
20
22
  ws_bom_robot_app/llm/models/base.py,sha256=1TqxuTK3rjJEALn7lvgoen_1ba3R2brAgGx6EDTtDZo,152
23
+ ws_bom_robot_app/llm/models/feedback.py,sha256=pYNQGxNOBgeAAfdJLI95l7ePLBI5tVdsgnyjp5oMOQU,1722
21
24
  ws_bom_robot_app/llm/models/kb.py,sha256=oVSw6_dmNxikAHrPqcfxDXz9M0ezLIYuxpgvzfs_Now,9514
22
25
  ws_bom_robot_app/llm/providers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
- ws_bom_robot_app/llm/providers/llm_manager.py,sha256=mJNVgv9QwAY9xEYybfOt5NzzZvTqVcvGUdyBmEIqvJM,8290
26
+ ws_bom_robot_app/llm/providers/llm_manager.py,sha256=C63GJOaJHcKraDYZgemOdh8F2UPrheH_0E-gdhmpD6s,8336
24
27
  ws_bom_robot_app/llm/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
28
  ws_bom_robot_app/llm/tools/tool_builder.py,sha256=p_Q32_-OSydcxzj69PgPIuiny816zYv5dVsCHSY0ELc,1188
26
29
  ws_bom_robot_app/llm/tools/tool_manager.py,sha256=xyGDa4BnPrdZv4-AL_kXIwaUpD7JOVO4FAhLbSTuujg,6001
@@ -62,7 +65,7 @@ ws_bom_robot_app/llm/vector_store/loader/__init__.py,sha256=47DEQpj8HBSa-_TImW-5
62
65
  ws_bom_robot_app/llm/vector_store/loader/base.py,sha256=L_ugekNuAq0N9O-24wtlHSNHkqSeD-KsJrfGt_FX9Oc,5340
63
66
  ws_bom_robot_app/llm/vector_store/loader/docling.py,sha256=yP0zgXLeFAlByaYuj-6cYariuknckrFds0dxdRcnVz8,3456
64
67
  ws_bom_robot_app/llm/vector_store/loader/json_loader.py,sha256=LDppW0ZATo4_1hh-KlsAM3TLawBvwBxva_a7k5Oz1sc,858
65
- ws_bom_robot_app-0.0.55.dist-info/METADATA,sha256=hoyAKOKcnwUx3QK70KwRXKZqnLFCVj9WnxXlJhqdQts,8329
66
- ws_bom_robot_app-0.0.55.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
67
- ws_bom_robot_app-0.0.55.dist-info/top_level.txt,sha256=Yl0akyHVbynsBX_N7wx3H3ZTkcMLjYyLJs5zBMDAKcM,17
68
- ws_bom_robot_app-0.0.55.dist-info/RECORD,,
68
+ ws_bom_robot_app-0.0.57.dist-info/METADATA,sha256=pNu9PdNL8evyWeVAD8LyHUMG-MPY0nYICCHdS4mC4oA,8329
69
+ ws_bom_robot_app-0.0.57.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
70
+ ws_bom_robot_app-0.0.57.dist-info/top_level.txt,sha256=Yl0akyHVbynsBX_N7wx3H3ZTkcMLjYyLJs5zBMDAKcM,17
71
+ ws_bom_robot_app-0.0.57.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.7.1)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5