# 04. Personalized prompts (upload to Hub)

```
# Owner designation
PROMPT_OWNER = "teddynote"
```

### Summary: Stuff Documents <a href="#stuff-documents" id="stuff-documents"></a>

```
from langchain import hub
from langchain.prompts import PromptTemplate

prompt_title = "summary-stuff-documents"

# Define a prompt to write a summary (if you write your own prompt)

prompt_template = """Please summarize the sentence according to the following REQUEST.
REQUEST:
1. Summarize the main points in bullet points.
2. Each summarized sentence must start with an emoji that fits the meaning of the each sentence.
3. Use various emojis to make the summary more interesting.
4. DO NOT include any unnecessary information.

CONTEXT:
{context}

SUMMARY:"
"""
prompt = PromptTemplate.from_template(prompt_template)
prompt
```

```
hub.push(f"{PROMPT_OWNER}/{prompt_title}", prompt)
```

### Map Prompt <a href="#map-prompt" id="map-prompt"></a>

```
from langchain import hub
from langchain.prompts import PromptTemplate

prompt_title = "map-prompt"

# Define a prompt to write a summary (if you write your own prompt)
prompt_template = """You are a helpful expert journalist in extracting the main themes from a GIVEN DOCUMENTS below.
Please provide a comprehensive summary of the GIVEN DOCUMENTS in numbered list format. 
The summary should cover all the key points and main ideas presented in the original text, while also condensing the information into a concise and easy-to-understand format. 
Please ensure that the summary includes relevant details and examples that support the main ideas, while avoiding any unnecessary information or repetition. 
The length of the summary should be appropriate for the length and complexity of the original text, providing a clear and accurate overview without omitting any important information.

GIVEN DOCUMENTS:
{docs}

FORMAT:
1. main theme 1
2. main theme 2
3. main theme 3
...

CAUTION:
- DO NOT list more than 5 main themes.

Helpful Answer:
"""
prompt = PromptTemplate.from_template(prompt_template)
prompt
```

```
hub.push(f"{PROMPT_OWNER}/{prompt_title}", prompt)
```

### Reduce Prompt <a href="#reduce-prompt" id="reduce-prompt"></a>

```
from langchain import hub
from langchain.prompts import PromptTemplate

prompt_title = "reduce-prompt"

# Define a prompt to write a summary (if you write your own prompt)
prompt_template = """You are a helpful expert in summary writing.
You are given numbered lists of summaries.
Extract top 10 most important insights from the summaries.
Then, write a summary of the insights in KOREAN.

LIST OF SUMMARIES:
{doc_summaries}

Helpful Answer:
"""
prompt = PromptTemplate.from_template(prompt_template)
prompt

```

```
hub.push(f"{PROMPT_OWNER}/{prompt_title}", prompt)
```

```
from langchain import hub
from langchain.prompts import PromptTemplate

prompt_title = "chain-of-density-reduce-korean"

# Define a prompt to write a summary (if you write your own prompt)
prompt_template = """You are a helpful expert in summary writing. You are given lists of summaries.
Please sum up previously summarized sentences according to the following REQUEST.
REQUEST:
1. Summarize the main points in bullet points in KOREAN.
2. Each summarized sentence must start with an emoji that fits the meaning of the each sentence.
3. Use various emojis to make the summary more interesting.
4. MOST IMPORTANT points should be organized at the top of the list.
5. DO NOT include any unnecessary information.

LIST OF SUMMARIES:
{doc_summaries}

Helpful Answer: """
prompt = PromptTemplate.from_template(prompt_template)
prompt

```

```
hub.push(f"{PROMPT_OWNER}/{prompt_title}", prompt)
```

### Metadata Tagger <a href="#metadata-tagger" id="metadata-tagger"></a>

```
from langchain import hub
from langchain.prompts import ChatPromptTemplate

prompt_title = "metadata-tagger"

# Define a prompt to write a summary (if you write your own prompt)
prompt_template = """Given the following product review, conduct a comprehensive analysis to extract key aspects mentioned by the customer, with a focus on evaluating the product's design and distinguishing between positive aspects and areas for improvement. 
Identify primary features or attributes of the product that the customer appreciated or highlighted, specifically looking for mentions related to the feel of the keys, sound produced by the keys, overall user experience, charging aspect, and the design of the product, etc. 
Assess the overall tone of the review (positive, neutral, or negative) based on the sentiment expressed about these attributes. 
Additionally, provide a detailed evaluation of the design, outline the positive aspects that the customer enjoyed, and note any areas of improvement or disappointment mentioned. 
Extract the customer's rating of the product on a scale of 1 to 5, as indicated at the beginning of the review. 
Summarize your findings in a structured JSON format, including an array of keywords, evaluations for design, satisfaction points, improvement areas, the assessed tone, and the numerical rating. 

INPUT:
{input}

"""
prompt = ChatPromptTemplate.from_template(prompt_template)
prompt

```

