Merge branch 'fix/openai-prompt-caching-optimization-2355'
This commit is contained in:
@@ -2832,9 +2832,11 @@ async def extract_entities(
|
||||
cache_keys_collector = []
|
||||
|
||||
# Get initial extraction
|
||||
# Format system prompt without input_text for each chunk (enables OpenAI prompt caching across chunks)
|
||||
entity_extraction_system_prompt = PROMPTS[
|
||||
"entity_extraction_system_prompt"
|
||||
].format(**{**context_base, "input_text": content})
|
||||
].format(**context_base)
|
||||
# Format user prompts with input_text for each chunk
|
||||
entity_extraction_user_prompt = PROMPTS["entity_extraction_user_prompt"].format(
|
||||
**{**context_base, "input_text": content}
|
||||
)
|
||||
|
||||
@@ -58,18 +58,10 @@ You are a Knowledge Graph Specialist responsible for extracting entities and rel
|
||||
|
||||
---Examples---
|
||||
{examples}
|
||||
|
||||
---Real Data to be Processed---
|
||||
<Input>
|
||||
Entity_types: [{entity_types}]
|
||||
Text:
|
||||
```
|
||||
{input_text}
|
||||
```
|
||||
"""
|
||||
|
||||
PROMPTS["entity_extraction_user_prompt"] = """---Task---
|
||||
Extract entities and relationships from the input text to be processed.
|
||||
Extract entities and relationships from the input text in Data to be Processed below.
|
||||
|
||||
---Instructions---
|
||||
1. **Strict Adherence to Format:** Strictly adhere to all format requirements for entity and relationship lists, including output order, field delimiters, and proper noun handling, as specified in the system prompt.
|
||||
@@ -77,6 +69,15 @@ Extract entities and relationships from the input text to be processed.
|
||||
3. **Completion Signal:** Output `{completion_delimiter}` as the final line after all relevant entities and relationships have been extracted and presented.
|
||||
4. **Output Language:** Ensure the output language is {language}. Proper nouns (e.g., personal names, place names, organization names) must be kept in their original language and not translated.
|
||||
|
||||
---Data to be Processed---
|
||||
<Entity_types>
|
||||
[{entity_types}]
|
||||
|
||||
<Input Text>
|
||||
```
|
||||
{input_text}
|
||||
```
|
||||
|
||||
<Output>
|
||||
"""
|
||||
|
||||
@@ -99,7 +100,10 @@ Based on the last extraction task, identify and extract any **missed or incorrec
|
||||
"""
|
||||
|
||||
PROMPTS["entity_extraction_examples"] = [
|
||||
"""<Input Text>
|
||||
"""<Entity_types>
|
||||
["Person","Creature","Organization","Location","Event","Concept","Method","Content","Data","Artifact","NaturalObject"]
|
||||
|
||||
<Input Text>
|
||||
```
|
||||
while Alex clenched his jaw, the buzz of frustration dull against the backdrop of Taylor's authoritarian certainty. It was this competitive undercurrent that kept him alert, the sense that his and Jordan's shared commitment to discovery was an unspoken rebellion against Cruz's narrowing vision of control and order.
|
||||
|
||||
@@ -124,7 +128,10 @@ relation{tuple_delimiter}Taylor{tuple_delimiter}The Device{tuple_delimiter}rever
|
||||
{completion_delimiter}
|
||||
|
||||
""",
|
||||
"""<Input Text>
|
||||
"""<Entity_types>
|
||||
["Person","Creature","Organization","Location","Event","Concept","Method","Content","Data","Artifact","NaturalObject"]
|
||||
|
||||
<Input Text>
|
||||
```
|
||||
Stock markets faced a sharp downturn today as tech giants saw significant declines, with the global tech index dropping by 3.4% in midday trading. Analysts attribute the selloff to investor concerns over rising interest rates and regulatory uncertainty.
|
||||
|
||||
@@ -151,7 +158,10 @@ relation{tuple_delimiter}Federal Reserve Policy Announcement{tuple_delimiter}Mar
|
||||
{completion_delimiter}
|
||||
|
||||
""",
|
||||
"""<Input Text>
|
||||
"""<Entity_types>
|
||||
["Person","Creature","Organization","Location","Event","Concept","Method","Content","Data","Artifact","NaturalObject"]
|
||||
|
||||
<Input Text>
|
||||
```
|
||||
At the World Athletics Championship in Tokyo, Noah Carter broke the 100m sprint record using cutting-edge carbon-fiber spikes.
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user