langgraph.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import axios from 'axios'
  2. // LangGraph 服务地址
  3. const LANGGRAPH_BASE = 'https://ai.etotem.com.cn'
  4. // 直接创建 axios 实例,不走通用拦截器(LangGraph 返回原始 JSON,不是 {code, data} 格式)
  5. const lgAxios = axios.create({
  6. baseURL: LANGGRAPH_BASE,
  7. timeout: 10000,
  8. withCredentials: true
  9. })
  10. /**
  11. * 获取 LangGraph 健康状态
  12. */
  13. export function getLangGraphHealth() {
  14. return new Promise((resolve) => {
  15. const img = new Image()
  16. img.onload = () => resolve({ status: 'healthy' })
  17. img.onerror = () => resolve({ status: 'unreachable' })
  18. img.src = LANGGRAPH_BASE + '/health?t=' + Date.now()
  19. })
  20. }
  21. /**
  22. * 获取 LangGraph OpenAPI 规范
  23. */
  24. export function getLangGraphSpec() {
  25. return lgAxios.get('/openapi.json')
  26. }
  27. /**
  28. * 获取详细健康检查
  29. */
  30. export function getLangGraphDetailedHealth() {
  31. return lgAxios.get('/api/v1/health')
  32. }
  33. /**
  34. * 获取 Prometheus metrics
  35. */
  36. export function getLangGraphMetrics() {
  37. return lgAxios.get('/metrics')
  38. }
  39. /**
  40. * 测试食材识别
  41. */
  42. export function testFoodRecognize(data) {
  43. return lgAxios.post('/api/v1/food/recognize', data, { timeout: 60000 })
  44. }
  45. /**
  46. * 测试菜单生成
  47. */
  48. export function testMenuGenerate(data) {
  49. return lgAxios.post('/api/v1/menu/generate', data, { timeout: 60000 })
  50. }
  51. /**
  52. * 测试对话
  53. */
  54. export function testChat(data) {
  55. return lgAxios.post('/api/v1/chat', data, { timeout: 60000 })
  56. }
  57. /**
  58. * 测试营养推荐
  59. */
  60. export function testRecommend(data) {
  61. return lgAxios.post('/api/v1/recommend', data, { timeout: 60000 })
  62. }
  63. /**
  64. * 测试问卷生成
  65. */
  66. export function testQuestionnaireGenerate(data) {
  67. return lgAxios.post('/api/v1/questionnaire/generate', data, { timeout: 60000 })
  68. }