refactor: change endpoint

pull/24/head
hanchchch 1 year ago
parent b119a3a6c2
commit 40359dce30

@ -13,10 +13,13 @@ https://user-images.githubusercontent.com/51526347/230061897-b3479405-8ebd-45ab-
EVAL Making a UI for itself
#### [EVAL-BOT](https://github.com/eval-bot)
EVAL's self-managed github account. EVAL does everything except for signup and bio setting.
### Examples
[Here](examples/) is an example.
### EVAL's FEATURE
1. **Multimodal Conversation**
@ -107,20 +110,20 @@ Some tools requires environment variables. Set envs depend on which tools you wa
### 3. Send request to EVAL
- `POST /command`
- `POST /api/execute`
- `key` - session id
- `session` - session id
- `files` - urls of file inputs
- `query` - prompt
- `prompt` - prompt
- You can send request to EVAL with `curl` or `httpie`.
```bash
curl -X POST -H "Content-Type: application/json" -d '{"key": "sessionid", "files": ["https://example.com/image.png"], "query": "Hi there!"}' http://localhost:8000/command
curl -X POST -H "Content-Type: application/json" -d '{"session": "sessionid", "files": ["https://example.com/image.png"], "prompt": "Hi there!"}' http://localhost:8000/command
```
```bash
http POST http://localhost:8000/command key=sessionid files:='["https://example.com/image.png"]' query="Hi there!"
http POST http://localhost:8000/command session=sessionid files:='["https://example.com/image.png"]' prompt="Hi there!"
```
- We are planning to make a GUI for EVAL so you can use it without terminal.

@ -62,14 +62,14 @@ agent_manager = AgentManager.create(toolsets=toolsets)
file_handler = FileHandler(handlers=handlers)
class CommandRequest(BaseModel):
key: str
query: str
class ExecuteRequest(BaseModel):
session: str
prompt: str
files: List[str]
class CommandResponse(TypedDict):
response: str
class ExecuteResponse(TypedDict):
answer: str
files: List[str]
@ -90,11 +90,11 @@ async def create_upload_file(files: List[UploadFile]):
return {"urls": urls}
@app.post("/command")
async def command(request: CommandRequest) -> CommandResponse:
query = request.query
@app.post("/api/execute")
async def execute(request: ExecuteRequest) -> ExecuteResponse:
query = request.prompt
files = request.files
session = request.key
session = request.session
executor = agent_manager.get_or_create_executor(session)
@ -104,12 +104,12 @@ async def command(request: CommandRequest) -> CommandResponse:
try:
res = executor({"input": promptedQuery})
except Exception as e:
return {"response": str(e), "files": []}
return {"answer": str(e), "files": []}
files = re.findall("(image/\S*png)|(dataframe/\S*csv)", res["output"])
return {
"response": res["output"],
"answer": res["output"],
"files": [uploader.upload(file) for file in files],
}

@ -1,21 +1,21 @@
{% extends "base.html" %} {% block head %}
<script src="{{ url_for('static', path='/command.js') }}"></script>
<script src="{{ url_for('static', path='/execute.js') }}"></script>
{% endblock %} {% block content %}
<div class="container-fluid pb-3">
<div class="d-grid gap-3" style="grid-template-columns: 2fr 3fr">
<div class="bg-body-tertiary border rounded-3 p-3">
<div>
<div class="mb-3">
<label for="query" class="form-label">Prompt</label>
<textarea id="query" name="query" class="form-control"></textarea>
<label for="prompt" class="form-label">Prompt</label>
<textarea id="prompt" name="prompt" class="form-control"></textarea>
</div>
<div class="mb-3">
<label for="files" class="form-label">Files</label>
<input id="files" type="file" class="form-control" />
</div>
<div class="mb-3">
<label for="key" class="form-label">Session</label>
<input id="key" name="key" class="form-control" />
<label for="session" class="form-label">Session</label>
<input id="session" name="session" class="form-control" />
</div>
<button type="submit" class="btn btn-primary" onclick="submit(event)">
Submit

@ -15,21 +15,21 @@ const submit = async () => {
files.push(...urls);
}
const query = document.getElementById("query").value;
const key = document.getElementById("key").value;
const prompt = document.getElementById("prompt").value;
const session = document.getElementById("session").value;
const response = await fetch("/command", {
const response = await fetch("/api/execute", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
query,
key,
prompt,
session,
files,
}),
});
const { response: answer } = await response.json();
const { answer } = await response.json();
document.getElementById("answer").textContent = answer;
};
Loading…
Cancel
Save