Skip to content

Commit

Permalink
autocomplete and new config
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulschand committed Oct 25, 2023
1 parent f887662 commit 83ca8d0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion public/all_configs.json

Large diffs are not rendered by default.

52 changes: 50 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useState, useEffect } from "react";
import TextInput from "./textBox";
import Modal from "react-modal";

Expand Down Expand Up @@ -942,6 +942,11 @@ function App() {

const [modalIsOpen, setIsOpen] = React.useState(false);

const [responseCache, setResponseCache] = useState(null);
const [responseCacheKeys, setResponseCacheKeys] = useState(null);

const [suggestions, setSuggestions] = useState([]);

const [jsonData, setJsonData] = useState(null);

function openModal() {
Expand Down Expand Up @@ -1032,7 +1037,7 @@ function App() {
openModal();
return;
}
let parsedConfig = await fetchParams(specialMapping(modelName));
let parsedConfig = responseCache.hasOwnProperty(modelName) ? responseCache[modelName] : null;
const out = getAllComputedData(
parsedConfig,
jsonData,
Expand Down Expand Up @@ -1073,6 +1078,36 @@ function App() {

// };

useEffect(() => {
// Your function here to populate myVariable
const fetchData = async () => {
// Fetch data or perform some other operation
let response = await fetch(configPath);
response = await response.json();
setResponseCache(response);
setResponseCacheKeys(Object.keys(response));
};

fetchData();
}, []);

useEffect(() => {
if (modelName) {
if (modelName.length>2){
const filtered = responseCacheKeys.filter(item => item.startsWith(modelName) && item !== modelName);
setSuggestions(filtered.slice(0,10));
}
else{
setSuggestions([]);
}
}
else{
setSuggestions([]);
}
}, [modelName]);

console.log(responseCache);

return (
<div className="App">
<header className="App-header">
Expand Down Expand Up @@ -1123,12 +1158,25 @@ function App() {
<label className="text-sm font-mono pr-4">
Model Name (Hugginface ID)
</label>
<div>
<TextInput
className="w-64 font-mono input border border-black text-sm"
value={modelName}
setValue={setModelName}
placeholder="e.g. meta-llama/Llama-2-7b-hf"
/>
<ul className="mt-2 border rounded divide-y">
{suggestions.map((item, index) => (
<li
key={index}
onClick={() => setModelName(item)}
className="p-2 hover:bg-gray-200 cursor-pointer"
>
{item}
</li>
))}
</ul>
</div>
</div>
<label className="text-sm">OR</label>

Expand Down

0 comments on commit 83ca8d0

Please sign in to comment.