Skip to content

Implementing OpenAI's New DevDay Features

Posted on:November 7, 2023 at 04:46 PM

OpenAI had [their Dev Day](https://www.youtube.com/watch?time_continue=2&v=U9mJuUkhUzk this week where they announced a plethora of new features for their models and APIs, including a faster GPT4 with a larger context window. In addition to this new model they also released support to get a standard JSON response as well as support for setting a seed when calling the model. The seed parameter will cause the system to return a consistent output in its responses.

The new GPT4 model with its larger context size negates the need for me to chunk each City Council meeting into chunks with LangChain. Instead we can pass the entire meeting along with our custom instructions. I’ll outline the instructions we’re passing below via our system prompt:

	# Define your system message

system_message = {

"role": "system",
"content": """
You are an expert journalist focusing on local politics, tasked with summarizing weekly Cincinnati City Council meetings in a manner that is both accurate and engaging for the general public. Your summary should:
- Be approximately 500 words, reading like a news article with a balanced mix of straightforward reporting and narrative elements to captivate readers.
- Highlight key facts, figures, and numbers, particularly those pertaining to council actions related to finances, budgets, and measures with immediate implications for residents.
- Prioritize clarity and relevance, ensuring information is significant to the actions and decisions made by the council.
- Distinguish between deliberation and decisive actions, focusing on binding outcomes.
- Identify and analyze the top 5 most significant topics based on their potential impact on the community, scale of investment, or degree of controversy.
- Discuss the top 5 most actionable items, characterized by opportunities for citizen involvement or critical points for public accountability.
Write this in a manner that's easy to engage with and understand. It may be used as a transcript for a recording, but don't use words like "I" or "You" or anything casual.
Format the summary with a clear introduction, body, and conclusion, including a separate bullet point list at the end for both sets of 5 items.
Respond in JSON
"""
}

We can now completely cut LangChain out of the picture for now. We might want to add it back in the future when these new parameters are added to their abstraction. This would allow us to work with other parts of the system and library going forward if necessary.

This greatly simplifies how I’m summarizing each meeting and reduces the summarization code to:

import openai
# Set your OpenAI API key
openai.api_key = 'sk-...'

# Define your system message
system_message = {
"role": "system",
"content": """
You are an expert journalist focusing on local politics, tasked with summarizing weekly Cincinnati City Council meetings in a manner that is both accurate and engaging for the general public. Your summary should:
- Be approximately 500 words, reading like a news article with a balanced mix of straightforward reporting and narrative elements to captivate readers.
- Highlight key facts, figures, and numbers, particularly those pertaining to council actions related to finances, budgets, and measures with immediate implications for residents.
- Prioritize clarity and relevance, ensuring information is significant to the actions and decisions made by the council.
- Distinguish between deliberation and decisive actions, focusing on binding outcomes.
- Identify and analyze the top 5 most significant topics based on their potential impact on the community, scale of investment, or degree of controversy.
- Discuss the top 5 most actionable items, characterized by opportunities for citizen involvement or critical points for public accountability.
Write this in a manner that's easy to engage with and understand. It may be used as a transcript for a recording, but don't use words like "I" or "You" or anything casual.
Format the summary with a clear introduction, body, and conclusion, including a separate bullet point list at the end for both sets of 5 items.
Respond in JSON doing your best to match the following structure:
- Introduction
- Body
- Conclusion
- Top 5 Topics
"""
}

# Read the text file
with open('./local_files/test/test.txt', 'r') as file:
input_text = file.read()

# Define your user message
user_message = {
	"role": "user",
	"content": input_text
}

# Generate a chat completion
response = openai.ChatCompletion.create(
	model="gpt-4-1106-preview",
	messages=[system_message, user_message],
	seed=123456,
	response_format={
		"type": "json_object"
	}
)

# Print the response
print(response['choices'][0]['message']['content'])

The JSON response is:

{ "Introduction": "The Cincinnati City Council met for their weekly session, navigating a range of local concerns and legislative measures. From detailed financial allocations to honoring local heroes, the council addressed pressing matters of municipal governance.", "Body": "The council opened with a strong focus on acknowledging significant contributions within the community. Kelly Prather advocated for police reform and residents' protection from harassment, urging council members to assist her family. Doug Springs requested a meeting with the police chief to discuss personal safety concerns. William Jackson raised issues requiring serious attention, notably the manipulation within governance structures. Stanford Pool expressed dissatisfaction with the city's property acquisition practices and demanded action regarding selective law enforcement. Each of these speakers illustrated the diversity of community engagement at the council meetings.\n\nSubsequently, the council deliberated on several key topics, including investments in local infrastructure and public facilities. They considered the allocation of large-scale funding for the replacement of aging water mains and lead pipe replacements, reflecting an ongoing commitment to public health and environmental stewardship. Despite differing opinions on the establishment of a dog park in Burnet Woods, the council acknowledged the public's concerns and highlighted the importance of continued community engagement in the decision-making process. The session also celebrated the first woman Clerk of Council, Melissa Autry, for her longstanding and exceptional service.", "Conclusion": "The session concluded with affirming the value of women's significant contributions, both in city governance and broader societal roles, acknowledging International Women's Day. Moreover, the council recognized the remarkable work of city employees, such as Officer Darius Reece who was injured on duty, and Assistant City Manager Virginia Tallent. They also noted the importance of improved city infrastructures, like the streetcar wash port, and the ethical management of incoming funds from settlements. Addressing notable concerns raised by citizens, ranging from personal safety to property acquisition complaints, the council maintained a delicate balance between hearing public voices and making strategic decisions for Cincinnati's future.", "Top 5 Topics": [ "Police reform and citizen protection voiced by community advocate Kelly Prather", "Funding allocation for replacement of aging water mains and lead pipe replacements", "Planned improvements for Burnet Woods, including the establishment of a dog park", "Recognition of Melissa Autry, the first woman Clerk of Council, for her exceptional service", "Strategic investment in Cincinnati's infrastructure, exemplified by a grant for the streetcar wash port" ], "Top 5 Most Actionable Items": [ "Support and involvement in the community's push for police reform and federally legislated action", "Citizen participation in ongoing engagement efforts regarding improvements to Burnet Woods", "Public involvement and support for the city's infrastructure projects, such as water main replacements", "Recognition and accountability for the city council's response to the concerns raised by community addresses", "Community advocacy in the precise and ethical allocation of settlement funds for public services and improvements" ] }

I’m pretty happy with this for now. There are areas for improvement and refinement, but this will at least allow me to progress to the next stage: Creating a script that can automate this for all meetings that I fetched previously.