MCPcopy
hub / github.com/whoiskatrin/sql-translator / translate

Function translate

hooks/useTranslate.ts:13–48  ·  view source on GitHub ↗
({
		inputText,
		tableSchema,
		isHumanToSql,
	}: { inputText: string; tableSchema: string; isHumanToSql: boolean })

Source from the content-addressed store, hash-verified

11 const [translationError, setTranslationError] = useState("");
12
13 const translate = async ({
14 inputText,
15 tableSchema,
16 isHumanToSql,
17 }: { inputText: string; tableSchema: string; isHumanToSql: boolean }) => {
18 setTranslating(true);
19 try {
20 const requestBody: RequestBody = { inputText };
21 if (tableSchema !== "") {
22 requestBody.tableSchema = tableSchema;
23 }
24 const response = await fetch(
25 `/api/${isHumanToSql ? "translate" : "sql-to-human"}`,
26 {
27 method: "POST",
28 body: JSON.stringify(requestBody),
29 headers: { "Content-Type": "application/json" },
30 },
31 );
32 if (response.ok) {
33 const data = await response.json();
34 setOutputText(data.outputText);
35 } else {
36 setTranslationError(
37 `Error translating ${isHumanToSql ? "to SQL" : "to human"}.`,
38 );
39 }
40 } catch (error) {
41 console.error(error);
42 setTranslationError(
43 `Error translating ${isHumanToSql ? "to SQL" : "to human"}.`,
44 );
45 } finally {
46 setTranslating(false);
47 }
48 };
49
50 return {
51 outputText,

Callers 1

handleSubmitFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected