diff --git a/application/api/user/routes.py b/application/api/user/routes.py index 239278b9..b1ec69e4 100644 --- a/application/api/user/routes.py +++ b/application/api/user/routes.py @@ -351,7 +351,14 @@ def get_api_keys(): keys = api_key_collection.find({"user": user}) list_keys = [] for key in keys: - list_keys.append({"id": str(key["_id"]), "name": key["name"], "key": key["key"][:4] + "..." + key["key"][-4:], "source": key["source"]}) + list_keys.append({ + "id": str(key["_id"]), + "name": key["name"], + "key": key["key"][:4] + "..." + key["key"][-4:], + "source": key["source"], + "prompt_id": key["prompt_id"], + "chunks": key["chunks"] + }) return jsonify(list_keys) @user.route("/api/create_api_key", methods=["POST"]) @@ -359,6 +366,8 @@ def create_api_key(): data = request.get_json() name = data["name"] source = data["source"] + prompt_id = data["prompt_id"] + chunks = data["chunks"] key = str(uuid.uuid4()) user = "local" resp = api_key_collection.insert_one( @@ -367,6 +376,8 @@ def create_api_key(): "key": key, "source": source, "user": user, + "prompt_id": prompt_id, + "chunks": chunks } ) new_id = str(resp.inserted_id) diff --git a/frontend/src/Setting.tsx b/frontend/src/Setting.tsx index 172691a0..46c64cad 100644 --- a/frontend/src/Setting.tsx +++ b/frontend/src/Setting.tsx @@ -205,6 +205,7 @@ const General: React.FC = () => {

Select Theme

{ @@ -218,6 +219,7 @@ const General: React.FC = () => { Select Language

{ Chunks processed per query

dispatch(setChunks(value))} @@ -677,7 +680,13 @@ const APIKeys: React.FC = () => { console.log(error); } }; - const createAPIKey = (payload: { name: string; source: string }) => { + + const createAPIKey = (payload: { + name: string; + source: string; + prompt_id: string; + chunks: string; + }) => { fetch(`${apiHost}/api/create_api_key`, { method: 'POST', headers: { @@ -808,7 +817,12 @@ const SaveAPIKeyModal: React.FC = ({ apiKey, close }) => { type CreateAPIKeyModalProps = { close: () => void; - createAPIKey: (payload: { name: string; source: string }) => void; + createAPIKey: (payload: { + name: string; + source: string; + prompt_id: string; + chunks: string; + }) => void; }; const CreateAPIKeyModal: React.FC = ({ close, @@ -819,7 +833,33 @@ const CreateAPIKeyModal: React.FC = ({ label: string; value: string; } | null>(null); + + const chunkOptions = ['0', '2', '4', '6', '8', '10']; + const [chunk, setChunk] = useState('2'); + const [activePrompts, setActivePrompts] = useState< + { name: string; id: string; type: string }[] + >([]); + const [prompt, setPrompt] = useState<{ + name: string; + id: string; + type: string; + } | null>(null); const docs = useSelector(selectSourceDocs); + useEffect(() => { + const fetchPrompts = async () => { + try { + const response = await fetch(`${apiHost}/api/get_prompts`); + if (!response.ok) { + throw new Error('Failed to fetch prompts'); + } + const promptsData = await response.json(); + setActivePrompts(promptsData); + } catch (error) { + console.error(error); + } + }; + fetchPrompts(); + }, []); const extractDocPaths = () => docs ? docs @@ -872,7 +912,7 @@ const CreateAPIKeyModal: React.FC = ({
@@ -881,11 +921,41 @@ const CreateAPIKeyModal: React.FC = ({ options={extractDocPaths()} />
+ +
+ + setPrompt(value) + } + /> +
+
+

+ Chunks processed per query +

+ setChunk(value)} + /> +