import React, { useEffect, useState } from 'react'; import { Form, Button, Card, Row, Col, Spin, Input, Collapse } from 'antd'; import { CloseOutlined, CheckOutlined } from '@ant-design/icons' import ModelSelection from '../../../components/DropdownInput/ModelSelection'; import { APIPostDemoPrivacy, APIPostDemoBias, APIPostDemoHarmfulOutput } from '../../../services/attack'; import { PromptSelection } from '../../../components/DropdownInput/PromptSelections'; const { Panel } = Collapse; const defaultModel = "GPT35" interface Props { mode: DemoIOMode } export enum DemoIOMode { HarmfulOutput, Privacy, Bias } function AttackPrompt(text: string) { return {text} } function DemoIO( { mode } : Props) { const [form] = Form.useForm(); const [modifiedPrompt, setModifiedPrompt] = useState(''); const [responseWithoutGuard, setResponseWithoutGuard] = useState(''); const [responseWithGuard, setResponseWithGuard] = useState(''); const [currModel, setCurrModel] = useState(defaultModel); const [currPrompt, setCurrPrompt] = useState(""); const [loading, setLoading] = useState(false); useEffect(() => { setModifiedPrompt(""); setResponseWithoutGuard(""); setResponseWithGuard(""); }, [mode]); const handleSubmit = async (value: any) => { // Simulate modifying the prompt setLoading(true); setModifiedPrompt(""); setResponseWithoutGuard(""); setResponseWithGuard(""); let result; try { switch (mode) { case DemoIOMode.Bias: result = await APIPostDemoBias(currPrompt, currModel, value['attribute']); break; case DemoIOMode.Privacy: result = await APIPostDemoPrivacy(currPrompt, currModel); break; case DemoIOMode.HarmfulOutput: result = await APIPostDemoHarmfulOutput(currPrompt, currModel); break; default: result = null break; }} catch (error) { console.error(error) alert(`Failed to run. Error ${JSON.stringify(error)}`) } setLoading(false) if (!result) return; const {attack_prompt, response, defense_response} = result.data; setModifiedPrompt(attack_prompt); setResponseWithoutGuard(response); setResponseWithGuard(defense_response); }; return (
{/* Do not use prompt here */} {/*