Skip to content

Commit

Permalink
started to add use cases Json_Prompt__Create_Summary and Json_Prompt_…
Browse files Browse the repository at this point in the history
…_Validate_Summary
  • Loading branch information
DinisCruz committed Nov 15, 2024
1 parent cebf824 commit 2137258
Show file tree
Hide file tree
Showing 7 changed files with 335 additions and 173 deletions.
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:
"""
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.
Loading

0 comments on commit 2137258

Please sign in to comment.