Skip to content

Commit 787f203

Browse files
committed
refactor: Simplifies API base URL handling
Removes the need to specify the base URL for API calls within the `ChatService` class by utilizing Vite's proxy configuration. This change streamlines the code and centralizes the base URL configuration in `vite.config.ts`. It also adds a proxy for the `/slots` endpoint.
1 parent e23d39d commit 787f203

File tree

3 files changed

+3
-12
lines changed

3 files changed

+3
-12
lines changed

tools/server/webui/.env.example

Lines changed: 0 additions & 1 deletion
This file was deleted.

tools/server/webui/src/lib/services/chat.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,8 @@ import { config } from '$lib/stores/settings.svelte';
55
* Provides methods for sending messages, handling streaming responses, and managing chat sessions.
66
*/
77
export class ChatService {
8-
private baseUrl: string;
98
private abortController: AbortController | null = null;
109

11-
/**
12-
* Creates a new ChatService instance.
13-
* @param baseUrl - The base URL for the llama.cpp server API. Defaults to 'http://localhost:8080'.
14-
*/
15-
constructor(baseUrl = import.meta.env.VITE_BASE_URL || 'http://localhost:8080') {
16-
this.baseUrl = baseUrl;
17-
}
18-
1910
/**
2011
* Sends a chat completion request to the llama.cpp server.
2112
* Supports both streaming and non-streaming responses with comprehensive parameter configuration.
@@ -97,7 +88,7 @@ export class ChatService {
9788
}
9889

9990
try {
100-
const response = await fetch(`${this.baseUrl}/v1/chat/completions`, {
91+
const response = await fetch(`/v1/chat/completions`, {
10192
method: 'POST',
10293
headers: {
10394
'Content-Type': 'application/json'
@@ -427,7 +418,7 @@ export class ChatService {
427418
*/
428419
static async getServerProps(): Promise<ApiLlamaCppServerProps> {
429420
try {
430-
const response = await fetch(`${import.meta.env.VITE_BASE_URL}/props`, {
421+
const response = await fetch(`/props`, {
431422
headers: {
432423
'Content-Type': 'application/json'
433424
}

tools/server/webui/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export default defineConfig({
100100
proxy: {
101101
'/v1': 'http://localhost:8080',
102102
'/props': 'http://localhost:8080',
103+
'/slots': 'http://localhost:8080',
103104
},
104105
headers: {
105106
'Cross-Origin-Embedder-Policy': 'require-corp',

0 commit comments

Comments
 (0)