Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion frontend/chat-ui/src/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || '';
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || '';
const API_KEY = import.meta.env.VITE_API_KEY || '';

async function request(method, path, body) {
Expand Down
3 changes: 0 additions & 3 deletions frontend/chat-ui/src/components/ChatWindow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import { useStore } from '../store';
import MessageBubble from './MessageBubble.jsx';
import { API_BASE_URL } from '../api';

const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || '';

export default function ChatWindow() {
const { state, dispatch } = useStore();
const bottomRef = useRef();
Expand All @@ -31,7 +29,6 @@ export default function ChatWindow() {
url.searchParams.set('api_key', apiKey);
}
const events = new EventSource(url.toString());
const events = new EventSource(`${API_BASE_URL}/stream/${state.currentConversation.id}`);

const handleToken = (e) => {
try {
Expand Down
1 change: 0 additions & 1 deletion frontend/chat-ui/src/components/InputBox.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useState, useRef } from 'react';
import { useStore } from '../store';
import { API_BASE_URL } from '../api';
import { post } from '../api';

export default function InputBox() {
Expand Down
21 changes: 4 additions & 17 deletions frontend/chat-ui/src/components/MessageActions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { useStore } from '../store';

/** @typedef {import('../types').Message} Message */

const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || '';
import { API_BASE_URL } from '../api';
import { post } from '../api';

/**
* Action buttons associated with a message.
Expand All @@ -24,13 +23,8 @@ export default function MessageActions({ message }) {
const regenerate = async () => {
if (!state.currentConversation) return;
try {
await fetch(`${API_BASE_URL}/messages/${state.currentConversation.id}/regenerate`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': import.meta.env.VITE_API_KEY,
},
body: JSON.stringify({ messageId: message.id }),
await post(`/messages/${state.currentConversation.id}/regenerate`, {
messageId: message.id,
});
} catch (e) {
console.error(e);
Expand All @@ -39,14 +33,7 @@ export default function MessageActions({ message }) {

const feedback = async (value) => {
try {
await fetch(`${API_BASE_URL}/feedback`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': import.meta.env.VITE_API_KEY,
},
body: JSON.stringify({ messageId: message.id, value }),
});
await post('/feedback', { messageId: message.id, value });
} catch (e) {
console.error(e);
}
Expand Down
10 changes: 0 additions & 10 deletions frontend/chat-ui/src/components/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import { useStore } from '../store';
* @typedef {import('../types').Message} Message
*/

const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || '';

import { API_BASE_URL } from '../api';
import { get, post } from '../api';

/**
Expand Down Expand Up @@ -56,13 +53,6 @@ export default function Sidebar() {
*/
const openConversation = async (c) => {
try {
const res = await fetch(`${API_BASE_URL}/messages/${c.id}`, {
headers: { 'x-api-key': import.meta.env.VITE_API_KEY },
});
const msgs = /** @type {Message[]} */ (await res.json());
dispatch({ type: 'SET_CURRENT_CONVERSATION', conversation: c });
dispatch({ type: 'SET_MESSAGES', messages: msgs });

const msgs = await get(`/messages/${c.id}`);
dispatch({ type: 'SET_CURRENT_CONVERSATION', conversation: c });
dispatch({ type: 'SET_MESSAGES', messages: msgs });
Expand Down
16 changes: 3 additions & 13 deletions frontend/chat-ui/src/components/TopBar.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react';
import { useStore } from '../store';
import { API_BASE_URL } from '../api';
import { put, del } from '../api';

export default function TopBar() {
const { state, dispatch } = useStore();
Expand All @@ -16,14 +16,7 @@ export default function TopBar() {
setTitle(t);
if (!state.currentConversation) return;
try {
await fetch(`${API_BASE_URL}/conversations/${state.currentConversation.id}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'x-api-key': import.meta.env.VITE_API_KEY,
},
body: JSON.stringify({ title: t }),
});
await put(`/conversations/${state.currentConversation.id}`, { title: t });
const updated = { ...state.currentConversation, title: t };
dispatch({ type: 'SET_CURRENT_CONVERSATION', conversation: updated });
dispatch({
Expand All @@ -38,10 +31,7 @@ export default function TopBar() {
const remove = async () => {
if (!state.currentConversation) return;
try {
await fetch(`${API_BASE_URL}/conversations/${state.currentConversation.id}`, {
method: 'DELETE',
headers: { 'x-api-key': import.meta.env.VITE_API_KEY },
});
await del(`/conversations/${state.currentConversation.id}`);
dispatch({
type: 'SET_CONVERSATIONS',
conversations: state.conversations.filter((c) => c.id !== state.currentConversation.id),
Expand Down