Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
matrix:
php-versions: [ '8.2' ]
databases: [ 'sqlite' ]
server-versions: [ 'master', 'stable32', 'stable31' ]
server-versions: [ 'master', 'stable33', 'stable32', 'stable31' ]

name: Integration test on ☁️${{ matrix.server-versions }} 🐘${{ matrix.php-versions }}

Expand Down Expand Up @@ -198,7 +198,7 @@ jobs:
CREDS: "alice:alice"
run: |
sleep 300
TASK=$(curl -X POST -u "$CREDS" -H "oCS-APIRequest: true" -H "Content-type: application/json" http://localhost:8080/ocs/v2.php/taskprocessing/schedule?format=json --data-raw '{"input": {"input": "Search duckduckgo for Nextcloud", "confirmation":1, "conversation_token": ""},"type":"core:contextagent:interaction", "appId": "test", "customId": ""}')
TASK=$(curl -X POST -u "$CREDS" -H "oCS-APIRequest: true" -H "Content-type: application/json" http://localhost:8080/ocs/v2.php/taskprocessing/schedule?format=json --data-raw '{"input": {"input": "Search youtube for videos about Nextcloud", "confirmation":1, "conversation_token": ""},"type":"core:contextagent:interaction", "appId": "test", "customId": ""}')
echo $TASK
TASK_ID=$(echo $TASK | jq '.ocs.data.task.id')
NEXT_WAIT_TIME=0
Expand All @@ -215,7 +215,7 @@ jobs:
[ "$TASK_STATUS" == '"STATUS_SUCCESSFUL"' ]
echo $TASK | jq '.ocs.data.task.output.output'
echo $TASK | jq '.ocs.data.task.output.sources'
echo $TASK | jq '.ocs.data.task.output.sources' | grep -q 'duckduckgo_results_json'
echo $TASK | jq '.ocs.data.task.output.sources' | grep -q 'youtube_search'
echo $TASK | jq '.ocs.data.task.output.output' | grep -q 'Nextcloud'

- name: Show nextcloud logs
Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Positive:
<screenshot>https://github.com/nextcloud/context_agent/blob/main/img/screenshot.png?raw=true</screenshot>
<repository type="git">https://github.com/nextcloud/context_agent</repository>
<dependencies>
<nextcloud min-version="31.0.8" max-version="33"/>
<nextcloud min-version="31.0.8" max-version="34"/>
</dependencies>
<external-app>
<docker-install>
Expand Down
8 changes: 3 additions & 5 deletions ex_app/lib/all_tools/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from time import sleep
from typing import Optional

import httpx
from niquests import ConnectionError, Timeout
import pytz
from ics import Calendar, Event, Attendee, Organizer, Todo
from langchain_core.tools import tool
Expand Down Expand Up @@ -91,10 +91,8 @@ def schedule_event(calendar_name: str, title: str, description: str, start_date:
json = nc.ocs('GET', '/ocs/v2.php/cloud/user')
break
except (
httpx.RemoteProtocolError,
httpx.ReadError,
httpx.LocalProtocolError,
httpx.PoolTimeout,
ConnectionError,
Timeout
) as e:
log(nc, LogLvl.DEBUG, "Ignored error during task polling")
i += 1
Expand Down
1 change: 0 additions & 1 deletion ex_app/lib/all_tools/deck.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from time import sleep
from typing import Optional

import httpx
import pytz
from langchain_core.tools import tool
from nc_py_api import Nextcloud
Expand Down
4 changes: 2 additions & 2 deletions ex_app/lib/all_tools/here.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import datetime
import urllib.parse

import httpx
import niquests
from langchain_core.tools import tool
from nc_py_api import Nextcloud

Expand All @@ -30,7 +30,7 @@ def get_public_transport_route_for_coordinates(origin_lat: str, origin_lon: str,
if departure_time is None:
departure_time = urllib.parse.quote_plus(datetime.datetime.now(datetime.UTC).isoformat())
api_key = nc.appconfig_ex.get_value('here_api')
res = httpx.get('https://transit.hereapi.com/v8/routes?transportMode=car&origin='
res = niquests.get('https://transit.hereapi.com/v8/routes?transportMode=car&origin='
+ origin_lat + ',' + origin_lon + '&destination=' + destination_lat + ',' + destination_lon
+ '&alternatives=' + str(routes-1) + '&departureTime=' + departure_time + '&apikey=' + api_key)
json = res.json()
Expand Down
31 changes: 21 additions & 10 deletions ex_app/lib/all_tools/lib/task_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
import typing

import httpx
from niquests import ConnectionError, Timeout
from nc_py_api import NextcloudException
from nc_py_api.ex_app import LogLvl
from pydantic import BaseModel, ValidationError
Expand All @@ -20,11 +20,24 @@ class Response(BaseModel):
task: Task

def run_task(nc, type, task_input):
response = nc.ocs(
"POST",
"/ocs/v1.php/taskprocessing/schedule",
json={"type": type, "appId": "context_agent", "input": task_input},
)
i = 0
while i < 20:
try:
response = nc.ocs(
"POST",
"/ocs/v1.php/taskprocessing/schedule",
json={"type": type, "appId": "context_agent", "input": task_input},
)
break
except (
ConnectionError,
Timeout

) as e:
log(nc, LogLvl.DEBUG, "Ignored error during task scheduling")
i += 1
sleep(1)
continue

try:
task = Response.model_validate(response).task
Expand All @@ -38,10 +51,8 @@ def run_task(nc, type, task_input):
try:
response = nc.ocs("GET", f"/ocs/v1.php/taskprocessing/task/{task.id}")
except (
httpx.RemoteProtocolError,
httpx.ReadError,
httpx.LocalProtocolError,
httpx.PoolTimeout,
ConnectionError,
Timeout
) as e:
log(nc, LogLvl.DEBUG, "Ignored error during task polling")
time.sleep(5)
Expand Down
8 changes: 3 additions & 5 deletions ex_app/lib/all_tools/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
from time import sleep

import httpx
from niquests import ConnectionError, Timeout
from langchain_core.tools import tool
from nc_py_api import Nextcloud
from nc_py_api.ex_app import LogLvl
Expand Down Expand Up @@ -35,10 +35,8 @@ def send_email(subject: str, body: str, account_id: int, from_email: str, to_ema
'to': [{'label': '', 'email': email} for email in to_emails],
})
except (
httpx.RemoteProtocolError,
httpx.ReadError,
httpx.LocalProtocolError,
httpx.PoolTimeout,
ConnectionError,
Timeout
) as e:
log(nc, LogLvl.DEBUG, "Ignored error during task polling")
i += 1
Expand Down
8 changes: 4 additions & 4 deletions ex_app/lib/all_tools/openstreetmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import urllib.parse
from time import sleep

import httpx
import niquests
from langchain_core.tools import tool
from nc_py_api import Nextcloud

Expand All @@ -22,7 +22,7 @@ def get_coordinates_for_address(address: str) -> (str, str):
:param address: the address to calculate the coordinates for
:return: a tuple of latitude and longitude
"""
res = httpx.get('https://nominatim.openstreetmap.org/search', params={'q': address, 'format': 'json', 'addressdetails': '1', 'extratags': '1', 'namedetails': '1', 'limit': '1'})
res = niquests.get('https://nominatim.openstreetmap.org/search', params={'q': address, 'format': 'json', 'addressdetails': '1', 'extratags': '1', 'namedetails': '1', 'limit': '1'})
json = res.json()
if 'error' in json:
raise Exception(json['error'])
Expand Down Expand Up @@ -56,7 +56,7 @@ def get_osm_route(profile: str, origin_lat: str, origin_lon: str, destination_la
profile_num = "2"
url = f'https://routing.openstreetmap.de/{profile}/route/v1/driving/{origin_lon},{origin_lat};{destination_lon},{destination_lat}?overview=false&steps=true'
map_url = f' https://routing.openstreetmap.de/?loc={origin_lat}%2C{origin_lon}&loc={destination_lat}%2C{destination_lon}&srv={profile_num}'
res = httpx.get(url)
res = niquests.get(url)
json = res.json()
return {'route_json_description': json, 'map_url': map_url}

Expand All @@ -70,7 +70,7 @@ def get_osm_link(location: str):
:return: URL
"""

res = httpx.get('https://nominatim.openstreetmap.org/search', params={'q': location, 'format': 'json','limit': '1'})
res = niquests.get('https://nominatim.openstreetmap.org/search', params={'q': location, 'format': 'json','limit': '1'})
json = res.json()
if 'error' in json:
raise Exception(json['error'])
Expand Down
4 changes: 2 additions & 2 deletions ex_app/lib/all_tools/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import typing
import urllib.parse

import httpx
import niquests
from langchain_core.tools import tool
from nc_py_api import Nextcloud

Expand All @@ -20,7 +20,7 @@ def get_current_weather_for_coordinates(lat: str, lon: str) -> dict[str, typing.
:param lon: Longitude
:return:
"""
res = httpx.get('https://api.met.no/weatherapi/locationforecast/2.0/compact', params={
res = niquests.get('https://api.met.no/weatherapi/locationforecast/2.0/compact', params={
'lat': lat,
'lon': lon,
},
Expand Down
32 changes: 22 additions & 10 deletions ex_app/lib/nc_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import typing
from typing import Optional, Any, Sequence, Union, Callable

import httpx
from niquests import ConnectionError, Timeout
from langchain_core.callbacks import CallbackManagerForLLMRun
from langchain_core.language_models import LanguageModelInput
from langchain_core.messages import BaseMessage, AIMessage
Expand Down Expand Up @@ -90,11 +90,24 @@ def _generate(

log(nc, LogLvl.DEBUG, task_input)

response = nc.ocs(
"POST",
"/ocs/v1.php/taskprocessing/schedule",
json={"type": "core:text2text:chatwithtools", "appId": "context_agent", "input": task_input},
)
i = 0
while i < 20:
try:
response = nc.ocs(
"POST",
"/ocs/v1.php/taskprocessing/schedule",
json={"type": "core:text2text:chatwithtools", "appId": "context_agent", "input": task_input},
)
break
except (
ConnectionError,
Timeout

) as e:
log(nc, LogLvl.DEBUG, "Ignored error during task scheduling")
i += 1
sleep(1)
continue

try:
task = Response.model_validate(response).task
Expand All @@ -109,10 +122,9 @@ def _generate(
try:
response = nc.ocs("GET", f"/ocs/v1.php/taskprocessing/task/{task.id}")
except (
httpx.RemoteProtocolError,
httpx.ReadError,
httpx.LocalProtocolError,
httpx.PoolTimeout,
ConnectionError,
Timeout

) as e:
log(nc, LogLvl.DEBUG, "Ignored error during task polling")
time.sleep(5)
Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

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

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ duckduckgo-search = "^8.0.1"
uvicorn = "^0.34.2"
langchain-mcp-adapters = "^0.1.9"
fastmcp = "^2.11.2"
niquests = "^3.17.0"

[build-system]
requires = ["poetry-core"]
Expand Down
Loading