| import { getApiBaseUrl } from '@/config/api';
|
|
|
| |
| |
|
|
| export async function fetchAvailableModels(): Promise<string[]> {
|
| try {
|
| const response = await fetch(`${getApiBaseUrl()}/models`);
|
| if (!response.ok) {
|
| throw new Error('Failed to fetch models');
|
| }
|
| const data = await response.json();
|
|
|
| return Array.isArray(data) ? data : (data.models || []);
|
| } catch (error) {
|
| console.error('Error fetching models:', error);
|
|
|
| return ['microsoft/Fara-7B'];
|
| }
|
| }
|
|
|
| |
| |
|
|
| export async function generateRandomQuestion(): Promise<string> {
|
| try {
|
| const response = await fetch(`${getApiBaseUrl()}/random-question`);
|
| if (!response.ok) {
|
| throw new Error('Failed to generate instruction');
|
| }
|
| const data = await response.json();
|
| return data.question || data.instruction || 'Search for the latest AI news';
|
| } catch (error) {
|
| console.error('Error generating question:', error);
|
|
|
| return 'Search for the latest news about AI agents';
|
| }
|
| }
|
|
|
| |
| |
|
|
| export async function updateStepEvaluation(
|
| traceId: string,
|
| stepId: string,
|
| evaluation: 'like' | 'dislike' | 'neutral'
|
| ): Promise<void> {
|
| try {
|
| 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) {
|
| console.warn('Failed to update step evaluation (endpoint may not exist)');
|
| }
|
| } catch (error) {
|
| console.warn('Error updating step evaluation:', error);
|
| }
|
| }
|
|
|
| |
| |
|
|
| export async function updateTraceEvaluation(
|
| traceId: string,
|
| evaluation: 'success' | 'failed' | 'not_evaluated'
|
| ): Promise<void> {
|
| try {
|
| const response = await fetch(`${getApiBaseUrl()}/traces/${traceId}/evaluation`, {
|
| method: 'PATCH',
|
| headers: {
|
| 'Content-Type': 'application/json',
|
| },
|
| body: JSON.stringify({
|
| user_evaluation: evaluation,
|
| }),
|
| });
|
|
|
| if (!response.ok) {
|
| console.warn('Failed to update trace evaluation (endpoint may not exist)');
|
| }
|
| } catch (error) {
|
| console.warn('Error updating trace evaluation:', error);
|
| }
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| export async function uploadTraceToModal(traceData: object): Promise<{
|
| success: boolean;
|
| message?: string;
|
| error?: string;
|
| }> {
|
| try {
|
| const response = await fetch(`${getApiBaseUrl()}/traces`, {
|
| method: 'POST',
|
| headers: {
|
| 'Content-Type': 'application/json',
|
| },
|
| body: JSON.stringify(traceData),
|
| });
|
|
|
| if (!response.ok) {
|
| const errorText = await response.text();
|
| console.error('Failed to upload trace:', errorText);
|
| return { success: false, error: `HTTP ${response.status}: ${errorText}` };
|
| }
|
|
|
| const result = await response.json();
|
| return result;
|
| } catch (error) {
|
| console.error('Error uploading trace:', error);
|
| return {
|
| success: false,
|
| error: error instanceof Error ? error.message : 'Unknown error'
|
| };
|
| }
|
| }
|
|
|