-
Notifications
You must be signed in to change notification settings - Fork 79
dapr default better devex #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8cad9e7
4c36598
0945093
5b4877a
1fcca38
75982e6
8b1cd65
237d5e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import inspect | ||
import json | ||
import logging | ||
import time | ||
import sys | ||
import uuid | ||
from datetime import datetime, timezone | ||
|
@@ -516,6 +517,9 @@ def start_runtime(self): | |
self.wf_runtime.start() | ||
self.wf_runtime_is_running = True | ||
|
||
logger.info("Sleeping for 5 seconds to ensure runtime is started.") | ||
time.sleep(5) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. helps with actor runtime not found There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we rm since i have the open pr upstream and theyre planning to cut 1.16.1 next week There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure that will fix that, if there is no app port define won't you still need some time to have the runtime ready? |
||
|
||
# Sync database state with Dapr workflow status after runtime starts | ||
# This ensures our database reflects the actual state of resumed workflows | ||
self._sync_workflow_state_after_startup() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,25 @@ This quickstart provides a hands-on introduction to Dapr Agents through simple e | |
|
||
## Prerequisites | ||
|
||
- Python 3.10 (recommended) | ||
- pip package manager | ||
- Python 3.10+ (recommended) | ||
- [uv package manager](https://docs.astral.sh/uv/getting-started/installation/) | ||
sicoyle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- OpenAI API key (you can put in an .env file or directly in the `openai.yaml` file, but we recommend the .env file that is gitignored) | ||
|
||
## Environment Setup | ||
|
||
<details open> | ||
<summary><strong>Option 1: Using uv (Recommended)</strong></summary> | ||
|
||
<!-- We include setting up the venv as part of the first step to make sure the venv is created and activated before the examples are run.--> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the first step was moved up to setup the environment, we probably should add an option in mechanical markdown for SETUP/TEARDOWN There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added this issue in mm repo dapr/mechanical-markdown#38 that I'll try to implement |
||
|
||
<!-- STEP | ||
name: Run basic LLM example | ||
expected_stdout_lines: | ||
- "Got response:" | ||
timeout_seconds: 30 | ||
output_match_mode: substring | ||
--> | ||
|
||
```bash | ||
# Create and activate virtual environment | ||
uv venv .venv | ||
|
@@ -27,7 +37,7 @@ uv pip install -r requirements.txt | |
<details> | ||
<summary><strong>Option 2: Using pip</strong></summary> | ||
|
||
```bash | ||
```a shell [not setting type to avoid mechanical markdown execution] | ||
# Create a virtual environment | ||
python3.10 -m venv .venv | ||
|
||
|
@@ -39,17 +49,19 @@ source .venv/bin/activate | |
|
||
# Install dependencies | ||
pip install -r requirements.txt | ||
|
||
``` | ||
|
||
</details> | ||
|
||
|
||
## Configuration | ||
## OpenAI API Key | ||
|
||
> **Warning** | ||
> The examples will not work if you do not have a OpenAI API key exported in the environment. | ||
|
||
<details open> | ||
<summary><strong>Option 1: Using .env file</strong></summary> | ||
|
||
Create a `.env` file in the project root and add your OpenAI API key: | ||
|
||
```env | ||
|
@@ -59,23 +71,32 @@ OPENAI_API_KEY=your_api_key_here | |
Replace `your_api_key_here` with your actual OpenAI API key. | ||
|
||
Export the environment variables from the .env file to your shell: | ||
```bash | ||
export $(grep -v '^#' .env | xargs) # or if .env is in the root directory, you can just run `export $(grep -v '^#' ../../.env | xargs)` | ||
```a shell [not setting type to avoid mechanical markdown execution] | ||
export $(grep -v '^#' .env | xargs) | ||
|
||
# or if .env is in the root directory of the repository, | ||
# export $(grep -v '^#' ../../.env | xargs) | ||
``` | ||
|
||
</details> | ||
|
||
<details> | ||
<summary><strong>Option 2: Exporting the OpenAI API Key directly to the shell</strong></summary> | ||
|
||
```a shell [not setting type to avoid mechanical markdown execution] | ||
export OPENAI_API_KEY=your_api_key_here | ||
``` | ||
|
||
Replace `your_api_key_here` with your actual OpenAI API key. | ||
|
||
</details> | ||
|
||
## Examples | ||
|
||
### 1. Basic LLM Usage | ||
|
||
Run the basic LLM example to see how to interact with OpenAI's language models: | ||
|
||
<!-- STEP | ||
name: Run basic LLM example | ||
expected_stdout_lines: | ||
- "Got response:" | ||
timeout_seconds: 30 | ||
output_match_mode: substring | ||
--> | ||
```bash | ||
python 01_ask_llm.py | ||
``` | ||
|
@@ -167,6 +188,9 @@ A stateful agent that uses Dapr Workflows to ensure durability and persistence o | |
We are using the Dapr ChatClient to interact with the OpenAI API. In the components folder, we have a `openai.yaml` file that contains the configuration for the OpenAI API. | ||
You need to replace the `{YOUR_OPENAI_API_KEY}` with your actual OpenAI API key. | ||
|
||
We are using the Dapr ChatClient to interact with the OpenAI API. In the components folder, we have a `openai.yaml` file that contains the configuration for the OpenAI API. | ||
You need to replace the `{YOUR_OPENAI_API_KEY}` with your actual OpenAI API key. | ||
|
||
Make sure Dapr is initialized on your system: | ||
|
||
```bash | ||
|
@@ -180,14 +204,16 @@ name: Run basic LLM example | |
expected_stdout_lines: | ||
- "I want to find flights to Paris" | ||
- "TravelBuddy" | ||
timeout_seconds: 30 | ||
timeout_seconds: 60 | ||
output_match_mode: substring | ||
--> | ||
|
||
|
||
We are using the `resolve_env_templates.py` script to resolve the environment variables in the components folder and substitute them with the actual values in your .env file, like the OpenAI API key. | ||
We are using the `resolve_env_templates.py` script to resolve the environment variables in the components folder and substitute them with the actual values in your environment, like the OpenAI API key. | ||
|
||
```bash | ||
source .venv/bin/activate | ||
|
||
dapr run --app-id stateful-llm --dapr-http-port 3500 --resources-path $(../resolve_env_templates.py ./components) -- python 03_durable_agent.py | ||
``` | ||
|
||
|
@@ -321,6 +347,8 @@ expected_stdout_lines: | |
output_match_mode: substring | ||
--> | ||
```bash | ||
source .venv/bin/activate | ||
|
||
dapr run --app-id dapr-agent-wf --resources-path $(../resolve_env_templates.py ./components) -- python 04_chain_tasks.py | ||
``` | ||
<!-- END_STEP --> | ||
|
@@ -402,6 +430,8 @@ expected_stdout_lines: | |
output_match_mode: substring | ||
--> | ||
```bash | ||
source .venv/bin/activate | ||
sicoyle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
python 05_agent_with_vectorstore.py | ||
``` | ||
<!-- END_STEP --> | ||
|
@@ -541,6 +571,7 @@ if __name__ == "__main__": | |
|
||
## Key Concepts | ||
|
||
- **DaprChatClient**: The interface for interacting with Dapr's LLMs | ||
- **OpenAIChatClient**: The interface for interacting with OpenAI's LLMs | ||
- **Agent**: A class that combines an LLM with tools and instructions | ||
- **@tool decorator**: A way to create tools that agents can use | ||
|
Uh oh!
There was an error while loading. Please reload this page.