123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- import { HttpService } from '@nestjs/axios'
- import { Injectable } from '@nestjs/common'
- import { lastValueFrom } from 'rxjs'
- import { ServiceResponse } from '@/response/response.interface'
- import { HttpStatusCode } from '@/response/status-code.enum'
- @Injectable()
- export class AgentServerHttpService {
- private readonly baseUrl = 'http://192.168.206.189:8083/api'
- constructor(private readonly httpService: HttpService) {}
- private async makeRequest<T>(
- endpoint: string,
- params?: Record<string, any>
- ): Promise<ServiceResponse<T>> {
- try {
- const url = `${this.baseUrl}/${endpoint}`
- const responseObservable = await this.httpService.get<ServiceResponse<T>>(
- url,
- { params }
- )
- const { data } = await lastValueFrom(responseObservable)
- return data
- } catch (error) {
- return {
- code: HttpStatusCode.INTERNAL_SERVER_ERROR,
- msg: error.message,
- data: null as T
- }
- }
- }
- async makeRequestPost<T>(
- endpoint: string,
- params?: Record<string, any>
- ): Promise<ServiceResponse<T>> {
- try {
- const url = `${this.baseUrl}/${endpoint}`
- const responseObservable = await this.httpService.post<
- ServiceResponse<T>
- >(url, params, {
- headers: {
- 'Content-Type': 'application/json'
- }
- })
- const { data } = await lastValueFrom(responseObservable)
- return data
- } catch (error) {
- return {
- code: HttpStatusCode.INTERNAL_SERVER_ERROR,
- msg: error.message,
- data: null as T
- }
- }
- }
- async listStaffs(): Promise<ServiceResponse<StaffsType[]>> {
- return this.makeRequest<StaffsType[]>('listStaffs')
- }
- async getStaffProfile(
- staff_id: string
- ): Promise<ServiceResponse<StaffProfile>> {
- return this.makeRequest<StaffProfile>('getStaffProfile', { staff_id })
- }
- async getUserProfile(user_id: string): Promise<ServiceResponse<UserProfile>> {
- return this.makeRequest<UserProfile>('getUserProfile', { user_id })
- }
- async listUsers(
- user_name: string,
- user_union_id: string
- ): Promise<ServiceResponse<UserProfile[]>> {
- return this.makeRequest<UserProfile[]>('listUsers', {
- user_name,
- user_union_id
- })
- }
- async getDialogueHistory(
- staff_id: string,
- user_id: string,
- recent_minutes: string
- ): Promise<ServiceResponse<DialogueHistory[]>> {
- return this.makeRequest<DialogueHistory[]>('getDialogueHistory', {
- staff_id,
- user_id,
- recent_minutes
- })
- }
- async listModels(): Promise<ServiceResponse<Model[]>> {
- return this.makeRequest<Model[]>('listModels')
- }
- async listScenes(): Promise<ServiceResponse<any[]>> {
- return this.makeRequest<any[]>('listScenes')
- }
- async getBasePrompt(scene: string): Promise<ServiceResponse<string>> {
- return this.makeRequest<string>('getBasePrompt', { scene })
- }
- async runPrompt(params: any): Promise<ServiceResponse<any>> {
- return this.makeRequestPost<any>('runPrompt', params)
- }
- async formatForPrompt(params: any): Promise<ServiceResponse<any>> {
- return this.makeRequestPost<any>('formatForPrompt', params)
- }
- }
|