File size: 1,850 Bytes
51747e6
67b042f
 
 
 
 
51747e6
67b042f
 
 
 
 
 
 
 
 
 
f505f2c
51747e6
67b042f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51747e6
67b042f
 
 
 
 
 
 
 
 
 
 
 
 
3593cc3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { getApiBaseUrl } from '@/config/api';

/**
 * Fetch available models from the backend
 */
export async function fetchAvailableModels(): Promise<string[]> {
  const response = await fetch(`${getApiBaseUrl()}/models`);
  if (!response.ok) {
    throw new Error('Failed to fetch models');
  }
  const data = await response.json();
  return data.models;
}

/**
 * Generate a random instruction from the backend
 */
export async function generateRandomQuestion(): Promise<string> {
  const response = await fetch(`${getApiBaseUrl()}/generate-instruction`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
  });
  if (!response.ok) {
    throw new Error('Failed to generate instruction');
  }
  const data = await response.json();
  return data.instruction;
}

/**
 * Update step evaluation (vote)
 */
export async function updateStepEvaluation(
  traceId: string,
  stepId: string,
  evaluation: 'like' | 'dislike' | 'neutral'
): Promise<void> {
  const response = await fetch(`${getApiBaseUrl()}/traces/${traceId}/steps/${stepId}`, {
    method: 'PATCH',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      step_evaluation: evaluation,
    }),
  });

  if (!response.ok) {
    throw new Error('Failed to update step evaluation');
  }
}

/**
 * Update trace evaluation (overall task feedback)
 */
export async function updateTraceEvaluation(
  traceId: string,
  evaluation: 'success' | 'failed' | 'not_evaluated'
): Promise<void> {
  const response = await fetch(`${getApiBaseUrl()}/traces/${traceId}/evaluation`, {
    method: 'PATCH',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      user_evaluation: evaluation,
    }),
  });

  if (!response.ok) {
    throw new Error('Failed to update trace evaluation');
  }
}