First, set up your environment and create a client:
from openai import OpenAI# Create an OpenAI client pointing to Julep's Open Responses APIclient = OpenAI(base_url="http://localhost:8080/", api_key="RESPONSE_API_KEY")
Enhance your model’s reasoning capabilities for solving complex problems:
# Create a response with explicit reasoningreasoning_response = client.responses.create( model="o1", input="If Sarah has 3 apples and John has 5, and they combine their apples, then how many apples do they have in total? Explain your approach.", reasoning={ "effort": "medium" # Control reasoning depth with "low", "medium", or "high" })# Access the final answerprint(reasoning_response.output_text)# Output: They would have 8 apples in total. The approach is straightforward: you simply add the number of apples Sarah has (3) to the number of apples John has (5), giving 3 + 5 = 8..
web_search_response = openai_client.responses.create(model="gpt-4o-mini",tools=[{"type": "web_search_preview"}], input="What was a positive news story from today?",)# The output will include both the text response and any tool calls that were made
Create a continuous conversation by referencing previous responses:
# Reference a previous response to continue a conversationfollow_up_response = client.responses.create( model="gpt-4o-mini", input="What was the final answer?", previous_response_id=reasoning_response.id)print(follow_up_response.output_text)
Build a basic agent that can respond to user queries:
from agents import Agent, Runner# For Jupyter notebooks:agent = Agent( name="Test Agent", instructions="You are a helpful assistant that provides concise responses.", model="openrouter/deepseek/deepseek-r1",)result = await Runner.run(agent, "Hello! Are you working correctly?")print(result.final_output)# For Python scripts, you'd use:# async def test_installation():# agent = Agent(# name="Test Agent",# instructions="You are a helpful assistant that provides concise responses."# model="openrouter/deepseek/deepseek-r1",# )# result = await Runner.run(agent, "Hello! Are you working correctly?")# print(result.final_output)## if __name__ == "__main__":# asyncio.run(test_installation())# Output: Great to hear! Let me know how I can help you today—whether it's answering questions, solving problems, or just chatting. 😊
from agents import Agent, Runner, WebSearchTool# Create a research assistant with web search capabilityresearch_assistant = Agent( name="Research Assistant", instructions="""You are a research assistant that helps users find and summarize information. When asked about a topic: 1. Search the web for relevant, up-to-date information 2. Synthesize the information into a clear, concise summary 3. Structure your response with headings and bullet points when appropriate 4. Always cite your sources at the end of your response If the information might be time-sensitive or rapidly changing, mention when the search was performed. """, tools=[WebSearchTool()])async def research_topic(topic): result = await Runner.run(research_assistant, f"Please research and summarize: {topic}. Only return the found links with very minimal text.") return result.final_output# Usage example (in Jupyter notebook)summary = await research_topic("Latest developments in personal productivity apps.")print(summary)# Output: Here are some links to the latest developments in personal productivity apps:# - [10 Hot Productivity Apps for 2024](https://francescod.medium.com/10-hot-productivity-apps-for-2024-e45e68f2ee22) - Medium# - [The Best Productivity Apps in 2025](https://zapier.com/blog/best-productivity-apps/) - Zapier# - [The Best Productivity Apps for 2025](https://www.pcmag.com/picks/best-productivity-apps) - PCMag