-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
started to add use cases Json_Prompt__Create_Summary and Json_Prompt_…
…_Validate_Summary
- Loading branch information
Showing
7 changed files
with
335 additions
and
173 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
osbot_llms/llms/prompt_to_json/use_cases/Json_Prompt__Create_Summary.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from pydantic import BaseModel | ||
|
||
from osbot_llms.llms.prompt_to_json.Prompt_To_Json__Open_AI import Prompt_To_Json__Open_AI | ||
from osbot_utils.base_classes.Type_Safe import Type_Safe | ||
|
||
|
||
class Model__Response_Format__Json_Prompt__Create_Summary(BaseModel): | ||
summary: str | ||
keywords: list[str] | ||
|
||
class Json_Prompt__Create_Summary(Type_Safe): | ||
prompt_to_json : Prompt_To_Json__Open_AI | ||
response_format : type = None | ||
|
||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
self.response_format = Model__Response_Format__Json_Prompt__Create_Summary | ||
|
||
|
||
def create_summary(self, target_text: str): | ||
with self.prompt_to_json as _: | ||
_.set_model__gpt_4o_mini ( ) | ||
_.set_response_format (self.response_format) | ||
_.add_message__system (self.system_prompt()) | ||
_.add_message__user (target_text ) | ||
|
||
return _.invoke() | ||
|
||
def system_prompt(self): | ||
return """ | ||
You are a precise text summarization system. Follow these rules exactly: | ||
1. ONLY use information explicitly stated in the input text | ||
2. DO NOT add any external knowledge, context, or assumptions | ||
3. DO NOT include any dates, statistics, or specific details unless they appear verbatim in the text | ||
4. DO NOT make generalizations about the topic | ||
5. DO NOT add explanatory or background information | ||
6. For keywords: | ||
- ONLY extract words/phrases that appear in the original text | ||
- List them in order of appearance | ||
- DO NOT add related terms or categories | ||
- Limit to 5 keywords maximum | ||
FORMAT: | ||
- Summary: One or two sentences using only information from the text | ||
- Keywords: Maximum 5 terms that appear verbatim in the text | ||
If the input text is too short or lacks sufficient content, just provide a very short summary: | ||
""" |
44 changes: 44 additions & 0 deletions
44
osbot_llms/llms/prompt_to_json/use_cases/Json_Prompt__Validate_Summary.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from pydantic import BaseModel | ||
from osbot_llms.llms.prompt_to_json.Prompt_To_Json__Open_AI import Prompt_To_Json__Open_AI | ||
from osbot_utils.base_classes.Type_Safe import Type_Safe | ||
|
||
class Model__Response_Format__Json_Prompt__Validate_Summary(BaseModel): | ||
is_valid : bool | ||
confidence : float | ||
quality : float | ||
issues_found : list[str] | ||
|
||
class Json_Prompt__Validate_Summary(Type_Safe): | ||
prompt_to_json : Prompt_To_Json__Open_AI | ||
response_format : type = None | ||
|
||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
self.response_format = Model__Response_Format__Json_Prompt__Validate_Summary | ||
|
||
def validate_summary(self, original_text: str, summary: str): | ||
with self.prompt_to_json as _: | ||
_.set_model__gpt_4o_mini() | ||
_.set_response_format(self.response_format) | ||
_.add_message__system(self.system_prompt()) | ||
_.add_message__user(f"""Original Text: | ||
{original_text} | ||
Summary to validate: | ||
{summary}""") | ||
return _.invoke() | ||
|
||
def system_prompt(self): | ||
return """Analyze if the provided summary accurately represents the original text. | ||
Rules: | ||
1. Check if summary ONLY contains information from original text | ||
2. Verify no external knowledge/assumptions added | ||
3. Confirm dates/stats appear in original | ||
4. Check for over generalizations | ||
5. Look for added explanatory content | ||
Score explanation: | ||
- confidence: your certainty in the assessment | ||
- quality: how well summary reflects original content | ||
Return detailed issues list for any problems found.""" |
Empty file.
Oops, something went wrong.