**Add new test script, agent modifications, and SearXNG integration updates**

This commit is contained in:
geoffsee
2025-05-27 19:10:33 -04:00
parent bb99e652f9
commit 29f70146d2
24 changed files with 2538 additions and 38 deletions

10
.env
View File

@@ -1,6 +1,6 @@
OPENAI_API_KEY="" OPENAI_API_KEY="your-key-goes-here"
OPENAI_API_BASE="https://api.openai.com/v1" OPENAI_API_BASE="https://api.openai.com/v1"
GENAISCRIPT_MODEL_LARGE="" GENAISCRIPT_MODEL_LARGE="gpt-4o-mini-2024-07-18"
GENAISCRIPT_MODEL_SMALL="" GENAISCRIPT_MODEL_SMALL="gpt-4o-mini-2024-07-18"
SEARXNG_API_BASE_URL="" SEARXNG_API_BASE_URL="http://localhost:8080"
SEARXNG_PASSWORD= SEARXNG_PASSWORD="777b930e"

View File

@@ -1,4 +0,0 @@
OPENAI_API_KEY=""
OPENAI_API_BASE="https://api.cerebras.ai/v1"
GENAISCRIPT_MODEL_LARGE=""
GENAISCRIPT_MODEL_SMALL=""

View File

@@ -1,4 +0,0 @@
OPENAI_API_KEY=""
OPENAI_API_BASE="https://api.fireworks.ai/inference/v1"
GENAISCRIPT_MODEL_LARGE=""
GENAISCRIPT_MODEL_SMALL=""

View File

@@ -1,4 +0,0 @@
OPENAI_API_KEY=""
OPENAI_API_BASE="https://generativelanguage.googleapis.com/v1beta/openai"
GENAISCRIPT_MODEL_LARGE=""
GENAISCRIPT_MODEL_SMALL=""

View File

@@ -1,4 +0,0 @@
OPENAI_API_KEY=""
OPENAI_API_BASE="https://api.groq.com/openai/v1"
GENAISCRIPT_MODEL_LARGE=""
GENAISCRIPT_MODEL_SMALL=""

View File

@@ -1,4 +0,0 @@
OPENAI_API_KEY=""
OPENAI_API_BASE="https://api.openai.com/v1"
GENAISCRIPT_MODEL_LARGE="gpt-4o"
GENAISCRIPT_MODEL_SMALL="gpt-4o-mini"

3
.gitignore vendored
View File

@@ -4,7 +4,8 @@
chrome chrome
stream_store stream_store
data/ data/
web-agent-rs/ /open-web-agent-rs/
/dist/
./.env* ./.env*
/.genaiscript/ /.genaiscript/
/packages/genaiscript/node_modules/ /packages/genaiscript/node_modules/

4
Cargo.lock generated
View File

@@ -514,9 +514,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.166" version = "0.2.172"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2ccc108bbc0b1331bd061864e7cd823c0cab660bbe6970e66e2c0614decde36" checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
[[package]] [[package]]
name = "lock_api" name = "lock_api"

View File

@@ -2,6 +2,42 @@
Remote genaiscript host for integration into conversational AI applications. Remote genaiscript host for integration into conversational AI applications.
> This application is actively being ported, expect breaking changes. > This application is actively being ported, expect breaking changes.
## Quickstart
```bash
git clone <repo-url>
bun i
bun run build
bun dev
```
```javascript
#!/usr/bin/env node
(async () => {
const url = "http://localhost:3006"
const createAgentRequestParams = {
};
const createAgentRequest = fetch(url, {
method: "POST",
body: JSON.stringify(createAgentRequestParams)
});
const {streamId} = await createAgentRequest.json();
const streamUrl = new URL(url);
streamUrl.pathname = streamId;
const eventsource = new EventSource(streamUrl)
eventsource.onmessage = (event) => {
console.log(JSON.stringify(event))
}
})
```
### Disclaimer ### Disclaimer
This has not undergone a formal security assessment. You should do your own evaluation before using this. This has not undergone a formal security assessment. You should do your own evaluation before using this.

BIN
bun.lockb

Binary file not shown.

View File

@@ -1,4 +1,10 @@
services: services:
searxng:
build:
context: ./searxng # Path to the directory containing the searxng.Dockerfile
dockerfile: searxng.Dockerfile
ports:
- "8080:8080" # Expose SearxNG on port 8080
agent-server: agent-server:
build: build:
context: . context: .

View File

