Compare commits
2 Commits
0b323ed537
...
feature/ch
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a6cf113c8 | |||
| 48d734516a |
@@ -1,13 +1,4 @@
|
|||||||
import {
|
import { Body, Controller, HttpException, Logger, Post, Req, Res, UseGuards } from "@nestjs/common";
|
||||||
Body,
|
|
||||||
Controller,
|
|
||||||
HttpException,
|
|
||||||
Logger,
|
|
||||||
Post,
|
|
||||||
Req,
|
|
||||||
Res,
|
|
||||||
UseGuards,
|
|
||||||
} from "@nestjs/common";
|
|
||||||
import type { Response } from "express";
|
import type { Response } from "express";
|
||||||
import { AuthGuard } from "../auth/guards/auth.guard";
|
import { AuthGuard } from "../auth/guards/auth.guard";
|
||||||
import type { MaybeAuthenticatedRequest } from "../auth/types/better-auth-request.interface";
|
import type { MaybeAuthenticatedRequest } from "../auth/types/better-auth-request.interface";
|
||||||
|
|||||||
@@ -90,10 +90,7 @@ export class ChatProxyService {
|
|||||||
* - GUEST_LLM_API_KEY: API key (optional, for cloud providers)
|
* - GUEST_LLM_API_KEY: API key (optional, for cloud providers)
|
||||||
* - GUEST_LLM_MODEL: Model name to use
|
* - GUEST_LLM_MODEL: Model name to use
|
||||||
*/
|
*/
|
||||||
async proxyGuestChat(
|
async proxyGuestChat(messages: ChatMessage[], signal?: AbortSignal): Promise<Response> {
|
||||||
messages: ChatMessage[],
|
|
||||||
signal?: AbortSignal
|
|
||||||
): Promise<Response> {
|
|
||||||
const llmUrl = this.config.get<string>("GUEST_LLM_URL") ?? DEFAULT_GUEST_LLM_URL;
|
const llmUrl = this.config.get<string>("GUEST_LLM_URL") ?? DEFAULT_GUEST_LLM_URL;
|
||||||
const llmApiKey = this.config.get<string>("GUEST_LLM_API_KEY");
|
const llmApiKey = this.config.get<string>("GUEST_LLM_API_KEY");
|
||||||
const llmModel = this.config.get<string>("GUEST_LLM_MODEL") ?? DEFAULT_GUEST_LLM_MODEL;
|
const llmModel = this.config.get<string>("GUEST_LLM_MODEL") ?? DEFAULT_GUEST_LLM_MODEL;
|
||||||
@@ -103,7 +100,7 @@ export class ChatProxyService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (llmApiKey) {
|
if (llmApiKey) {
|
||||||
headers["Authorization"] = `Bearer ${llmApiKey}`;
|
headers.Authorization = `Bearer ${llmApiKey}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestInit: RequestInit = {
|
const requestInit: RequestInit = {
|
||||||
|
|||||||
@@ -280,13 +280,16 @@ export function useChat(options: UseChatOptions = {}): UseChatReturn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Streaming failed - check if auth error, try guest mode
|
// Streaming failed - check if auth error, try guest mode
|
||||||
const isAuthError = err instanceof Error &&
|
const isAuthError =
|
||||||
(err.message.includes("403") || err.message.includes("401") ||
|
err instanceof Error &&
|
||||||
err.message.includes("auth") || err.message.includes("Forbidden"));
|
(err.message.includes("403") ||
|
||||||
|
err.message.includes("401") ||
|
||||||
|
err.message.includes("auth") ||
|
||||||
|
err.message.includes("Forbidden"));
|
||||||
|
|
||||||
if (isAuthError) {
|
if (isAuthError) {
|
||||||
console.warn("Auth failed, trying guest chat mode");
|
console.warn("Auth failed, trying guest chat mode");
|
||||||
|
|
||||||
// Try guest chat streaming
|
// Try guest chat streaming
|
||||||
try {
|
try {
|
||||||
await new Promise<void>((guestResolve, guestReject) => {
|
await new Promise<void>((guestResolve, guestReject) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user