Skip to content

Commit

Permalink
Update OpenAI cookbook
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpreetbedi committed Sep 27, 2024
1 parent 7654f92 commit 5cde751
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 41 deletions.
30 changes: 12 additions & 18 deletions cookbook/providers/openai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,41 @@ export OPENAI_API_KEY=***
### 3. Install libraries

```shell
pip install -U openai duckduckgo-search duckdb yfinance exa_py phidata
pip install -U openai duckduckgo-search duckdb yfinance phidata
```

### 4. Run Agent
### 4. Run Agent without Tools

- stream off
- Streaming on

```shell
python cookbook/providers/openai/basic.py
python cookbook/providers/openai/basic_stream.py
```

- stream on
- Streaming off

```shell
python cookbook/providers/openai/basic_stream.py
python cookbook/providers/openai/basic.py
```

### 5. Run Agent with Tools

- DuckDuckGo Search

```shell
python cookbook/providers/openai/agent.py
```

- DuckDuckGo Search Stream
- DuckDuckGo Search with streaming on

```shell
python cookbook/providers/openai/agent_stream.py
```

- YFinance
- DuckDuckGo Search without streaming

```shell
python cookbook/providers/openai/finance.py
python cookbook/providers/openai/agent.py
```

- Exa Search
- Finance Agent

```shell
python cookbook/providers/openai/exa_search.py
python cookbook/providers/openai/finance_agent.py
```

- Data Analyst
Expand All @@ -67,7 +61,7 @@ python cookbook/providers/openai/exa_search.py
python cookbook/providers/openai/data_analyst.py
```

### 6. Run Agent with Structured output
### 6. Run Agent that returns structured output

```shell
python cookbook/providers/openai/structured_output.py
Expand Down
4 changes: 2 additions & 2 deletions cookbook/providers/openai/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
)

# Get the response in a variable
# run: RunResponse = agent.run("What is the stock price of NVDA")
# run: RunResponse = agent.run("What is the stock price of NVDA and TSLA")
# print(run.content)

# Print the response on the terminal
agent.print_response("What is the stock price of NVDA")
agent.print_response("What is the stock price of NVDA and TSLA")
4 changes: 2 additions & 2 deletions cookbook/providers/openai/agent_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
)

# Get the response in a variable
# run_response: Iterator[RunResponse] = agent.run("What is the stock price of NVDA", stream=True)
# run_response: Iterator[RunResponse] = agent.run("What is the stock price of NVDA and TSLA", stream=True)
# for chunk in run_response:
# print(chunk.content)

# Print the response on the terminal
agent.print_response("What is the stock price of NVDA", stream=True)
agent.print_response("What is the stock price of NVDA and TSLA", stream=True)
13 changes: 0 additions & 13 deletions cookbook/providers/openai/exa_search.py

This file was deleted.

6 changes: 1 addition & 5 deletions phi/playground/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ def get_agent_sessions(body: GetAgentSessionsRequest):
for session in all_agent_sessions:
title = get_session_title(session)
agent_sessions.append(
GetAgentSessionsResponse(
session_id=session.session_id,
title=title,
created_at=session.created_at
)
GetAgentSessionsResponse(session_id=session.session_id, title=title, created_at=session.created_at)
)
return agent_sessions

Expand Down
2 changes: 1 addition & 1 deletion phi/utils/json_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def default(self, o):

def read_json_file(file_path: Optional[Path]) -> Optional[Union[Dict, List]]:
if file_path is not None and file_path.exists() and file_path.is_file():
logger.debug(f"Reading {file_path}")
# logger.debug(f"Reading {file_path}")
return json.loads(file_path.read_text())
return None

Expand Down

0 comments on commit 5cde751

Please sign in to comment.