File
Metadata
selector |
app-page-mine |
styleUrls |
page-mine.component.scss |
templateUrl |
page-mine.component.html |
Methods
getEatAndSend
|
getEatAndSend()
|
Returns: any
|
send
|
send(content: string)
|
Returns: void
|
sendnull
|
sendnull()
|
Returns: void
|
getEat
|
getEat()
|
Returns: any
|
messageList
|
messageList: TestChatMessage[]
|
userInput
|
userInput: string
|
import { Component, NgModule } from '@angular/core';
import { Router } from '@angular/router';
import * as Parse from "parse"
(Parse as any).serverURL = "http://metapunk.cn:9999/parse"
Parse.initialize("dev")
// 引入IonicModule依赖
import { TestChatCompletion, TestChatMessage } from './class-chat-completion';
// interface Spot {
// name: string // 名称
// location: string // 地点
// food: string//美食
// activity: string//娱乐项目
// }
@Component({
selector: 'app-page-mine',
templateUrl: './page-mine.component.html',
styleUrls: ['./page-mine.component.scss']
})
export class PageMineComponent {
// constructor(private router: Router) { }
// 跳转函数
// goSpotDetail(spot: Spot) {
// this.router.navigate(["/lesson/mine/spotDetail"], {
// queryParams: spot
// })
// }
// spotList: Array<Spot> = [
// {
// "name": "庐山龙虎山风景名胜区",
// "location": "九江市",
// "food": "庐山烤鱼、龙虎山茶叶",
// "activity": "徒步、登山、观景"
// },
// {
// "name": "鄱阳湖",
// "location": "九江市、上饶市、抚州市",
// "food": "鄱阳湖鲜鱼",
// "activity": "游船、钓鱼、观鸟"
// },
// {
// "name": "井冈山革命旧址",
// "location": "吉安市",
// "food": "井冈山农家菜",
// "activity": "红色旅游、参观革命历史景点"
// },
// {
// "name": "赣州岩画",
// "location": "赣州市",
// "food": "赣州米粉",
// "activity": "观赏岩画、文化考察"
// },
// {
// "name": "庐山东林寺",
// "location": "九江市",
// "food": "庐山烤鱼、庐山茶",
// "activity": "参观古寺、禅修体验"
// }
// ]
messageList: Array<TestChatMessage> = []
userInput: string = ""
completion: TestChatCompletion
constructor() {
this.completion = new TestChatCompletion(this.messageList)
}
async getEatAndSend(): Promise<void> {
const food = await this.getEat();
if (food) {
this.send("这是我的早餐,请分析:" + food);
}
}
send(content: string) {
this.messageList.push({
role: "user",
content: content
});
this.userInput = "";
this.completion.createCompletionByStream();
}
sendnull() {
this.messageList.push({
role: "user",
content: this.userInput
})
this.userInput = ""
this.completion.createCompletionByStream()
}
async getEat(): Promise<string | null> {
const Upload = Parse.Object.extend("HealthEat");
const query = new Parse.Query(Upload);
query.descending("food");
query.limit(1); // 限制查询结果为最新的一个
try {
const result = await query.find();
if (result.length > 0) {
const food = result[0].get("food");
console.log(food);
return food;
} else {
return null;
}
} catch (error) {
console.error("Error:", error);
return null;
}
}
}