First, set up your environment and create a client:
Copy
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:
Copy
# 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:
Copy
# 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)