|
| 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 | +""" |
0 commit comments