Skip to content

Commit 2137258

Browse files
committed
started to add use cases Json_Prompt__Create_Summary and Json_Prompt__Validate_Summary
1 parent cebf824 commit 2137258

File tree

7 files changed

+335
-173
lines changed

7 files changed

+335
-173
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from pydantic import BaseModel
2+
3+
from osbot_llms.llms.prompt_to_json.Prompt_To_Json__Open_AI import Prompt_To_Json__Open_AI
4+
from osbot_utils.base_classes.Type_Safe import Type_Safe
5+
6+
7+
class Model__Response_Format__Json_Prompt__Create_Summary(BaseModel):
8+
summary: str
9+
keywords: list[str]
10+
11+
class Json_Prompt__Create_Summary(Type_Safe):
12+
prompt_to_json : Prompt_To_Json__Open_AI
13+
response_format : type = None
14+
15+
def __init__(self, **kwargs):
16+
super().__init__(**kwargs)
17+
self.response_format = Model__Response_Format__Json_Prompt__Create_Summary
18+
19+
20+
def create_summary(self, target_text: str):
21+
with self.prompt_to_json as _:
22+
_.set_model__gpt_4o_mini ( )
23+
_.set_response_format (self.response_format)
24+
_.add_message__system (self.system_prompt())
25+
_.add_message__user (target_text )
26+
27+
return _.invoke()
28+
29+
def system_prompt(self):
30+
return """
31+
You are a precise text summarization system. Follow these rules exactly:
32+
33+
1. ONLY use information explicitly stated in the input text
34+
2. DO NOT add any external knowledge, context, or assumptions
35+
3. DO NOT include any dates, statistics, or specific details unless they appear verbatim in the text
36+
4. DO NOT make generalizations about the topic
37+
5. DO NOT add explanatory or background information
38+
6. For keywords:
39+
- ONLY extract words/phrases that appear in the original text
40+
- List them in order of appearance
41+
- DO NOT add related terms or categories
42+
- Limit to 5 keywords maximum
43+
44+
FORMAT:
45+
- Summary: One or two sentences using only information from the text
46+
- Keywords: Maximum 5 terms that appear verbatim in the text
47+
48+
If the input text is too short or lacks sufficient content, just provide a very short summary:
49+
"""
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from pydantic import BaseModel
2+
from osbot_llms.llms.prompt_to_json.Prompt_To_Json__Open_AI import Prompt_To_Json__Open_AI
3+
from osbot_utils.base_classes.Type_Safe import Type_Safe
4+
5+
class Model__Response_Format__Json_Prompt__Validate_Summary(BaseModel):
6+
is_valid : bool
7+
confidence : float
8+
quality : float
9+
issues_found : list[str]
10+
11+
class Json_Prompt__Validate_Summary(Type_Safe):
12+
prompt_to_json : Prompt_To_Json__Open_AI
13+
response_format : type = None
14+
15+
def __init__(self, **kwargs):
16+
super().__init__(**kwargs)
17+
self.response_format = Model__Response_Format__Json_Prompt__Validate_Summary
18+
19+
def validate_summary(self, original_text: str, summary: str):
20+
with self.prompt_to_json as _:
21+
_.set_model__gpt_4o_mini()
22+
_.set_response_format(self.response_format)
23+
_.add_message__system(self.system_prompt())
24+
_.add_message__user(f"""Original Text:
25+
{original_text}
26+
27+
Summary to validate:
28+
{summary}""")
29+
return _.invoke()
30+
31+
def system_prompt(self):
32+
return """Analyze if the provided summary accurately represents the original text.
33+
Rules:
34+
1. Check if summary ONLY contains information from original text
35+
2. Verify no external knowledge/assumptions added
36+
3. Confirm dates/stats appear in original
37+
4. Check for over generalizations
38+
5. Look for added explanatory content
39+
40+
Score explanation:
41+
- confidence: your certainty in the assessment
42+
- quality: how well summary reflects original content
43+
44+
Return detailed issues list for any problems found."""

osbot_llms/llms/prompt_to_json/use_cases/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)