Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/confidence data to prompt service #877

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions prompt-service/src/unstract/prompt_service/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class PromptServiceContants:
ENABLE_HIGHLIGHT = "enable_highlight"
FILE_PATH = "file_path"
HIGHLIGHT_DATA = "highlight_data"
CONFIDENCE_DATA = "confidence_data"


class RunLevel(Enum):
Expand Down
15 changes: 13 additions & 2 deletions prompt-service/src/unstract/prompt_service/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,19 @@ def run_completion(
)
answer: str = completion[PSKeys.RESPONSE].text
highlight_data = completion.get(PSKeys.HIGHLIGHT_DATA)
if all([metadata, highlight_data, prompt_key]):
metadata.setdefault(PSKeys.HIGHLIGHT_DATA, {})[prompt_key] = highlight_data
confidence_data = completion.get(PSKeys.CONFIDENCE_DATA)

if metadata is not None and prompt_key:
if highlight_data:
metadata.setdefault(PSKeys.HIGHLIGHT_DATA, {})[
prompt_key
] = highlight_data

if confidence_data:
metadata.setdefault(PSKeys.CONFIDENCE_DATA, {})[
prompt_key
] = confidence_data

return answer
# TODO: Catch and handle specific exception here
except SdkRateLimitError as e:
Expand Down
15 changes: 0 additions & 15 deletions tools/structure/src/main.py
vishnuszipstack marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -236,21 +236,6 @@ def run(

if not summarize_as_source:
metadata = structured_output_dict[SettingsKeys.METADATA]
epilogue = metadata.pop(SettingsKeys.EPILOGUE, None)
if epilogue:
try:
from helper import ( # type: ignore [attr-defined]
get_confidence_data,
)

metadata[SettingsKeys.CONFIDENCE_DATA] = get_confidence_data(
epilogue, tool_data_dir
)
except ImportError:
self.stream_log(
f"Confidence data is not added. {PAID_FEATURE_MSG}",
level=LogLevel.WARN,
)
# Update the dictionary with modified metadata
structured_output_dict[SettingsKeys.METADATA] = metadata
structured_output = json.dumps(structured_output_dict)
Expand Down
Loading