|
|
@@ -14,10 +14,7 @@ class AiTranslateController extends Controller
|
|
|
*
|
|
|
* @return \Illuminate\Http\Response
|
|
|
*/
|
|
|
- public function index()
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
+ public function index() {}
|
|
|
|
|
|
/**
|
|
|
* Store a newly created resource in storage.
|
|
|
@@ -31,31 +28,32 @@ class AiTranslateController extends Controller
|
|
|
return $this->fetch(strip_tags($request->get('origin')));
|
|
|
}
|
|
|
|
|
|
- private function fetch($origin,$engin='kimi',$prompt_pre='',$prompt_suf='请翻译上述巴利文。'){
|
|
|
+ private function fetch($origin, $engin = 'kimi', $prompt_pre = '', $prompt_suf = '请翻译上述巴利文。')
|
|
|
+ {
|
|
|
$api = config('mint.ai.accounts');
|
|
|
- $selected = array_filter($api,function($value) use($engin){
|
|
|
- return $value['name']===$engin;
|
|
|
+ $selected = array_filter($api, function ($value) use ($engin) {
|
|
|
+ return $value['name'] === $engin;
|
|
|
});
|
|
|
- if(!is_array($selected) || count($selected)===0){
|
|
|
- return $this->error('no engin name',200,200);
|
|
|
+ if (!is_array($selected) || count($selected) === 0) {
|
|
|
+ return $this->error('no engin name', 200, 200);
|
|
|
}
|
|
|
|
|
|
$url = $selected[0]['api_url'];
|
|
|
$param = [
|
|
|
- "model" => $selected[0]['model'],
|
|
|
- "messages" => [
|
|
|
- ["role" => "system","content" => "你是翻译人工智能助手,bhikkhu 为专有名词,不可翻译成其他语言。"],
|
|
|
- ["role" => "user","content" => "{$prompt_pre}{$origin}\n{$prompt_suf}"],
|
|
|
- ],
|
|
|
- "temperature" => 0.3,
|
|
|
+ "model" => $selected[0]['model'],
|
|
|
+ "messages" => [
|
|
|
+ ["role" => "system", "content" => "你是翻译人工智能助手,bhikkhu 为专有名词,不可翻译成其他语言。"],
|
|
|
+ ["role" => "user", "content" => "{$prompt_pre}{$origin}\n{$prompt_suf}"],
|
|
|
+ ],
|
|
|
+ "temperature" => 0.3,
|
|
|
];
|
|
|
$response = Http::withToken('sk-kwjHIMh3PoWwUwQyKdT3KHvNe8Es19SUiujGrxtH09uDQCui')
|
|
|
- ->post($url,$param);
|
|
|
- if($response->failed()){
|
|
|
- $this->error('http request error'.$response->json('message'));
|
|
|
- Log::error('http request error', ['data'=>$response->json()]);
|
|
|
- return $this->error($response->json(),200,200);
|
|
|
- }else{
|
|
|
+ ->post($url, $param);
|
|
|
+ if ($response->failed()) {
|
|
|
+ $this->error('http request error' . $response->json('message'));
|
|
|
+ Log::error('http request error', ['data' => $response->json()]);
|
|
|
+ return $this->error($response->json(), 200, 200);
|
|
|
+ } else {
|
|
|
return $this->ok($response->json());
|
|
|
}
|
|
|
}
|
|
|
@@ -66,21 +64,21 @@ class AiTranslateController extends Controller
|
|
|
* @param string $id
|
|
|
* @return \Illuminate\Http\Response
|
|
|
*/
|
|
|
- public function show(Request $request,$id)
|
|
|
+ public function show(Request $request, $id)
|
|
|
{
|
|
|
//
|
|
|
- $para = explode('-',$id);
|
|
|
- if(count($para) >= 2){
|
|
|
- $content = PaliText::where('book',$para[0])
|
|
|
- ->where('paragraph',$para[1])
|
|
|
- ->value('text');
|
|
|
- if(!empty($content)){
|
|
|
- return $this->fetch($content,$request->get('engin',config('mint.ai.default')));
|
|
|
- }else{
|
|
|
- return $this->error('no content',200,200);
|
|
|
+ $para = explode('-', $id);
|
|
|
+ if (count($para) >= 2) {
|
|
|
+ $content = PaliText::where('book', $para[0])
|
|
|
+ ->where('paragraph', $para[1])
|
|
|
+ ->value('text');
|
|
|
+ if (!empty($content)) {
|
|
|
+ return $this->fetch($content, $request->get('engin', config('mint.ai.default')));
|
|
|
+ } else {
|
|
|
+ return $this->error('no content', 200, 200);
|
|
|
}
|
|
|
- }else{
|
|
|
- return $this->error('参数错误',403,403);
|
|
|
+ } else {
|
|
|
+ return $this->error('参数错误', 403, 403);
|
|
|
}
|
|
|
}
|
|
|
|