nsarrazin HF Staff commited on
Commit
71b3944
·
unverified ·
1 Parent(s): aa186af

Standardize llama.cpp endpoint with `baseURL` (#1305)

Browse files

* Standardize llama.cpp endpoint with `baseURL`

* cleaner

src/lib/server/endpoints/llamacpp/endpointLlamacpp.ts CHANGED
@@ -9,7 +9,8 @@ export const endpointLlamacppParametersSchema = z.object({
9
  weight: z.number().int().positive().default(1),
10
  model: z.any(),
11
  type: z.literal("llamacpp"),
12
- url: z.string().url().default("http://127.0.0.1:8080"),
 
13
  accessToken: z
14
  .string()
15
  .min(1)
@@ -19,7 +20,7 @@ export const endpointLlamacppParametersSchema = z.object({
19
  export function endpointLlamacpp(
20
  input: z.input<typeof endpointLlamacppParametersSchema>
21
  ): Endpoint {
22
- const { url, model } = endpointLlamacppParametersSchema.parse(input);
23
  return async ({ messages, preprompt, continueMessage, generateSettings }) => {
24
  const prompt = await buildPrompt({
25
  messages,
@@ -30,7 +31,7 @@ export function endpointLlamacpp(
30
 
31
  const parameters = { ...model.parameters, ...generateSettings };
32
 
33
- const r = await fetch(`${url}/completion`, {
34
  method: "POST",
35
  headers: {
36
  "Content-Type": "application/json",
 
9
  weight: z.number().int().positive().default(1),
10
  model: z.any(),
11
  type: z.literal("llamacpp"),
12
+ url: z.string().url().default("http://127.0.0.1:8080"), // legacy, feel free to remove in breaking change update
13
+ baseURL: z.string().url().optional(),
14
  accessToken: z
15
  .string()
16
  .min(1)
 
20
  export function endpointLlamacpp(
21
  input: z.input<typeof endpointLlamacppParametersSchema>
22
  ): Endpoint {
23
+ const { baseURL, url, model } = endpointLlamacppParametersSchema.parse(input);
24
  return async ({ messages, preprompt, continueMessage, generateSettings }) => {
25
  const prompt = await buildPrompt({
26
  messages,
 
31
 
32
  const parameters = { ...model.parameters, ...generateSettings };
33
 
34
+ const r = await fetch(`${baseURL ?? url}/completion`, {
35
  method: "POST",
36
  headers: {
37
  "Content-Type": "application/json",