T-K-O-H commited on
Commit
ae52b28
·
1 Parent(s): 59f3ecb

Update code to use environment variables and improve error handling

Browse files
Files changed (3) hide show
  1. push_git.bat +3 -0
  2. push_huggingface.bat +4 -0
  3. test_agent.py +16 -5
push_git.bat ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ @echo off
2
+ git push origin main
3
+ git push upstream main
push_huggingface.bat ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ @echo off
2
+ git add .
3
+ git commit -m "Update code to use environment variables and improve error handling"
4
+ git push origin main
test_agent.py CHANGED
@@ -7,6 +7,13 @@ import os
7
  # Load environment variables from .env file
8
  load_dotenv()
9
 
 
 
 
 
 
 
 
10
  # Define tools
11
  tools = [
12
  Tool(
@@ -16,14 +23,18 @@ tools = [
16
  ),
17
  Tool(
18
  name="BuyingPowerCalculator",
19
- func=lambda q: buying_power_tool(q.split(',')[0], float(q.split(',')[1])),
20
- description="Calculate how many shares you can buy. Input format: 'AAPL,5000'"
21
  )
22
  ]
23
 
24
- # Create agent
25
- llm = ChatOpenAI(model="gpt-4", temperature=0)
26
- agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
 
 
 
 
27
 
28
  # Run a test
29
  response = agent.run("How much is AAPL?")
 
7
  # Load environment variables from .env file
8
  load_dotenv()
9
 
10
+ # Initialize the language model with API key from environment variables
11
+ llm = ChatOpenAI(
12
+ temperature=0,
13
+ model_name="gpt-3.5-turbo",
14
+ openai_api_key=os.getenv("OPENAI_API_KEY")
15
+ )
16
+
17
  # Define tools
18
  tools = [
19
  Tool(
 
23
  ),
24
  Tool(
25
  name="BuyingPowerCalculator",
26
+ func=buying_power_tool,
27
+ description="Calculate how many shares you can buy. Input format: 'TICKER,AMOUNT' (e.g., 'AAPL,5000')"
28
  )
29
  ]
30
 
31
+ # Initialize the agent
32
+ agent = initialize_agent(
33
+ tools,
34
+ llm,
35
+ agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
36
+ verbose=True
37
+ )
38
 
39
  # Run a test
40
  response = agent.run("How much is AAPL?")