All files / src/services/api/routers ModelRouter.tsx

81.25% Statements 13/16
76% Branches 19/25
100% Functions 4/4
81.25% Lines 13/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                        2209x           2209x 140x         140x 140x         2209x 14x 14x 14x         2209x                           6x                           6x 6x          
import { Model, PromptResponse } from "@/objects/Model";
import { Dictionary } from "@/types/ext";
import { AxiosRequestConfig } from "axios";
import { APIRouter } from "../ApiRouter";
 
export class ModelRouter extends APIRouter {
  constructor(
    host: string,
    token: string | null = null,
    default_config: AxiosRequestConfig | null = null,
    headers: Dictionary<string> = {},
  ) {
    super("models", host, token, default_config, headers);
  }
 
  /** The model catalogue. `includeArchived` adds the models taken out of
   *  it — to name what an old conversation or trace ran on, never to offer
   *  one for choosing. */
  list = async (options: { includeArchived?: boolean } = {}) => {
    const res = await this.api.get<Model[]>(
      options.includeArchived
        ? `${this.prefix}?include_archived=true`
        : this.prefix,
    );
    Eif (super.validRes(res)) {
      return res.data;
    }
    return null;
  };
 
  id = async (val: string) => {
    const res = await this.api.get(super.endpoint(`${val}`));
    Eif (super.validRes(res)) {
      return res.data as Model;
    }
    return null;
  };
 
  prompt = async (
    id: string,
    prompt: string,
    conversationId: string | null = null,
    system_messages: string[] = [],
    file_ids: string[] = [],
    temperature?: number,
    signal?: AbortSignal,
    output_format?: string,
    output_schema?: string,
    /** The client's id for this turn, which its Stop names
     *  (`turn_router.stop`) before the response arrives. */
    turn_id?: string,
  ) => {
    const res = await this.api.post(
      super.endpoint(`${id}/prompt`),
      {
        prompt,
        conversation_id: conversationId,
        system_messages,
        file_ids,
        ...(temperature !== undefined ? { temperature } : {}),
        ...(output_format ? { output_format } : {}),
        ...(output_schema ? { output_schema } : {}),
        ...(turn_id ? { turn_id } : {}),
      },
      signal ? { signal } : null,
    );
    Eif (super.validRes(res)) {
      return res.data as PromptResponse;
    }
    return null;
  };
}