update README example
This commit is contained in:
59
README.md
59
README.md
@@ -5,37 +5,56 @@ Remote genaiscript host for integration into conversational AI applications.
|
|||||||
|
|
||||||
## Quickstart
|
## Quickstart
|
||||||
```bash
|
```bash
|
||||||
git clone <repo-url>
|
git clone https://github.com/seemueller-io/open-web-agent-rs.git
|
||||||
bun i
|
bun i
|
||||||
bun run build
|
bun run build
|
||||||
bun dev
|
bun dev
|
||||||
```
|
```
|
||||||
|
|
||||||
```javascript
|
```typescript
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env deno -A
|
||||||
|
|
||||||
(async () => {
|
const API_ROOT = "http://localhost:3006";
|
||||||
const url = "http://localhost:3006"
|
|
||||||
const createAgentRequestParams = {
|
|
||||||
|
|
||||||
};
|
const sid = crypto.randomUUID();
|
||||||
|
// -------------------- 1. Create the agent --------------------
|
||||||
|
const createAgentBody = {
|
||||||
|
id: sid,
|
||||||
|
resource: "web-search",
|
||||||
|
parent: sid,
|
||||||
|
payload: { input: "Who won the 2024 election in the US?" },
|
||||||
|
};
|
||||||
|
|
||||||
const createAgentRequest = fetch(url, {
|
const createRes = await fetch(`${API_ROOT}/api/agents`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(createAgentRequestParams)
|
headers: { "content-type": "application/json" },
|
||||||
});
|
body: JSON.stringify(createAgentBody),
|
||||||
|
});
|
||||||
const {streamId} = await createAgentRequest.json();
|
|
||||||
|
|
||||||
|
|
||||||
const streamUrl = new URL(url);
|
const raw = await createRes.text();
|
||||||
streamUrl.pathname = streamId;
|
console.log({raw});
|
||||||
const eventsource = new EventSource(streamUrl)
|
const {stream_url: streamId} = JSON.parse(raw);
|
||||||
|
|
||||||
eventsource.onmessage = (event) => {
|
console.log("Agent created with streamId:", streamId);
|
||||||
console.log(JSON.stringify(event))
|
|
||||||
}
|
// -------------------- 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();
|
||||||
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
### Disclaimer
|
### Disclaimer
|
||||||
|
Reference in New Issue
Block a user