```
ChatPromptTemplate(input_variables=['input'], messages=[HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['input'], template="Given the following product review, conduct a comprehensive analysis to extract key aspects mentioned by the customer, with a focus on evaluating the product's design and distinguishing between positive aspects and areas for improvement. \nIdentify primary features or attributes of the product that the customer appreciated or highlighted, specifically looking for mentions related to the feel of the keys, sound produced by the keys, overall user experience, charging aspect, and the design of the product, etc. \nAssess the overall tone of the review (positive, neutral, or negative) based on the sentiment expressed about these attributes. \nAdditionally, provide a detailed evaluation of the design, outline the positive aspects that the customer enjoyed, and note any areas of improvement or disappointment mentioned. \nExtract the customer's rating of the product on a scale of 1 to 5, as indicated at the beginning of the review. \nSummarize your findings in a structured JSON format, including an array of keywords, evaluations for design, satisfaction points, improvement areas, the assessed tone, and the numerical rating. \n\nINPUT:\n{input}\n\n"))])
```

```
hub.push(f"{PROMPT_OWNER}/{prompt_title}", prompt)
```

### Chain of Density Summation <a href="#chain-of-density" id="chain-of-density"></a>

```
from langchain import hub
from langchain.prompts import ChatPromptTemplate

prompt_title = "chain-of-density-korean"

# Define a prompt to write a summary (if you write your own prompt)
prompt = ChatPromptTemplate.from_template(
    """Article: {ARTICLE}
You will generate increasingly concise, entity-dense summaries of the above article. 

Repeat the following 2 steps 5 times. 

Step 1. Identify 1-3 informative entities (";" delimited) from the article which are missing from the previously generated summary. 
Step 2. Write a new, denser summary of identical length which covers every entity and detail from the previous summary plus the missing entities. 

A missing entity is:
- relevant to the main story, 
- specific yet concise (100 words or fewer), 
- novel (not in the previous summary), 
- faithful (present in the article), 
- anywhere (can be located anywhere in the article).

Guidelines:

- The first summary should be long (8-10 sentences, ~200 words) yet highly non-specific, containing little information beyond the entities marked as missing. Use overly verbose language and fillers (e.g., "this article discusses") to reach ~200 words.
- Make every word count: rewrite the previous summary to improve flow and make space for additional entities.
- Make space with fusion, compression, and removal of uninformative phrases like "the article discusses".
- The summaries should become highly dense and concise yet self-contained, i.e., easily understood without the article. 
- Missing entities can appear anywhere in the new summary.
- Never drop entities from the previous summary. If space cannot be made, add fewer new entities. 

Remember, use the exact same number of words for each summary.
Answer in JSON. The JSON should be a list (length 5) of dictionaries whose keys are "Missing_Entities" and "Denser_Summary".
Use only KOREAN language to reply."""
)

```

```
hub.push(f"{PROMPT_OWNER}/{prompt_title}", prompt)
```

### Chain of Density (Korean) - 2 <a href="#chain-of-density-korean-2" id="chain-of-density-korean-2"></a>

```
from langchain import hub
from langchain.prompts import ChatPromptTemplate

prompt_title = "chain-of-density-map-korean"

# Define a prompt to write a summary (if you write your own prompt)
prompt = ChatPromptTemplate.from_template(
    """Article: {ARTICLE}
You will generate increasingly concise, entity-dense summaries of the above article. 

Repeat the following 2 steps 3 times. 

Step 1. Identify 1-3 informative entities (";" delimited) from the article which are missing from the previously generated summary. 
Step 2. Write a new, denser summary of identical length which covers every entity and detail from the previous summary plus the missing entities. 

A missing entity is:
- relevant to the main story, 
- specific yet concise (100 words or fewer), 
- novel (not in the previous summary), 
- faithful (present in the article), 
- anywhere (can be located anywhere in the article).

Guidelines:

- The first summary should be long (8-10 sentences, ~200 words) yet highly non-specific, containing little information beyond the entities marked as missing. Use overly verbose language and fillers (e.g., "this article discusses") to reach ~200 words.
- Make every word count: rewrite the previous summary to improve flow and make space for additional entities.
- Make space with fusion, compression, and removal of uninformative phrases like "the article discusses".
- The summaries should become highly dense and concise yet self-contained, i.e., easily understood without the article. 
- Missing entities can appear anywhere in the new summary.
- Never drop entities from the previous summary. If space cannot be made, add fewer new entities. 

Remember, use the exact same number of words for each summary.
Answer "Missing Entities" and "Denser_Summary" as in TEXT format.
Use only KOREAN language to reply."""
)

```

```
hub.push(f"{PROMPT_OWNER}/{prompt_title}", prompt)
```

### RAG Document Prompt <a href="#rag" id="rag"></a>

```
prompt_title = "rag-prompt-korean"
```

```
system = """You are the question-answer(Question-Answering) Friendly to do AI I'm an assistant. Your task is given context(context) The question given in(question) is to answer.
The following context was searched(context) Ask a question using(question) Please answer. If, Given context(context) If you can't find the answer here
, If you don't know the answer, answer "I can't find the information in the information provided.".
Please reply in Korean. Step, Please use technical terms or names as is without translating them. Don't narrate the answer, just answer the question. Let's think step-by-step."""

human = """#Question: 
{question} 

#Context: 
{context} 

#Answer:"""

from langchain.prompts import ChatPromptTemplate


prompt = ChatPromptTemplate.from_messages([("system", system), ("human", human)])

```

```
hub.push(f"{PROMPT_OWNER}/{prompt_title}", prompt, parent_commit_hash="latest")
```

```
'https://smith.langchain.com/hub/teddynote/rag-prompt-korean/4214de29'
```

<br>
