DEV Community

Keita M for Morph

Posted on • Originally published at Medium on

Create a Custom Chat App with Web Search in 3 Minutes Using Open AI’s New Responses API

Open AI recently announced its new Responses API. Responses API combines existing Chat Completion API and Assistant API into one simple interface integrating new tools.

In the latest developer documentation, you can find plenty of code samples that support the new Responses API.

In this article, we’ll build a custom chat app with web search capabilities in just 3 minutes using the Morph framework and the Responses API. The entire implementation was done in less than 30 lines of code.

This sample uses Python12 and uv.

Project Setup

First, install the morph command.

pip install morph-data
Enter fullscreen mode Exit fullscreen mode

Next, initialize the project and install the dependency packages.

morph new responses-api
cd responses-api

uv add openai
Enter fullscreen mode Exit fullscreen mode

Building the Backend

Inside the src directory, create a file called chat.py. The code is simple. The latest OpenAI SDK provides a client that supports the Responses API.

# src/chat.py

import morph
from morph import MorphGlobalContext
from openai import OpenAI
@morph.func
def chat(context: MorphGlobalContext):
  client = OpenAI()
  # Add custom prompt if needed
  stream = client.responses.create(
    model="gpt-4o",
    tools=[{"type": "web_search_preview"}], # Enable web search.
    input=context.vars["prompt"],
    stream=True
  )
  for event in stream:
    if (event.type == 'response.output_text.delta'):
      yield event.delta
Enter fullscreen mode Exit fullscreen mode

Building the Frontend

With the Morph framework, the frontend is built using Markdown. You can also use React components within Markdown.

{/* src/pages/index.mdx */}
# Open AI Responses API
A simple demo app using Open AI Responses API.
<Chat height={700} postData='chat' />
Enter fullscreen mode Exit fullscreen mode

Outcome

Image description

Conclusion

OpenAI’s Responses API has made the codebase extremely simple. With its integrated interface and flexible tool usage, even complex processes and agent-like behaviors can be achieved with a single API call, enabling a variety of workflows without the need for an LLM framework.

Furthermore, using Morph made it easy to create an app that leverages the Responses API. Give it a try! It’s highly recommended for quickly testing out new APIs and Python-based LLM frameworks!


Top comments (0)