@@ -1,17 +1,21 @@
{ {
"name": "open-web-agent-rs", "name": "open-web-agent-rs",
"type": "module", "type": "module",
"workspaces": ["packages/*"], "workspaces": [
"packages/*"
],
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "bunx kill-port 3006 && bun run build && cargo watch -x 'run src/main.rs'", "dev": "bunx kill-port 3006 && bun run build && cargo watch -x 'run src/main.rs'",
"start": "docker compose up --build", "start": "docker compose up --build",
"ai:search": "genaiscript run packages/genaiscript/genaisrc/web-search.genai.mts --vars USER_INPUT='who won the 2024 election?'", "ai:search": "genaiscript run packages/genaiscript/genaisrc/web-search.genai.mts --vars USER_INPUT='who won the 2024 election?'",
"shim:ai:search": "pnpm build && ./dist/shim.js --file=genaisrc/search.genai.mts USER_INPUT=\"Who won the 2024 presidential election?\"\n", "shim:ai:search": "pnpm build && ./packages/genaiscript-rust-shim/dist/genaiscript-rust-shim.js --file=packages/genaiscript/genaisrc/web-search.genai.mts USER_INPUT=\"Who won the 2024 presidential election?\"\n",
"ai:news": "genaiscript run packages/genaiscript/genaisrc/news-search.genai.mts --vars USER_INPUT='What are the latest updates and developments in the Ukraine war?'", "ai:news": "genaiscript run packages/genaiscript/genaisrc/news-search.genai.mts --vars USER_INPUT='What are the latest updates and developments in the Ukraine war?'",
"ai:url:read": "genaiscript run packages/genaiscript/genaisrc/web-scrape.genai.mts --vars USER_INPUT='{\"url\":\"https://geoff.seemueller.io/about\",\"query\":\"Describe the details of the page.\", \"action\": \"read\"}'", "ai:url:read": "genaiscript run packages/genaiscript/genaisrc/web-scrape.genai.mts --vars USER_INPUT='{\"url\":\"https://geoff.seemueller.io/about\",\"query\":\"Describe the details of the page.\", \"action\": \"read\"}'",
"ai:url:scrape": "npx genaiscript run packages/genaiscript/genaisrc/web-scrape.genai.mts --vars USER_INPUT='{\"url\":\"https://www.time4learning.com/homeschool-curriculum/high-school/eleventh-grade/math.html\",\"query\":\"What is on this page?\", \"action\": \"scrape\"}'", "ai:url:scrape": "npx genaiscript run packages/genaiscript/genaisrc/web-scrape.genai.mts --vars USER_INPUT='{\"url\":\"https://www.time4learning.com/homeschool-curriculum/high-school/eleventh-grade/math.html\",\"query\":\"What is on this page?\", \"action\": \"scrape\"}'",
"prod:logs": "fly logs", "prod:logs": "fly logs",
"build": "(cd packages/genaiscript-rust-shim && bun run buildShim)" "test-http": "./test-search.ts",
} "build": "(cd packages/genaiscript-rust-shim && bun run buildShim && bun run setupDev && cargo build)"
},
"packageManager": "pnpm@10.7.1+sha512.2d92c86b7928dc8284f53494fb4201f983da65f0fb4f0d40baafa5cf628fa31dae3e5968f12466f17df7e97310e30f343a648baea1b9b350685dafafffdf5808"
} }

View File

