Skip to content

Commit 633f3d7

Browse files
authored
Merge branch 'main' into PeterObertTCE-patch-1
2 parents a09d215 + cc0c896 commit 633f3d7

File tree

94 files changed

+16744
-590
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+16744
-590
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# OCI Weather Assistant API
2+
3+
A FastAPI-based service that integrates with Oracle Cloud Infrastructure's Generative AI Agent and uses OpenWeather API to provide real-time weather forecasts. The agent invokes the `get_weather` tool automatically when weather-related questions are asked.
4+
5+
## Features
6+
7+
- FastAPI backend with async support
8+
- OCI Generative AI Agent integration
9+
- Weather tool using OpenWeather API
10+
- `.env` configuration for secrets
11+
12+
## Setup
13+
14+
1. Clone the repo & install dependencies:
15+
16+
```bash
17+
git clone https://github.com/your-username/oci-weather-assistant.git
18+
cd oci-weather-assistant
19+
pip install -r requirements.txt
20+
21+
## Create a .env file in the root directory:
22+
23+
OCI_AI_AGENT_ENDPOINT_ID=ocid1.generativeaiendpoint.oc1..example
24+
OCI_CONFIG_PROFILE=DEFAULT
25+
OCI_REGION=us-chicago-1
26+
OPENWEATHER_API_KEY=your_openweather_api_key
27+
28+
## Run the app
29+
30+
uvicorn main:app --reload --port 8000
31+
32+
## UI
33+
34+
To test the API via a simple UI, use the frontend from this repository:
35+
🔗 https://github.com/ralungei/oci-genai-agent-blackbelt
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
OCI_AI_AGENT_ENDPOINT_ID=ocid1.generativeaiendpoint.oc1..example
2+
OCI_CONFIG_PROFILE=DEFAULT
3+
OCI_REGION=us-chicago-1
4+
OPENWEATHER_API_KEY=your_openweather_api_key
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
from __future__ import annotations
2+
3+
import os
4+
from typing import Dict, Optional
5+
6+
import requests
7+
from dotenv import load_dotenv
8+
from oci.addons.adk import Agent, AgentClient, tool
9+
from fastapi import FastAPI
10+
from fastapi.middleware.cors import CORSMiddleware
11+
from pydantic import BaseModel
12+
13+
# ---------------------------------------------------------------------------
14+
# Environment setup
15+
# ---------------------------------------------------------------------------
16+
17+
load_dotenv(dotenv_path=os.path.join(os.path.dirname(__file__), ".env"))
18+
19+
OCI_AI_AGENT_ENDPOINT_ID = os.getenv("OCI_AI_AGENT_ENDPOINT_ID")
20+
OCI_CONFIG_PROFILE = os.getenv("OCI_CONFIG_PROFILE", "DEFAULT")
21+
OCI_REGION = os.getenv("OCI_REGION", "us-chicago-1")
22+
OPENWEATHER_API_KEY = os.getenv("OPENWEATHER_API_KEY", "")
23+
24+
25+
# ---------------------------------------------------------------------------
26+
# Tool definition
27+
# ---------------------------------------------------------------------------
28+
29+
@tool
30+
def get_weather(location: str, units: str = "metric") -> Dict[str, str]:
31+
"""Return the current weather for *location* using OpenWeatherMap.
32+
33+
Args:
34+
location: City name (e.g. "Seattle" or "Seattle,US").
35+
units: Measurement system – "metric" (°C), "imperial" (°F), or
36+
"standard" (Kelvin). Defaults to "metric".
37+
38+
Returns:
39+
A dict ready for the agent response, containing temperature, unit,
40+
humidity, wind speed and a short description.
41+
"""
42+
43+
base_url = "https://api.openweathermap.org/data/2.5/weather"
44+
params = {
45+
"q": location,
46+
"appid": OPENWEATHER_API_KEY,
47+
"units": units,
48+
}
49+
50+
try:
51+
resp = requests.get(base_url, params=params, timeout=10)
52+
resp.raise_for_status()
53+
except requests.RequestException as exc:
54+
raise RuntimeError(f"Weather service unavailable: {exc}") from exc
55+
56+
data = resp.json()
57+
58+
main = data["main"]
59+
weather = data["weather"][0]
60+
wind = data.get("wind", {})
61+
62+
unit_symbol = {"metric": "°C", "imperial": "°F", "standard": "K"}.get(units, "°?")
63+
64+
return {
65+
"location": location,
66+
"temperature": main["temp"],
67+
"unit": unit_symbol,
68+
"description": weather["description"],
69+
"humidity_percent": main.get("humidity"),
70+
"wind_speed_mps": wind.get("speed"),
71+
}
72+
73+
74+
# ---------------------------------------------------------------------------
75+
# FastAPI setup
76+
# ---------------------------------------------------------------------------
77+
app = FastAPI()
78+
app.add_middleware(
79+
CORSMiddleware,
80+
allow_origins=["*"],
81+
allow_credentials=True,
82+
allow_methods=["*"],
83+
allow_headers=["*"],
84+
)
85+
86+
# ---------------------------------------------------------------------------
87+
# Agent setup (reuse from main)
88+
# ---------------------------------------------------------------------------
89+
if not OCI_AI_AGENT_ENDPOINT_ID:
90+
raise SystemExit("OCI_AI_AGENT_ENDPOINT_ID is not set. Check your .env file.")
91+
92+
client = AgentClient(
93+
auth_type="api_key",
94+
profile=OCI_CONFIG_PROFILE,
95+
region=OCI_REGION,
96+
)
97+
98+
agent = Agent(
99+
client=client,
100+
agent_endpoint_id=OCI_AI_AGENT_ENDPOINT_ID,
101+
instructions=(
102+
"You are a helpful assistant that answers weather questions. "
103+
"Always invoke the get_weather tool when the user asks about the forecast."
104+
),
105+
tools=[get_weather],
106+
)
107+
108+
agent.setup()
109+
110+
# ---------------------------------------------------------------------------
111+
# API request/response models
112+
# ---------------------------------------------------------------------------
113+
class ChatRequest(BaseModel):
114+
question: str
115+
execute_functions: Optional[bool] = True
116+
session_id: Optional[str] = None
117+
118+
# ---------------------------------------------------------------------------
119+
# /chat endpoint
120+
# ---------------------------------------------------------------------------
121+
@app.post("/chat")
122+
async def chat(request: ChatRequest):
123+
try:
124+
response = await agent.run_async(request.question)
125+
return {
126+
"answer": response.final_output,
127+
"session_id": request.session_id or "session123"
128+
}
129+
except Exception as e:
130+
return {"answer": str(e), "session_id": request.session_id or "session123"}
131+
132+
133+
if __name__ == "__main__":
134+
main()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fastapi==0.111.0
2+
uvicorn==0.29.0
3+
requests==2.31.0
4+
python-dotenv==1.0.1
5+
oci==2.114.1
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Copyright (c) 2025 Oracle and/or its affiliates.
2+
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any
6+
person obtaining a copy of this software, associated documentation and/or data
7+
(collectively the "Software"), free of charge and under any and all copyright
8+
rights in the Software, and any and all patent rights owned or freely
9+
licensable by each licensor hereunder covering either (i) the unmodified
10+
Software as contributed to or provided by such licensor, or (ii) the Larger
11+
Works (as defined below), to deal in both
12+
13+
(a) the Software, and
14+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
one is included with the Software (each a "Larger Work" to which the Software
16+
is contributed by such licensors),
17+
18+
without restriction, including without limitation the rights to copy, create
19+
derivative works of, display, perform, and distribute the Software and make,
20+
use, sell, offer for sale, import, export, have made, and have sold the
21+
Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
either these or other terms.
23+
24+
This license is subject to the following condition:
25+
The above copyright notice and either this complete permission notice or at
26+
a minimum a reference to the UPL must be included in all copies or
27+
substantial portions of the Software.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
SOFTWARE.
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# Generic Document Evaluation Tool
2+
3+
🔍 **Evaluate PDFs against custom business criteria**
4+
5+
A simple, adaptable solution for analyzing and categorizing transactional documents using predefined evaluation criteria. Perfect for analysts, auditors, or developers seeking to automate document review in enterprise, finance, education, or public sector scenarios and more.
6+
7+
Reviewed: 22.07.2025
8+
9+
## Overview
10+
11+
**Document Evaluation Tool** lets you upload one or more documents (PDF), define your evaluation criteria in a CSV format or manual entry, and receive a professional markdown report categorizing each document as appropriate, with a rationale for each decision. With the option to add additional input to the prompt, making sure it's easy to customize for all sorts of scenarios where documents and criteria is involved.
12+
13+
**What's Included:**
14+
15+
**Frontend**: Modern React interface
16+
- **Backend**: Oracle GenAI Service integration
17+
18+
---
19+
20+
21+
# When to use this asset?
22+
23+
Analysts, compliance teams, auditors, or operational staff would use this asset whenever they need to systematically evaluate, validate, or categorize documents—such as visa applications, insurance claims, or student financial aid requests—based on well-defined criteria.
24+
25+
Developers and solution architects may also use this asset to rapidly prototype or demo document analysis workflows, including LLM-driven or human-in-the-loop review scenarios.
26+
27+
# How to use this asset?
28+
29+
Collect the Documents: Gather one or more PDFs containing the applications or claims to be evaluated.
30+
31+
Define Evaluation Criteria: Prepare a CSV file listing the evaluation criteria and descriptions tailored for the specific use case (e.g., insurance claim completeness, income eligibility for student aid). Optionally, you can give the criteria in a free-format in the front-end including additional requirements that may not be criteria.
32+
33+
Run the Tool: Upload the documents and relevant criterion.
34+
35+
Automated Evaluation: The tool analyzes the content of each document, evaluating and categorizing them according to your criteria.
36+
37+
Review the Results: Receive a professional, human-readable markdown report showing the outcome for each document (Ready to Admit, Conditional, Rejected), along with explanations and a summary table.
38+
39+
Take Action: Use the evaluation output to make operational decisions (e.g., approve/reject applications, flag items for manual review, generate audit trails).
40+
41+
42+
---
43+
44+
## Architecture
45+
46+
The solution consists of two complementary components:
47+
48+
### Frontend (React/Next.js)
49+
50+
- Multi-tenant chat interface
51+
- Multiple input option allows flexibility for use-case
52+
53+
### Backend (Node.js/Express)
54+
55+
- Oracle GenAI Services
56+
- Embedding documents in local qdrant vector store
57+
58+
59+
---
60+
61+
## Quick Start
62+
63+
### Full Stack
64+
65+
Complete setup with Oracle GenAI Service:
66+
#TO-DO
67+
```bash
68+
# Start backend
69+
cd backend/
70+
# Install dependencies
71+
pip install -r requirements.txt
72+
73+
# Set up environment variables
74+
cp .env.example .env.local
75+
# Edit .env.local with your Configure Oracle Credentials
76+
77+
# Start main.py
78+
python main.py
79+
80+
# Start frontend (in new terminal)
81+
cd files/frontend/
82+
npm install
83+
cp .env.example .env.local
84+
# Configure Oracle Digital Assistant + Speech Service URL
85+
npm run dev
86+
```
87+
88+
---
89+
## Example Use Cases
90+
91+
- Visa application processing
92+
- Insurance claim validation
93+
- Student financial aid and scholarship assessment
94+
- RFP evaluation
95+
- Resume evaluation
96+
- ESG Document review
97+
- Any transactional document requiring multi-criteria analysis
98+
99+
100+
101+
---
102+
## Example Criteria
103+
104+
105+
106+
### Insurance Claim (CSV)
107+
108+
| Criteria | Description |
109+
|------------------------|------------------------------------------------------------------------------------------|
110+
| Completeness | All required fields are filled out and information is provided for each section. |
111+
| Incident Clarity | Incident details are clearly described, dates and type of incident are consistent. |
112+
| Cost Breakdown Accuracy| All claimed expenses are itemized, reasonable, and total matches the sum of items. |
113+
| Supporting Evidence | Incident verification is provided (e.g., police report, doctor’s note). |
114+
| Policy Coverage Check | Total claimed amount is within the policy coverage limit. |
115+
| Contact Validity | Contact information for the claimant is complete and plausible. |
116+
117+
### Visa Application (CSV)
118+
119+
| Criteria | Description |
120+
|-----------------------------|-----------------------------------------------------------------------------|
121+
| Completeness | All required fields are filled and accurate. |
122+
| Financial Sufficiency | Applicant has sufficient bank balance (e.g., minimum €3,000). |
123+
| Passport Validity | Passport expiration is at least 6 months after intended departure. |
124+
| Employment/Sponsorship Info | Clear and valid employment or sponsorship details provided. |
125+
126+
### Student Financial Aid (CSV)
127+
128+
| Criteria | Description |
129+
|--------------------|--------------------------------------------------------------------|
130+
| Completeness | All fields filled and supporting docs present. |
131+
| Income Eligibility | Household income and size match program limits. |
132+
| Academic Merit | If required: grades, honors, awards, or other evidence provided. |
133+
| Loan Co-signer | If loan: co-signer details are complete and income is sufficient. |
134+
135+
---
136+
137+
## Example Outcome Categories
138+
139+
- **Ready to Admit**: Document is fully verified, consistent, and meet all criteria
140+
- **Conditional**: Document is mostly satisfactory but missing minor details or require further clarification
141+
- **Rejected**: Documents are clearly incomplete, falsified, or contain highly inconsistent information
142+
143+
---
144+
145+
## Quick Start
146+
147+
1. Upload your document(s) as PDF.
148+
2. Provide a CSV listing your evaluation criteria (see templates above).
149+
3. Add any additional requirements you have such as asking for a scoring over hundred for each criteria.
150+
151+
---
152+
153+
154+
# Components
155+
156+
- **Frontend**: [`files/frontend/`](files/frontend/) - Complete React interface
157+
- **Backend**: [`files/backend/`](files/backend/) - Oracle Generative AI Service integration
158+
159+
## Technology Stack
160+
161+
**Frontend**: Next.js 15, React 19, Material-UI, Framer Motion, Oracle WebSDK
162+
**Backend**: Node.js, Express, WebSocket, Oracle GenAI, FFmpeg #TO-DO update this
163+
164+
# Browser Requirements
165+
166+
- Modern browser with WebSocket support
167+
- LocalStorage for project persistence
168+
169+
---
170+
171+
Copyright (c) 2025 Oracle and/or its affiliates.
172+
173+
Licensed under the Universal Permissive License (UPL), Version 1.0.
174+
175+
See [LICENSE](https://github.com/oracle-devrel/technology-engineering/blob/main/LICENSE) for more details.

0 commit comments

Comments
 (0)