如何在Angular中调用AI对话API
{{ answer }}
`
})
export class ExampleComponent {
answer: string = '';
constructor(private aiApiService: AiApiService) {}
async submitQuestion(question: string) {
this.answer = await this.aiApiService.getResponse(question);
}
}
```
2. 运行项目
在终端中运行以下命令,启动Angular项目:
```bash
ng serve
```
现在,您可以在浏览器中访问`http://localhost:4200`,并在输入框中输入问题,点击“提问”按钮,即可看到AI对话API的回答。
五、总结
本文介绍了如何在Angular中调用AI对话API。通过创建API服务,并在组件中使用该服务,我们可以轻松地将AI对话功能集成到我们的应用中。希望本文对您有所帮助。在后续的开发过程中,您可以根据实际需求调整API服务,实现更多功能。
猜你喜欢:deepseek语音助手