普通数据后端PHP代码
- public function update2()
- {
- $post = input('post.chatgpt/a');
- if(!$post['id']){
- $this->error('ID错误');
- }
- //调用普通接口
- $result = file_get_contents('./test.json');
- //返回结果
- $json = json_decode($result,true);
- $this->success('ok','index/chatgpt/index',['question'=>$post,'answer'=>$json['choices'][0]['message']['content']]);
- }
复制代码
普通数据后端test.json数据
- {
- "id": "chatcmpl-7QcnJYT3QF6BUpN5M2KYRhE1dKvHO",
- "object": "chat.completion",
- "created": 1686580009,
- "model": "gpt-3.5-turbo-0301",
- "usage": {
- "prompt_tokens": 103,
- "completion_tokens": 300,
- "total_tokens": 403
- },
- "choices": [{
- "message": {
- "role": "assistant",
- "content": "# 《小王子》故事大纲\n\n## 概述\n\n《小王子》是法国作家安托万·德·圣-埃克苏佩里所写的一部儿童文学小说,于1943年首次出版。故事讲述了小王子在行星间旅行,寻找真正的友谊和爱情的故事。\n\n## 主要情节\n\n1. 小王子来到地球\n - 遇见飞行员\n - 向飞行员讲述他的经历\n2. 小王子的故事\n - 离开自己的小行星\n - 到达其他行星,与不同的人相遇\n - 发现爱情和友谊的重要性\n - 寻找回家的路\n3. 小王子离开地球\n - 告别飞行员\n - 回到自己的小行星\n\n## 人物角色\n\n- 小王子:主人公,寻找友谊和爱情\n- 飞行员:"
- },
- "finish_reason": "length",
- "index": 0
- }]
- }
复制代码
|