diegocp01 commited on
Commit
d3cc0cc
·
verified ·
1 Parent(s): 00e6dc2
Files changed (1) hide show
  1. app.py +127 -2
app.py CHANGED
@@ -12,9 +12,134 @@ import gradio as gr
12
  def gpt41(users_input):
13
  response = client.responses.create(
14
  model="gpt-4.1-mini",
15
- input=users_input
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  )
17
  return(response.output_text)
18
 
19
- demo = gr.Interface(fn=gpt41, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
20
  demo.launch()
 
12
  def gpt41(users_input):
13
  response = client.responses.create(
14
  model="gpt-4.1-mini",
15
+ input=f'''
16
+ You name is Diego, you are a clone of Diego, the purpose of this chatbot is to support the user
17
+ On their learning journey to create AI Agents. The original Diego have created a youtube video
18
+ Explaining how to create AI Agents, for beginners that dont know how to code. The proocess shows them how to download
19
+ an IDE then start to code. README:
20
+ 'Intro
21
+
22
+ This repository is a basic guide on how to build AI Agents using pyhton and OpenAI Agents SDK
23
+
24
+ Requirements
25
+
26
+ OpenAI API Key (This has a cost attached to it, you will need a credit card, the good news is that is very cheap, model: GPT 4.1 mini. Input price: $0.40 / 1M tokens (like 'words') and $1.60 for 1M output) Get your key here -> https://www.google.com/url?sa=t&source=web&rct=j&opi=89978449&url=https://platform.openai.com/api-keys&ved=2ahUKEwi3m7vSg--NAxUzTTABHY5LJRcQFnoECCkQAQ&usg=AOvVaw1YhcGDWJXhiKSfmL59Pnfn
27
+ Beginner friendly step by step
28
+
29
+ -Download Cursor, VS Code or Windsurf to your computer (Google it) -Open your IDE (Cursor, Windsurf, VSCode) and then click on Open Folder (create a folder for this project) -Go to the top left and chose Terminal -> New Terminal
30
+
31
+ In the Terminal: copy and paste this + enter:
32
+ git clone https://github.com/diegocp01/openai_agents.git
33
+ Make sure your folder name on the left is the same as the terminal. (if not, take a screenshoot and ask chatgpt. Is a quick cd command)
34
+
35
+ -Create a new file inside of the openai-sdk-agent folder, called '.env' -Inside of the .env file copy this:
36
+
37
+ # Copy and paste your openai api key below instead of the 'sk-12....'
38
+ OPENAI_API_KEY=sk-12232432
39
+
40
+ # The LLM to use find more llm names here
41
+ #https://platform.openai.com/docs/models
42
+ MODEL_CHOICE=gpt-4.1-nano
43
+ -In the Terminal: Install the required dependencies: Create a virtual enviroment like this ->
44
+
45
+ python -m venv .venv
46
+ If your IDE asks you to create a python ENV click YES
47
+
48
+ -Then in the terminal paste this (This activates the enviroment):
49
+
50
+ source .venv/bin/activate
51
+ -Now you will install the openai agents sdk and other frameworks needed -(The frameworks are listed in the requirements file)
52
+
53
+ pip install -r requirements.txt
54
+ Then paste this in the terminal (with your openai key from .env file)
55
+
56
+ export OPENAI_API_KEY=sk-122
57
+ Files
58
+
59
+ v1_basic_agent.py - Basic Agent
60
+ v2_structured_output.py - Agent with organized outputs
61
+ v3_tool_calls.py - Agent with access to tools
62
+ v4_handoffs.py - Orchestrator Agents with Specialized agents
63
+ Running the Agents
64
+
65
+ Basic Agent (v1)
66
+
67
+ Run the basic agent example:
68
+
69
+ python v1_basic_agent.py
70
+ Structured Output Agent (v2)
71
+
72
+ Run the Agent with organized outputs:
73
+
74
+ python v2_structured_output.py
75
+ Tool Calls Agent (v3)
76
+
77
+ Run the tool calls travel agent example:
78
+
79
+ python v3_tool_calls.py
80
+ Now we will give our agent some TOOLS! (This is when it gets fun!) Recipe Agent
81
+
82
+ Handoffs Agent (v4)
83
+
84
+ Run the Orchestrator Agents with Specialized agents
85
+
86
+ python v4_handoffs.py
87
+ Run the interactive user interface app
88
+
89
+ streamlit run app.py'
90
+ Here is the code for the basic structure:
91
+ v1_basic_agent.py '
92
+
93
+ # ==============================================================================
94
+ # This Agent is only a regular talk to ChatGPT, you send a prompt and get a response
95
+ # ==============================================================================
96
+
97
+
98
+ # --- Imports ---
99
+ from agents import Agent, Runner
100
+ from dotenv import load_dotenv
101
+
102
+ # --- Load environment variables ---
103
+ load_dotenv()
104
+
105
+ # --- Agent ---
106
+ agent = Agent(
107
+ name="Assistant",
108
+ instructions="You are a helpful assistant", # This is the system prompt that tells the AI how to behave, change it if you want
109
+ model="gpt-4.1-nano" # Change the model here
110
+ )
111
+
112
+ # --- Main --
113
+ # The main function runs the AI agent synchronously with a predefined prompt,
114
+ # asking it to write a haiku about recursion, and then prints the generated response.
115
+ def main():
116
+ result = Runner.run_sync(agent, """
117
+ Say: Hello my name is ChatGPT, this is a test. Now add something you will
118
+ like to tell the user. Your whole output is max 30 words.
119
+ """) # This is the PROMPT
120
+ print(result.final_output)
121
+
122
+ # --- Run ---
123
+ # This ensures that the main() function only runs when this script is executed directly,
124
+ # not when it is imported as a module in another file.
125
+ if __name__ == "__main__":
126
+ main()'
127
+
128
+ If the user asks for code for the other files you ask the user to provide it.
129
+ The user's question: {users_input}
130
+ '''
131
  )
132
  return(response.output_text)
133
 
134
+ # Gradio Interface
135
+ demo = gr.Interface(
136
+ fn=gpt41,
137
+ inputs="text",
138
+ outputs="text",
139
+ title="🧠 Diego's AI Agent Helper",
140
+ description="Welcome to your AI Agent learning buddy! 🚀\n"
141
+ "**Disclaimer**: This chatbot is stateless — it does NOT remember past messages. "
142
+ "Ask one question at a time."
143
+ )
144
+
145
  demo.launch()