@@ -5,7 +5,7 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"buildShim": "esbuild genaiscript-rust-shim.ts --bundle --format=esm --packages=external --outdir=dist --platform=node && chmod +x dist/genaiscript-rust-shim.js", "buildShim": "esbuild genaiscript-rust-shim.ts --bundle --format=esm --packages=external --outdir=dist --platform=node && chmod +x dist/genaiscript-rust-shim.js",
"setupDev": "cp dist/genaiscript-rust-shim.js ../../dist/genaiscript-rust-shim.js" "setupDev": "cp -R ./dist ../../"
}, },
"devDependencies": { "devDependencies": {
"@types/bun": "latest", "@types/bun": "latest",

1
searxng/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.idea

7
searxng/README.md Normal file
View File

@@ -0,0 +1,7 @@
# SearXNG
SearXNG is a free internet metasearch engine which aggregates results from up to 246 search services.
[See Documentation](https://docs.searxng.org)
**Default credentials:**
admin:777b930e

1
searxng/auth-file Normal file
View File

@@ -0,0 +1 @@
admin:XRo6tXfiAEXFk

View File

@@ -0,0 +1,4 @@
#!/usr/bin/env bash
# will prompt for a new password, default is 777b930e
htpasswd -d ./auth-file admin

View File

@@ -0,0 +1,15 @@
FROM searxng/searxng:2025.3.31-08885d061
RUN mkdir -p /etc/searxng
RUN apk upgrade && apk add uwsgi-router_basicauth
COPY settings.yml /etc/searxng/settings.yml
COPY uwsgi.ini /etc/searxng/uwsgi.ini
COPY auth-file /etc/searxng/auth-file
ENV INSTANCE_NAME=searxng \
SEARXNG_SETTINGS_PATH=/etc/searxng/settings.yml \
UWSGI_SETTINGS_PATH=/etc/searxng/uwsgi.ini
CMD ["python3", "-m", "searxng"]

2350
searxng/settings.yml Normal file

File diff suppressed because it is too large Load Diff

53
searxng/uwsgi.ini Normal file
View File

@@ -0,0 +1,53 @@
[uwsgi]
# Who will run the code
uid = searxng
gid = searxng
# Number of workers (usually CPU count)
# default value: %k (= number of CPU core, see Dockerfile)
workers = 1
# Number of threads per worker
# default value: 4 (see Dockerfile)
threads = 4
chmod-socket = 660
# Plugin to use and interpreter config
single-interpreter = true
master = true
plugin = python3
lazy-apps = true
enable-threads = 4
# Module to import
module = searx.webapp
# Virtualenv and python path
pythonpath = /usr/local/searxng/
chdir = /usr/local/searxng/searx/
# automatically set processes name to something meaningful
auto-procname = true
# Disable request logging for privacy
disable-logging = true
log-5xx = true
# Set the max size of a request (request-body excluded)
buffer-size = 8192
# No keep alive
# See https://github.com/searx/searx-docker/issues/24
add-header = Connection: close
# uwsgi serves the static files
static-map = /static=/usr/local/searxng/searx/static
# expires set to one day
static-expires = /* 86400
static-gzip-all = True
offload-threads = 1
# Basic auth
plugins = router_basicauth
route = .* basicauth:Searxng Console,auth-file

View File

@@ -1,6 +1,5 @@
use tokio::process::Child; use tokio::process::Child;
use tracing; use tracing;
use crate::utils::utils::run_agent; use crate::utils::utils::run_agent;
pub async fn agent(stream_id: &str, input: &str) -> Result<Child, String> { pub async fn agent(stream_id: &str, input: &str) -> Result<Child, String> {

View File

@@ -86,7 +86,7 @@ pub async fn use_agent(Path(agent_id): Path<String>) -> impl IntoResponse {
let input = serde_json::to_string(&info.payload.input).unwrap_or_default(); let input = serde_json::to_string(&info.payload.input).unwrap_or_default();
tracing::debug!( tracing::debug!(
"Processing webhook - Resource: {}, Stream ID: {}", "Executing agent - Type: {}, Id: {}",
resource, resource,
agent_id agent_id
); );
@@ -228,7 +228,7 @@ pub async fn create_agent(Json(payload): Json<WebhookPostRequest>) -> impl IntoR
// Verify the write by attempting to read it back // Verify the write by attempting to read it back
match db.get(&stream_id) { match db.get(&stream_id) {
Ok(Some(_)) => { Ok(Some(_)) => {
let stream_url = format!("/webhooks/{}", stream_id); let stream_url = format!("/agents/{}", stream_id);
tracing::info!( tracing::info!(
"Successfully created and verified stream URL: {}", "Successfully created and verified stream URL: {}",
stream_url stream_url

43
test-search.ts Executable file
View File

@@ -0,0 +1,43 @@
#!/usr/bin/env deno -A
const API_ROOT = "http://localhost:3006";
const sid = crypto.randomUUID();
// -------------------- 1. Create the agent --------------------
const createAgentBody = {
id: sid,
resource: "web-search",
parent: sid,
payload: { input: "What is the capital of France?" },
};
const createRes = await fetch(`${API_ROOT}/api/agents`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify(createAgentBody),
});
const raw = await createRes.text();
console.log({raw});
const {stream_url: streamId} = JSON.parse(raw);
console.log("Agent created with streamId:", streamId);
// -------------------- 2. Listen to the SSE stream --------------------
const streamUrl = `${API_ROOT}${streamId}`;
const es = new EventSource(streamUrl);
es.onopen = (e) => {
console.log("connected", e);
};
es.onmessage = (e) => {
console.log("⟶", e.data);
};
es.onerror = (e) => {
console.error("SSE error:", e);
es.close();
};