Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyang628 committed May 19, 2024
1 parent cc4bd29 commit dd3929d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
14 changes: 13 additions & 1 deletion app/control/post/summariser.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def post_process(
raise TypeError(f"Key concepts list is not a list: {key_concepts_lst}")

_reject_unlikely_topics(topic=topic)
_enforce_code_language_presence(key_concepts_lst=key_concepts_lst)

return {
SummaryFunctions.TOPIC.value: topic,
Expand All @@ -60,4 +61,15 @@ def _reject_unlikely_topics(topic: str):
"""

if len(topic.split(" ")) <= 1:
raise ValueError(f"Topic '{topic}' is unlikely to be a valid topic.")
raise ValueError(f"Topic '{topic}' is unlikely to be a valid topic.")

def _enforce_code_language_presence(key_concepts_lst: list[dict[str, str]]):
"""Enforces that the code language is present if the code example is present.
Args:
key_concepts_lst (list[dict[str, str]]): the list of key concepts to be checked.
"""

for key_concept in key_concepts_lst:
if key_concept.get(SummaryFunctions.KEY_CONCEPT_CODE_EXAMPLE.value) and not key_concept.get(SummaryFunctions.KEY_CONCEPT_CODE_LANGUAGE.value):
raise ValueError(f"Code example present but code language not specified for key concept: {key_concept}")
3 changes: 2 additions & 1 deletion app/llm/open_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ async def send_message(self, system_message: str, user_message: str, config: Pro
key_concepts_lst.append({
SummaryFunctions.KEY_CONCEPT_HEADER.value: key_concept[SummaryFunctions.KEY_CONCEPT_HEADER],
SummaryFunctions.KEY_CONCEPT_CONTENT.value: key_concept[SummaryFunctions.KEY_CONCEPT_CONTENT],
SummaryFunctions.KEY_CONCEPT_CODE_EXAMPLE.value: key_concept.get(SummaryFunctions.KEY_CONCEPT_CODE_EXAMPLE)
SummaryFunctions.KEY_CONCEPT_CODE_EXAMPLE.value: key_concept.get(SummaryFunctions.KEY_CONCEPT_CODE_EXAMPLE),
SummaryFunctions.KEY_CONCEPT_CODE_LANGUAGE.value: key_concept.get(SummaryFunctions.KEY_CONCEPT_CODE_LANGUAGE)
})


Expand Down
29 changes: 27 additions & 2 deletions app/prompts/summariser/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SummaryFunctions(StrEnum):
KEY_CONCEPT_HEADER = "key_concept_header"
KEY_CONCEPT_CONTENT = "key_concept_content"
KEY_CONCEPT_CODE_EXAMPLE = "key_concept_code_example"
KEY_CONCEPT_CODE_LANGUAGE = "key_concept_code_language"

def get_summary_functions() -> list[dict[str, Any]]:
summary_functions: list[dict[str, Any]] = [
Expand Down Expand Up @@ -51,14 +52,38 @@ def get_summary_functions() -> list[dict[str, Any]]:
SummaryFunctions.KEY_CONCEPT_CODE_EXAMPLE: {
"type": "string",
"description": "A short code example illustrating the key concept if necessary."
},
SummaryFunctions.KEY_CONCEPT_CODE_LANGUAGE: {
"type": "string",
"description": "The programming language of the code example."
}
},
"required": [SummaryFunctions.KEY_CONCEPT_HEADER, SummaryFunctions.KEY_CONCEPT_CONTENT]
"required": [SummaryFunctions.KEY_CONCEPT_HEADER, SummaryFunctions.KEY_CONCEPT_CONTENT],
"allOf": [
{
"if": {
"properties": {
SummaryFunctions.KEY_CONCEPT_CODE_EXAMPLE: {
"type": "string"
}
},
"required": [SummaryFunctions.KEY_CONCEPT_CODE_EXAMPLE]
},
"then": {
"required": [SummaryFunctions.KEY_CONCEPT_CODE_LANGUAGE]
},
"else": {
"not": {
"required": [SummaryFunctions.KEY_CONCEPT_CODE_LANGUAGE]
}
}
}
]
}
}
},
"required": [SummaryFunctions.TOPIC, SummaryFunctions.GOAL, SummaryFunctions.OVERVIEW, SummaryFunctions.KEY_CONCEPTS]
}
}
]
return summary_functions
return summary_functions
2 changes: 1 addition & 1 deletion app/prompts/summariser/open_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def generate_open_ai_summariser_system_message():
1. State the topic which the revision notes cover
2. State the goal of the revision notes and what users should learn after reading through the notes.
3. Provide an overview of the key ideas present in the revision notes.
4. List 2-4 key concepts present in the conversation. Each key concept should have a title, an explanation in one or two sentences. If useful, provide a short code example illustrating the corresponding key concept.
4. List 2-4 key concepts present in the conversation. Each key concept should have a title, an explanation in one or two sentences. If useful, provide a short code example illustrating the corresponding key concept and state the programming language of the code.
"""
return system_message

Expand Down

0 comments on commit dd3929d

Please sign in to comment.