-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: api refactor * feat: separate agent mgmt apis, add a front-end ui service layer on next.js * feat: added list method & enhance process mgmt * feat: finalize * feat: add api docs * feat: rename bot_uid and user_uid * fix: fix new line after param table
- Loading branch information
Showing
11 changed files
with
292 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { REQUEST_URL } from '@/common/constant'; | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import { getGraphProperties } from './graph'; | ||
|
||
/** | ||
* Handles the POST request to start an agent. | ||
* | ||
* @param request - The NextRequest object representing the incoming request. | ||
* @returns A NextResponse object representing the response to be sent back to the client. | ||
*/ | ||
export async function POST(request: NextRequest) { | ||
try { | ||
const body = await request.json(); | ||
const { | ||
request_id, | ||
channel_name, | ||
user_uid, | ||
graph_name, | ||
language, | ||
voice_type, | ||
} = body; | ||
|
||
// Send a POST request to start the agent | ||
const response = await fetch(`${REQUEST_URL}/start`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
request_id, | ||
channel_name, | ||
user_uid, | ||
graph_name, | ||
// Get the graph properties based on the graph name, language, and voice type | ||
properties: getGraphProperties(graph_name, language, voice_type), | ||
}), | ||
}); | ||
|
||
const responseData = await response.json(); | ||
|
||
return NextResponse.json(responseData, { status: response.status }); | ||
} catch (error) { | ||
if (error instanceof Response) { | ||
const errorData = await error.json(); | ||
return NextResponse.json(errorData, { status: error.status }); | ||
} else { | ||
return NextResponse.json({ code: "1", data: null, msg: "Internal Server Error" }, { status: 500 }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { REQUEST_URL } from '@/common/constant'; | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
/** | ||
* Handles the POST request to stop an agent. | ||
* | ||
* @param request - The NextRequest object representing the incoming request. | ||
* @returns A NextResponse object representing the response to be sent back to the client. | ||
*/ | ||
export async function POST(request: NextRequest) { | ||
try { | ||
const body = await request.json(); | ||
const { | ||
channel_name, | ||
request_id, | ||
} = body; | ||
|
||
// Send a POST request to stop the agent | ||
const response = await fetch(`${REQUEST_URL}/stop`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
request_id, | ||
channel_name | ||
}), | ||
}); | ||
|
||
// Get the response data | ||
const responseData = await response.json(); | ||
|
||
return NextResponse.json(responseData, { status: response.status }); | ||
} catch (error) { | ||
if (error instanceof Response) { | ||
const errorData = await error.json(); | ||
return NextResponse.json(errorData, { status: error.status }); | ||
} else { | ||
return NextResponse.json({ code: "1", data: null, msg: "Internal Server Error" }, { status: 500 }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
## Request & Response Examples | ||
The server provides a simple layer for managing agent processes. | ||
|
||
### API Resources | ||
|
||
- [POST /start](#get-magazines) | ||
- [POST /stop](#get-magazinesid) | ||
- [POST /ping](#post-magazinesidarticles) | ||
|
||
|
||
### POST /start | ||
This api starts an agent with given graph and override properties. The started agent will join into the specified channel, and subscribe to the uid which your browser/device's rtc use to join. | ||
|
||
| Param | Description | | ||
| -------- | ------- | | ||
| request_id | any uuid for tracing purpose | | ||
| channel_name | channel name, it needs to be the same with the one your browser/device joins, agent needs to stay with your browser/device in the same channel to communicate | | ||
| user_uid | the uid which your browser/device's rtc use to join, agent needs to know your rtc uid to subscribe your audio | | ||
| bot_uid | optional, the uid bot used to join rtc | | ||
| graph_name | the graph to be used when starting agent, will find in property.json | | ||
| properties | additional properties to override in property.json, the override will not change original property.json, only the one agent used to start | | ||
| timeout | determines how long the agent will remain active without receiving any pings. If the timeout is set to `-1`, the agent will not terminate due to inactivity. By default, the timeout is set to 60 seconds, but this can be adjusted using the `WORKER_QUIT_TIMEOUT_SECONDS` variable in your `.env` file. | | ||
|
||
Example: | ||
```bash | ||
curl 'http://localhost:8080/start' \ | ||
-H 'Content-Type: application/json' \ | ||
--data-raw '{ | ||
"request_id": "c1912182-924c-4d15-a8bb-85063343077c", | ||
"channel_name": "test", | ||
"user_uid": 176573, | ||
"graph_name": "camera.va.openai.azure", | ||
"properties": { | ||
"openai_chatgpt": { | ||
"model": "gpt-4o" | ||
} | ||
} | ||
}' | ||
``` | ||
|
||
### POST /stop | ||
This api stops the agent you started | ||
|
||
| Param | Description | | ||
| -------- | ------- | | ||
| request_id | any uuid for tracing purpose | | ||
| channel_name | channel name, the one you used to start the agent | | ||
|
||
Example: | ||
```bash | ||
curl 'http://localhost:8080/stop' \ | ||
-H 'Content-Type: application/json' \ | ||
--data-raw '{ | ||
"request_id": "c1912182-924c-4d15-a8bb-85063343077c", | ||
"channel_name": "test" | ||
}' | ||
``` | ||
|
||
|
||
### POST /ping | ||
This api sends a ping to the server to indicate connection is still alive. This is not needed if you specify `timeout:-1` when starting the agent, otherwise the agent will quit if not receiving ping after timeout in seconds. | ||
|
||
| Param | Description | | ||
| -------- | ------- | | ||
| request_id | any uuid for tracing purpose | | ||
| channel_name | channel name, the one you used to start the agent | | ||
|
||
Example: | ||
```bash | ||
curl 'http://localhost:8080/ping' \ | ||
-H 'Content-Type: application/json' \ | ||
--data-raw '{ | ||
"request_id": "c1912182-924c-4d15-a8bb-85063343077c", | ||
"channel_name": "test" | ||
}' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.