-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nik
committed
Feb 20, 2024
1 parent
0454d87
commit c0fbf8d
Showing
5 changed files
with
107 additions
and
63 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
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 |
---|---|---|
@@ -1,66 +1,101 @@ | ||
// @ts-nocheck | ||
|
||
import React, {useState, useEffect} from "react"; | ||
import React, { useState } from "react"; | ||
import "./App.css"; | ||
import { Adala } from "./adala"; | ||
import testData from "./testData"; | ||
|
||
type FormData = { | ||
inputFile: string; | ||
outputFile: string; | ||
errorFile: string; | ||
instructions: string; | ||
labels: string[]; // Explicitly typing labels as an array of strings | ||
model: string; | ||
apiKey: string; | ||
passThroughColumns: string[]; | ||
}; | ||
|
||
const App = () => { | ||
const [input, setInput] = useState(""); | ||
const [status, setStatus] = useState(""); | ||
const [jobId, setJobId] = useState(""); // This should be set to the jobId returned from the submit call | ||
const adala = new Adala("http://localhost:30001"); | ||
const [formData, setFormData] = useState<FormData>(testData); | ||
const [status, setStatus] = useState(""); | ||
const [jobId, setJobId] = useState(""); | ||
const adala = new Adala("http://localhost:30001"); | ||
|
||
const handleSubmit = async () => { | ||
try { | ||
const response = await adala.submit({ | ||
inputFile: "input.txt", | ||
outputFile: "output.txt", | ||
errorFile: "error.txt", | ||
instructions: input, | ||
labels: ["positive", "negative"], | ||
model: "gpt-3.5-turbo", | ||
apiKey: "your-api-key" | ||
}); | ||
setJobId(response.data.jobId); | ||
checkStatusPeriodically(); | ||
} catch | ||
(error) { | ||
console.error("Error submitting data to server:", error); | ||
} | ||
}; | ||
const handleSubmit = async () => { | ||
try { | ||
const response = await adala.submit({ | ||
...formData, | ||
labels: formData.labels, | ||
}); | ||
setJobId(response.job_id); | ||
checkStatusPeriodically(response.job_id); | ||
} catch (error) { | ||
console.error("Error submitting data to server:", error); | ||
} | ||
}; | ||
|
||
const checkStatusPeriodically = () => { | ||
const intervalId = setInterval(async () => { | ||
try { | ||
const response = await adala.getStatus({jobId}); | ||
setStatus(response.data.status); | ||
if (response.data.status === "Complete" || response.data.status === "Error") { | ||
clearInterval(intervalId); | ||
} | ||
} catch (error) { | ||
console.error("Error fetching status from server:", error); | ||
const checkStatusPeriodically = (currentJobId: string) => { | ||
const intervalId = setInterval(async () => { | ||
try { | ||
const response = await adala.getStatus({ jobId: currentJobId }); | ||
setStatus(response.status); // Adjust this according to your actual response structure | ||
if (response.status === "SUCCESS" || response.status === "FAILURE") { | ||
clearInterval(intervalId); | ||
} | ||
}, 5000); // Poll every 5 seconds | ||
}; | ||
} catch (error) { | ||
console.error("Error fetching status from server:", error); | ||
clearInterval(intervalId); | ||
} | ||
}, 5000); // Poll every 5 seconds | ||
}; | ||
|
||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const { name, value } = event.target; | ||
setFormData(prevState => ({ | ||
...prevState, | ||
// for list based fields (labels, passThroughColumns), split the value by comma and trim each item | ||
[name]: name === "labels" || name === "passThroughColumns" ? value.split(",").map(item => item.trim()) : value, | ||
})); | ||
}; | ||
|
||
return ( | ||
<div className="app-container"> | ||
<div className="left-panel"> | ||
<input | ||
type="text" | ||
value={input} | ||
onChange={(e) => setInput(e.target.value)} | ||
placeholder="Enter your input" | ||
/> | ||
<button onClick={handleSubmit}>Submit</button> | ||
</div> | ||
<div className="right-panel"> | ||
<textarea readOnly value={status} placeholder="Status will be displayed here"/> | ||
</div> | ||
return ( | ||
<div className="app-container"> | ||
<div className="left-panel"> | ||
{/* Text inputs for each field */} | ||
{Object.entries(formData).map(([key, value]) => { | ||
if ((key !== "labels") && (key !== "passThroughColumns")) | ||
{ | ||
return ( | ||
<input | ||
key={key} | ||
type="text" | ||
name={key} | ||
value={value} | ||
onChange={handleChange} | ||
placeholder={key.charAt(0).toUpperCase() + key.slice(1).replace(/([A-Z])/g, ' $1').trim()} // Formatting key to human-readable form | ||
/> | ||
); | ||
} else { | ||
return ( | ||
<input | ||
key={key} | ||
type="text" | ||
name={key} | ||
value={Array.isArray(value) ? value.join(", ") : ""} | ||
onChange={handleChange} | ||
placeholder="Comma-separated list of items" | ||
/> | ||
); | ||
} | ||
})} | ||
<button onClick={handleSubmit}>Submit</button> | ||
</div> | ||
<div className="right-panel"> | ||
{/*Display job id and status*/} | ||
<p>Job ID: {jobId}</p> | ||
<textarea readOnly value={status} placeholder="Status will be displayed here" /> | ||
</div> | ||
); | ||
} | ||
; | ||
</div> | ||
); | ||
}; | ||
|
||
export default App; |
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