Skip to content

Commit

Permalink
fix: added a fix for failed decoding error arguments (#665)
Browse files Browse the repository at this point in the history
<!-- ELLIPSIS_HIDDEN -->



> [!IMPORTANT]
> Fix decoding error by switching to `PyYAML` and updating cookbooks to
use formatted strings for YAML loading.
> 
>   - **YAML Handling**:
> - Replace `ruamel.yaml` with `PyYAML` in `yaml.py`, using
`CSafeLoader` and `CSafeDumper` for `load()` and `dump()` functions.
>     - Remove `ruamel-yaml` dependency from `pyproject.toml`.
>   - **Cookbooks**:
> - Update `06-Designing_Multi-Step_Tasks.py`,
`07-Integrating_External_Tools_and_APIs.py`,
`08-Managing_Persistent_Sessions.py`,
`09-User_Management_and_Personalization.py`,
`10-Document_Management_and_Search.py`, and
`11-Advanced_Chat_Interactions.py` to use formatted strings in
`yaml.safe_load()` calls.
>   - **Imports**:
> - Add `msgpack` import under
`workflow.unsafe.imports_passed_through()` in `__init__.py`.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=julep-ai%2Fjulep&utm_source=github&utm_medium=referral)<sup>
for b514c54. It will automatically
update as commits are pushed.</sup>

<!-- ELLIPSIS_HIDDEN -->

---------

Co-authored-by: Vedantsahai18 <[email protected]>
  • Loading branch information
Vedantsahai18 and Vedantsahai18 authored Oct 15, 2024
1 parent 4bab852 commit f4f9b87
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 113 deletions.
5 changes: 5 additions & 0 deletions agents-api/agents_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
#################################
## Do NOT put any imports here ##
#################################
# Failed decoding arguments fixture
from temporalio import workflow

with workflow.unsafe.imports_passed_through():
import msgpack as msgpack
16 changes: 5 additions & 11 deletions agents-api/agents_api/common/utils/yaml.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
from io import StringIO
from typing import Any

from ruamel.yaml import YAML
import yaml

yaml = YAML(typ="safe", pure=True) # pure is needed for yaml 1.2 support
yaml.version = (1, 2)


def dump(value: Any) -> str:
stream = StringIO()
yaml.dump(value, stream)

return stream.getvalue()
def load(string: str) -> Any:
return yaml.load(string, Loader=yaml.CSafeLoader)


def load(string: str) -> Any:
return yaml.load(string)
def dump(value: Any) -> str:
return yaml.dump(value, Dumper=yaml.CSafeDumper)
88 changes: 4 additions & 84 deletions agents-api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions agents-api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ google-re2 = "^1.1.20240702"
scalar-fastapi = "^1.0.3"
sse-starlette = "^2.1.3"
anyio = "^4.4.0"
python-box = {extras = ["toml"], version = "^7.2.0"}
python-box = {extras = [], version = "^7.2.0"}
prometheus-fastapi-instrumentator = "^7.0.0"
ruamel-yaml = "^0.18.6"
[tool.poetry.group.dev.dependencies]
ipython = "^8.26.0"
ruff = "^0.5.5"
Expand Down
2 changes: 1 addition & 1 deletion cookbooks/06-Designing_Multi-Step_Tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
)

# Defining a Task with various step types
task_def = yaml.safe_load("""
task_def = yaml.safe_load(f"""
name: Multi-Step Task Demonstration
input_schema:
Expand Down
2 changes: 1 addition & 1 deletion cookbooks/07-Integrating_External_Tools_and_APIs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)

# Defining a Task with various step types
task_def = yaml.safe_load("""
task_def = yaml.safe_load(f"""
name: Comprehensive Analysis Report
input_schema:
Expand Down
2 changes: 1 addition & 1 deletion cookbooks/08-Managing_Persistent_Sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
)

# Defining a task for managing user context
task_def = yaml.safe_load("""
task_def = yaml.safe_load(f"""
name: Manage User Context

input_schema:
Expand Down
4 changes: 2 additions & 2 deletions cookbooks/09-User_Management_and_Personalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
)

# Defining a task for user registration and profile creation
registration_task_def = yaml.safe_load("""
registration_task_def = yaml.safe_load(f"""
name: User Registration and Profile Creation
input_schema:
Expand Down Expand Up @@ -75,7 +75,7 @@
)

# Defining a task for personalized content recommendation
recommendation_task_def = yaml.safe_load("""
recommendation_task_def = yaml.safe_load(f"""
name: Personalized Content Recommendation
input_schema:
Expand Down
21 changes: 11 additions & 10 deletions cookbooks/10-Document_Management_and_Search.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
)

# Defining a task for document upload and indexing
upload_task_def = yaml.safe_load("""
upload_task_def = yaml.safe_load(f"""
name: Document Upload and Indexing
input_schema:
Expand Down Expand Up @@ -62,13 +62,14 @@
main:
- over: inputs[0].documents
map:
tool: document_upload
tool: document_create
arguments:
agent_id: "'{agent.id}'"
title: _.title
content: _.content
metadata: _.metadata
data:
title: _.title
content: _.content
metadata: _.metadata
- prompt:
- role: system
content: >-
Expand All @@ -84,7 +85,7 @@
)

# Defining a task for document search
search_task_def = yaml.safe_load("""
search_task_def = yaml.safe_load(f"""
name: Document Search
input_schema:
Expand Down Expand Up @@ -131,17 +132,17 @@
# Sample documents
sample_documents = [
{
"Title": "The Impact of Technology on Society",
"title": "The Impact of Technology on Society",
"content": "Artificial Intelligence (AI) is revolutionizing various industries, including healthcare, finance, and transportation.",
"metadata": {"category": "technology", "author": "John Doe"}
},
{
"Title": "Climate Change and Global Warming",
"title": "Climate Change and Global Warming",
"content": "Climate change is a pressing global issue that requires immediate action from governments, businesses, and individuals.",
"metadata": {"category": "environment", "author": "Jane Smith"}
},
{
"Title": "Remote Work and Digital Transformation",
"title": "Remote Work and Digital Transformation",
"content": "The COVID-19 pandemic has accelerated the adoption of remote work and digital technologies across many organizations.",
"metadata": {"category": "business", "author": "Alice Johnson"}
}
Expand Down
2 changes: 1 addition & 1 deletion cookbooks/11-Advanced_Chat_Interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
)

# Defining a task for handling complex conversations
chat_task_def = yaml.safe_load("""
chat_task_def = yaml.safe_load(f"""
name: Advanced Chat Interaction
input_schema:
Expand Down

0 comments on commit f4f9b87

Please sign in to comment.