Skip to content

Commit

Permalink
refactpr base url (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredfrancis authored Jan 25, 2025
1 parent 5dced40 commit e7f6c8d
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion frontend/app/admin/settings/integrations/ChatWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const ChatWidget: React.FC<ChatWidgetProps> = ({ integration, onUpdate }) => {

const widgetCode = `<script type="text/javascript">
!function(win,doc){"use strict";var script_loader=()=>{try
{var head=doc.head||doc.getElementsByTagName("head")[0],script=doc.createElement("script");script.setAttribute("type","text/javascript"),script.setAttribute("src","${process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:8080'}/static/widget/script.js"),head.appendChild(script)}
{var head=doc.head||doc.getElementsByTagName("head")[0],script=doc.createElement("script");script.setAttribute("type","text/javascript"),script.setAttribute("src","https://alfredfrancis.in/ai-chatbot-framework/app/static/widget/script.js"),head.appendChild(script)}
catch(e){}};win.chat_context={"username":"John"},win.iky_base_url="${process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:8080'}",script_loader()}(window,document);
</script>`;

Expand Down
2 changes: 1 addition & 1 deletion frontend/app/services/agents.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:8080/admin/';
import { API_BASE_URL } from "./base";

interface AgentConfig {
confidence_threshold: number
Expand Down
1 change: 1 addition & 0 deletions frontend/app/services/base.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:8080/admin/';
4 changes: 2 additions & 2 deletions frontend/app/services/chat.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:8080/';
import { API_BASE_URL } from "./base";

interface UserMessage {
thread_id: string;
Expand Down Expand Up @@ -49,7 +49,7 @@ interface ChatState {


export const converse = async (userMessage: UserMessage): Promise<ChatState> => {
const response = await fetch(`${API_BASE_URL}admin/test/chat`, {
const response = await fetch(`${API_BASE_URL}test/chat`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(userMessage),
Expand Down
3 changes: 1 addition & 2 deletions frontend/app/services/entities.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { EntityModel } from './training';

const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:8080/admin/';
import { API_BASE_URL } from "./base";

export const getEntities = async (): Promise<EntityModel[]> => {
const response = await fetch(`${API_BASE_URL}entities/`);
Expand Down
8 changes: 4 additions & 4 deletions frontend/app/services/integrations.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:8080';
import { API_BASE_URL } from "./base";

export interface FacebookSettings {
verify: string;
Expand All @@ -22,15 +22,15 @@ export interface IntegrationDetails<T> extends Integration {
}

export async function listIntegrations(): Promise<Integration[]> {
const response = await fetch(`${baseUrl}/admin/integrations/`);
const response = await fetch(`${API_BASE_URL}integrations/`);
if (!response.ok) {
throw new Error('Failed to fetch integrations');
}
return response.json();
}

export async function getIntegration<T>(integrationID: string): Promise<IntegrationDetails<T>> {
const response = await fetch(`${baseUrl}/admin/integrations/${integrationID}`);
const response = await fetch(`${API_BASE_URL}integrations/${integrationID}`);
if (!response.ok) {
throw new Error('Failed to fetch integration');
}
Expand All @@ -44,7 +44,7 @@ export async function updateIntegration<T>(
settings: T;
}
): Promise<IntegrationDetails<T>> {
const response = await fetch(`${baseUrl}/admin/integrations/${integrationID}`, {
const response = await fetch(`${API_BASE_URL}integrations/${integrationID}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/services/intents.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { API_BASE_URL } from "./base";
import type { IntentModel } from './training';

const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:8080/admin/';

export const getIntents = async (): Promise<IntentModel[]> => {
const response = await fetch(`${API_BASE_URL}intents/`);
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/services/training.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { API_BASE_URL } from "./base";

interface Parameter {
name: string;
value?: string;
Expand Down Expand Up @@ -61,8 +63,6 @@ interface IntentModel {
};
}

const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:8080/admin/';

export const saveTrainingData = async (intentId: string, data: Example[]) => {
const response = await fetch(`${API_BASE_URL}train/${intentId}/data`, {
method: 'POST',
Expand Down

0 comments on commit e7f6c8d

Please sign in to comment.