Streamlit + Readme update: copy to cURL (#22)
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
import curlify
|
||||
import requests
|
||||
from requests import PreparedRequest
|
||||
|
||||
from skyvern.forge.sdk.schemas.tasks import TaskRequest
|
||||
|
||||
@@ -11,7 +13,7 @@ class SkyvernClient:
|
||||
self.base_url = base_url
|
||||
self.credentials = credentials
|
||||
|
||||
def create_task(self, task_request_body: TaskRequest) -> str | None:
|
||||
def generate_curl_params(self, task_request_body: TaskRequest) -> PreparedRequest:
|
||||
url = f"{self.base_url}/tasks"
|
||||
payload = task_request_body.model_dump()
|
||||
headers = {
|
||||
@@ -19,11 +21,23 @@ class SkyvernClient:
|
||||
"x-api-key": self.credentials,
|
||||
}
|
||||
|
||||
return url, payload, headers
|
||||
|
||||
def create_task(self, task_request_body: TaskRequest) -> str | None:
|
||||
url, payload, headers = self.generate_curl_params(task_request_body)
|
||||
|
||||
response = requests.post(url, headers=headers, data=json.dumps(payload))
|
||||
if "task_id" not in response.json():
|
||||
return None
|
||||
return response.json()["task_id"]
|
||||
|
||||
def copy_curl(self, task_request_body: TaskRequest) -> str:
|
||||
url, payload, headers = self.generate_curl_params(task_request_body)
|
||||
|
||||
req = requests.Request("POST", url, headers=headers, data=json.dumps(payload, indent=4))
|
||||
|
||||
return curlify.to_curl(req.prepare())
|
||||
|
||||
def get_task(self, task_id: str) -> dict[str, Any] | None:
|
||||
"""Get a task by id."""
|
||||
url = f"{self.base_url}/internal/tasks/{task_id}"
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
from pydantic import BaseModel
|
||||
from skyvern.forge.sdk.schemas.tasks import TaskRequest
|
||||
|
||||
|
||||
class SampleData(BaseModel):
|
||||
class SampleTaskRequest(TaskRequest):
|
||||
name: str
|
||||
url: str
|
||||
navigation_goal: str
|
||||
data_extraction_goal: str
|
||||
navigation_payload: dict
|
||||
extracted_information_schema: dict
|
||||
|
||||
|
||||
geico_sample_data = SampleData(
|
||||
geico_sample_data = SampleTaskRequest(
|
||||
name="Geico",
|
||||
url="https://www.geico.com",
|
||||
navigation_goal="Navigate through the website until you generate an auto insurance quote. Do not generate a home insurance quote. If this page contains an auto insurance quote, consider the goal achieved",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import clipboard
|
||||
import pandas as pd
|
||||
import streamlit as st
|
||||
|
||||
@@ -104,6 +105,11 @@ st.markdown("# **:dragon: Skyvern :dragon:**")
|
||||
st.markdown(f"### **{select_env} - {select_org}**")
|
||||
execute_tab, visualizer_tab = st.tabs(["Execute", "Visualizer"])
|
||||
|
||||
|
||||
def copy_curl_to_clipboard(task_request_body: TaskRequest) -> None:
|
||||
clipboard.copy(client.copy_curl(task_request_body=task_request_body))
|
||||
|
||||
|
||||
with execute_tab:
|
||||
example_tabs = st.tabs([supported_example.name for supported_example in supported_examples])
|
||||
|
||||
@@ -111,8 +117,14 @@ with execute_tab:
|
||||
with example_tab:
|
||||
create_column, explanation_column = st.columns([1, 2])
|
||||
with create_column:
|
||||
run_task, copy_curl = st.columns([3, 1])
|
||||
task_request_body = supported_examples[i]
|
||||
copy_curl.button(
|
||||
"Copy cURL", on_click=lambda: copy_curl_to_clipboard(task_request_body=task_request_body)
|
||||
)
|
||||
with st.form("task_form"):
|
||||
st.markdown("## Run a task")
|
||||
run_task.markdown("## Run a task")
|
||||
|
||||
example = supported_examples[i]
|
||||
# Create all the fields to create a TaskRequest object
|
||||
st_url = st.text_input("URL*", value=example.url, key="url")
|
||||
|
||||
Reference in New Issue
Block a user