Skip to content

Commit a910c96

Browse files
committed
Add framework quickstart snippets
1 parent 7457a52 commit a910c96

File tree

5 files changed

+169
-0
lines changed

5 files changed

+169
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ from nutrient_dws import NutrientClient
6060
client = NutrientClient(api_key='your_api_key')
6161
```
6262

63+
## Framework Quickstarts
64+
65+
Framework-oriented snippets are available in `examples/src/`:
66+
67+
- `framework_openai_agents.py`
68+
- `framework_langchain.py`
69+
- `framework_crewai.py`
70+
71+
Syntax-check commands:
72+
73+
```bash
74+
python -m py_compile examples/src/framework_openai_agents.py
75+
python -m py_compile examples/src/framework_langchain.py
76+
python -m py_compile examples/src/framework_crewai.py
77+
```
78+
6379
## Direct Methods
6480

6581
The client provides numerous async methods for document processing:

examples/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ This example project demonstrates how to use the Nutrient DWS Python Client for
88
- `src/` - Contains Python source files
99
- `direct_method.py` - Examples using direct method calls
1010
- `workflow.py` - Examples using the workflow builder pattern
11+
- `framework_openai_agents.py` - OpenAI Agents SDK integration sketch
12+
- `framework_langchain.py` - LangChain/LangGraph integration sketch
13+
- `framework_crewai.py` - CrewAI integration sketch
1114
- `output/` - Directory where processed files will be saved
1215
- `.env.example` - Example environment variables file
1316

@@ -122,6 +125,30 @@ This will:
122125
3. Extract text with JSON output
123126
4. Execute a complex multi-step workflow
124127

128+
### Framework Examples
129+
130+
These examples are intentionally minimal and focus on framework wiring:
131+
132+
Install optional framework dependencies first:
133+
134+
```bash
135+
pip install openai-agents langchain langchain-openai langgraph crewai
136+
```
137+
138+
```bash
139+
python src/framework_openai_agents.py
140+
python src/framework_langchain.py
141+
python src/framework_crewai.py
142+
```
143+
144+
Syntax-check only:
145+
146+
```bash
147+
python -m py_compile src/framework_openai_agents.py
148+
python -m py_compile src/framework_langchain.py
149+
python -m py_compile src/framework_crewai.py
150+
```
151+
125152
## Output
126153

127154
All processed files will be saved to the `output/` directory. You can examine these files to see the results of the document processing operations.

examples/src/framework_crewai.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
3+
from crewai import Agent, Crew, Task
4+
from nutrient_dws import NutrientClient
5+
6+
7+
client = NutrientClient(api_key=os.getenv("NUTRIENT_API_KEY", "nutr_sk_placeholder"))
8+
9+
10+
document_planner = Agent(
11+
role="Document Workflow Planner",
12+
goal="Design a robust Nutrient DWS processing pipeline for incoming files.",
13+
backstory="You optimize OCR, extraction, and redaction workflows for accuracy."
14+
)
15+
16+
document_reviewer = Agent(
17+
role="Document QA Reviewer",
18+
goal="Review proposed workflow plans for failure modes and compliance risks.",
19+
backstory="You specialize in validating document automation quality."
20+
)
21+
22+
plan_task = Task(
23+
description=(
24+
"Design a pipeline for ./examples/assets/sample.pdf that extracts text, "
25+
"redacts emails, and exports a cleaned PDF."
26+
),
27+
expected_output="A numbered execution plan with tool calls.",
28+
agent=document_planner,
29+
)
30+
31+
review_task = Task(
32+
description=(
33+
"Review the proposed pipeline. Flag risks and add fallback handling steps."
34+
),
35+
expected_output="Risk review with concrete mitigations.",
36+
agent=document_reviewer,
37+
)
38+
39+
crew = Crew(
40+
agents=[document_planner, document_reviewer],
41+
tasks=[plan_task, review_task],
42+
verbose=True,
43+
)
44+
45+
46+
if __name__ == "__main__":
47+
# Keep a direct client reference so users see where DWS calls happen.
48+
print(f"Client configured: {bool(client)}")
49+
print(crew.kickoff())
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import asyncio
2+
import os
3+
4+
from langchain.tools import StructuredTool
5+
from langchain_openai import ChatOpenAI
6+
from langgraph.prebuilt import create_react_agent
7+
from nutrient_dws import NutrientClient
8+
9+
10+
client = NutrientClient(api_key=os.getenv("NUTRIENT_API_KEY", "nutr_sk_placeholder"))
11+
12+
13+
async def redact_emails(path: str) -> str:
14+
result = await client.create_redactions_ai(
15+
path,
16+
criteria="Redact all email addresses.",
17+
redaction_state="apply",
18+
)
19+
return str(result)
20+
21+
22+
tool = StructuredTool.from_function(
23+
func=redact_emails,
24+
coroutine=redact_emails,
25+
name="redact_emails",
26+
description="Redact email addresses from a document using Nutrient DWS.",
27+
)
28+
29+
30+
async def main() -> None:
31+
model = ChatOpenAI(
32+
model="gpt-4.1-mini",
33+
api_key=os.getenv("OPENAI_API_KEY", "sk-placeholder"),
34+
)
35+
agent = create_react_agent(model, [tool])
36+
state = await agent.ainvoke(
37+
{"messages": [("user", "Redact emails from ./assets/sample.pdf.")]}
38+
)
39+
print(state["messages"][-1].content)
40+
41+
42+
if __name__ == "__main__":
43+
asyncio.run(main())
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import asyncio
2+
import os
3+
4+
from agents import Agent, Runner, function_tool
5+
from nutrient_dws import NutrientClient
6+
7+
8+
client = NutrientClient(api_key=os.getenv("NUTRIENT_API_KEY", "nutr_sk_placeholder"))
9+
10+
11+
@function_tool
12+
async def extract_text(input_path: str) -> str:
13+
"""Extract text from a document using Nutrient DWS."""
14+
result = await client.extract_text(input_path)
15+
return str(result)
16+
17+
18+
assistant = Agent(
19+
name="nutrient-openai-agents-demo",
20+
instructions="Help users extract text and summarize document workflows.",
21+
tools=[extract_text],
22+
)
23+
24+
25+
async def main() -> None:
26+
run = await Runner.run(
27+
assistant,
28+
"Extract text from ./assets/sample.pdf and summarize it in three bullets.",
29+
)
30+
print(run.final_output)
31+
32+
33+
if __name__ == "__main__":
34+
asyncio.run(main())

0 commit comments

Comments
 (0)