Spaces:
Runtime error
Runtime error
Commit
·
46b11f4
1
Parent(s):
ede8222
Added fix for changing project and logstream from UI
Browse files- backend/api/main.py +4 -5
- backend/classes/galileo_platform.py +24 -10
backend/api/main.py
CHANGED
|
@@ -116,11 +116,10 @@ async def search(
|
|
| 116 |
protection: bool = Form(False),
|
| 117 |
hallucination_detection: bool = Form(False),
|
| 118 |
induce_hallucination: bool = Form(False),
|
| 119 |
-
project_name: str =
|
| 120 |
-
logstream_name: str =
|
| 121 |
-
dataset_name: str =
|
| 122 |
-
):
|
| 123 |
-
|
| 124 |
response, redacted_response, original_response, context_adherence_score, pii_flag = rag_app.run(
|
| 125 |
query,
|
| 126 |
protect_enabled=protection,
|
|
|
|
| 116 |
protection: bool = Form(False),
|
| 117 |
hallucination_detection: bool = Form(False),
|
| 118 |
induce_hallucination: bool = Form(False),
|
| 119 |
+
project_name: str = Form(...),
|
| 120 |
+
logstream_name: str = Form(...),
|
| 121 |
+
dataset_name: str = Form(...),
|
| 122 |
+
) -> JSONResponse:
|
|
|
|
| 123 |
response, redacted_response, original_response, context_adherence_score, pii_flag = rag_app.run(
|
| 124 |
query,
|
| 125 |
protect_enabled=protection,
|
backend/classes/galileo_platform.py
CHANGED
|
@@ -1,9 +1,11 @@
|
|
| 1 |
-
from typing import Optional
|
| 2 |
-
|
| 3 |
-
from dotenv import load_dotenv
|
| 4 |
from pydantic import BaseModel
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
from galileo import GalileoLogger, GalileoScorers, StageType
|
|
|
|
|
|
|
| 7 |
from galileo.protect import invoke_protect
|
| 8 |
from galileo.stages import create_protect_stage, get_protect_stage
|
| 9 |
from galileo_core.schemas.protect.action import OverrideAction
|
|
@@ -25,14 +27,26 @@ class GalileoPlatform:
|
|
| 25 |
self.config = config
|
| 26 |
self.protect_stage_id = self.get_protect_stage_id()
|
| 27 |
|
| 28 |
-
def get_logger(self, project_name: str, logstream_name: str):
|
| 29 |
"""Get or create a Galileo Logger."""
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
def get_protect_stage_id(self):
|
| 36 |
"""Get or create a Galileo Protect stage."""
|
| 37 |
try:
|
| 38 |
protect_stage = get_protect_stage(
|
|
@@ -49,7 +63,7 @@ class GalileoPlatform:
|
|
| 49 |
)
|
| 50 |
return protect_stage.id
|
| 51 |
|
| 52 |
-
def run_protect(self, input: str, output: str, logger:
|
| 53 |
"""Run Galileo Protect on input and output."""
|
| 54 |
response = invoke_protect(
|
| 55 |
payload=Payload(input=input, output=output),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from pydantic import BaseModel
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
from typing import Any
|
| 4 |
+
from uuid import UUID4
|
| 5 |
|
| 6 |
from galileo import GalileoLogger, GalileoScorers, StageType
|
| 7 |
+
from galileo.log_streams import create_log_stream, get_log_stream
|
| 8 |
+
from galileo.projects import create_project, get_project
|
| 9 |
from galileo.protect import invoke_protect
|
| 10 |
from galileo.stages import create_protect_stage, get_protect_stage
|
| 11 |
from galileo_core.schemas.protect.action import OverrideAction
|
|
|
|
| 27 |
self.config = config
|
| 28 |
self.protect_stage_id = self.get_protect_stage_id()
|
| 29 |
|
| 30 |
+
def get_logger(self, project_name: str, logstream_name: str) -> GalileoLogger | None:
|
| 31 |
"""Get or create a Galileo Logger."""
|
| 32 |
+
if not get_project(name=project_name):
|
| 33 |
+
_ = create_project(name=project_name)
|
| 34 |
+
print(f"Project {project_name} created")
|
| 35 |
+
|
| 36 |
+
if not get_log_stream(name=logstream_name, project_name=project_name):
|
| 37 |
+
_ = create_log_stream(name=logstream_name, project_name=project_name)
|
| 38 |
+
print(f"Logstream {logstream_name} created in project {project_name}")
|
| 39 |
+
|
| 40 |
+
try:
|
| 41 |
+
return GalileoLogger(
|
| 42 |
+
project=project_name,
|
| 43 |
+
log_stream=logstream_name,
|
| 44 |
+
)
|
| 45 |
+
except Exception as e:
|
| 46 |
+
print(f"Failed to create logger: {e}")
|
| 47 |
+
return None
|
| 48 |
|
| 49 |
+
def get_protect_stage_id(self) -> str | UUID4 | None:
|
| 50 |
"""Get or create a Galileo Protect stage."""
|
| 51 |
try:
|
| 52 |
protect_stage = get_protect_stage(
|
|
|
|
| 63 |
)
|
| 64 |
return protect_stage.id
|
| 65 |
|
| 66 |
+
def run_protect(self, input: str, output: str, logger: GalileoLogger | None = None) -> dict[Any, Any]:
|
| 67 |
"""Run Galileo Protect on input and output."""
|
| 68 |
response = invoke_protect(
|
| 69 |
payload=Payload(input=input, output=output),
|