Generate a brag document from a list of text chunks.
This function takes a list of text chunks, each representing a contribution or achievement,
and uses an AI agent to generate a comprehensive brag document. The brag document
highlights the user's accomplishments, technical skills, and contributions.
Each chunk is a string of text that represents a part of the document. Examples include:
- GitHub Pull Requests
- Blog posts
- Research papers
- Meeting notes
- Project reports
The caller is responsible for providing the chunks in the correct order and formatted in
a sensible manner.
Parameters:
Name |
Type |
Description |
Default |
model_name
|
KnownModelName
|
The name of the AI model to use for generating the brag document.
|
required
|
chunks
|
Iterable[str]
|
An iterable of strings, where each string is a chunk of text
representing a contribution or achievement. This is expected to contain at
least one chunk.
|
required
|
language
|
str
|
The language in which to generate the brag document.
|
'english'
|
|
str | None
|
An optional existing brag document to update with new
contributions. If provided, the function will update this document.
Otherwise, a new document will be generated from scratch.
|
None
|
Returns:
Type |
Description |
str
|
A string containing the generated brag document.
|
Source code in src/brag/agents.py
| async def generate_brag_document(
model_name: KnownModelName,
chunks: Iterable[str],
language: str = "english",
input_brag_document: str | None = None,
) -> str:
"""Generate a brag document from a list of text chunks.
This function takes a list of text chunks, each representing a contribution or achievement,
and uses an AI agent to generate a comprehensive brag document. The brag document
highlights the user's accomplishments, technical skills, and contributions.
Each chunk is a string of text that represents a part of the document. Examples include:
- GitHub Pull Requests
- Blog posts
- Research papers
- Meeting notes
- Project reports
The caller is responsible for providing the chunks in the correct order and formatted in
a sensible manner.
Args:
model_name: The name of the AI model to use for generating the brag document.
chunks: An iterable of strings, where each string is a chunk of text
representing a contribution or achievement. This is expected to contain at
least one chunk.
language: The language in which to generate the brag document.
input_brag_document: An optional existing brag document to update with new
contributions. If provided, the function will update this document.
Otherwise, a new document will be generated from scratch.
Returns:
A string containing the generated brag document.
"""
if input_brag_document:
# If an existing brag document is provided, use it as the starting point
brag_document = input_brag_document
# When using an existing document, we need to process all input chunks
# including the first one
chunks_to_process = chunks
else:
# If no existing document is provided, generate a new one from the first chunk
first_chunk, remaining_chunks = _head_and_tail(chunks)
# Generate initial summary from the first chunk.
initial_brag_document_generator_agent = _build_agent_from_system_prompt(
model_name,
system_prompt=f"""
You are an expert in creating compelling brag documents that highlight a person's achievements and skills.
Your task is to analyze a document and extract key accomplishments, technical skills demonstrated, and contributions made.
Focus on quantifiable results and impactful contributions.
Present the information in a concise and engaging manner, suitable for showcasing the individual's value.
Return only the generated brag document without extra comments or code fences.
Generate the brag document in {language}.
""",
)
brag_document = await _generate_initial_brag_document(
initial_brag_document_generator_agent,
first_chunk,
)
# We've already processed the first chunk, so only process the remaining ones
chunks_to_process = remaining_chunks
# Iteratively refine the brag document with the chunks
for chunk in chunks_to_process:
brag_document_updater_agent = _build_agent_from_system_prompt(
model_name,
system_prompt=f"""
You are an expert in refining existing brag documents by incorporating new information.
Your task is to integrate new context into an existing brag document, ensuring that the document remains concise, engaging, and highlights the individual's key achievements and skills.
Focus on seamlessly weaving in new accomplishments, technical skills, and contributions, while maintaining a consistent tone and style.
Feel free to modify and re-arrange existing content to better reflect the new information.
Return only the generated brag document without extra comments or code fences.
Generate the brag document in {language}.
""",
)
brag_document = await _update_brag_document(
brag_document_updater_agent, brag_document, chunk
)
return brag_document
|