forked from DDeokNip/Pizza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (35 loc) · 1.33 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const express = require("express")
const { exec } = require("child_process")
const cors = require("cors")
const app = express()
app.use(cors())
app.use(express.json())
app.post("/ask", (req, res) => {
const question = req.body.question
exec(
`python /Users/kim_jeonghyeon/VSCodeProjects/llama.cpp/_04_get_answer.py --question "${question}"`,
(error, stdout, stderr) => {
if (error) {
return res.status(500).json({ error: error.message })
}
if (stderr) {
return res.status(500).json({ error: stderr })
}
const answerMatch = stdout.match(/\[Answer\]\s*A:\s*(.*)/s)
if (answerMatch) {
let answer = answerMatch[1].trim()
// 한글로 시작하는 첫 번째 위치를 찾기 위한 정규 표현식
const firstKoreanCharIndex = answer.search(/[가-힣]/)
if (firstKoreanCharIndex !== -1) {
answer = answer.substring(firstKoreanCharIndex).trim()
}
res.json({ answer })
} else {
res.status(500).json({ error: "답변을 파싱하는 중 오류가 발생했습니다." })
}
}
)
})
app.listen(5001, () => {
console.log("Server is running on http://localhost:5001")
})