Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
harishmohanraj committed Apr 16, 2024
1 parent 6569d04 commit 84966d3
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/main.wasp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ action updateUserById {
entities: [User]
}

action getModels {
fn: import { getModels } from "@src/server/actions.js",
entities: []
}

// 📚 Queries

Expand Down
1 change: 0 additions & 1 deletion app/src/client/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export default function App({ children }: { children: ReactNode }) {

useEffect(() => {
if (user) {
console.log('user', user);
if (!user.isSignUpComplete) {
if (user.hasAcceptedTos) {
updateCurrentUser({
Expand Down
39 changes: 38 additions & 1 deletion app/src/client/app/ModelsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,43 @@
import { useState } from 'react';
import CustomLayout from './layout/CustomLayout';
import CustomBreadcrumb from '../components/CustomBreadcrumb';
import Button from '../components/Button';
import { getModels } from 'wasp/client/operations';

interface JsonSchemaProperty {
default?: string;
description: string;
enum?: string[];
title: string;
type: string;
const?: string;
format?: string;
maxLength?: number;
minLength?: number;
}

interface JsonSchema {
properties: Record<string, JsonSchemaProperty>;
required: string[];
title: string;
type: string;
}

interface Schema {
name: string;
json_schema: JsonSchema;
}

interface ModelSchema {
schemas: Schema[];
}

const ModelsPage = () => {
const [modelsSchema, setModelsSchema] = useState<ModelSchema | null>(null);
const logout = async () => {
const response = await getModels();
setModelsSchema(response);
};
return (
<CustomLayout>
<CustomBreadcrumb pageName='Models' />
Expand All @@ -12,7 +48,8 @@ const ModelsPage = () => {
className='flex-col flex items-start justify-between p-6 gap-3 w-full'
style={{ width: '1000px', height: '600px' }}
>
<span className='text-sm font-medium text-airt-primary'>Some content goes here...</span>
<Button onClick={logout} label='Add Model' />
<p>{modelsSchema?.schemas.map((schema: any) => schema.name)}</p>
</div>
</div>
</div>
Expand Down
33 changes: 32 additions & 1 deletion app/src/server/actions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { type User } from 'wasp/entities';
import { HttpError } from 'wasp/server';
import { type StripePayment, type UpdateCurrentUser, type UpdateUserById } from 'wasp/server/operations';
import {
type StripePayment,
type UpdateCurrentUser,
type UpdateUserById,
type GetModels,
} from 'wasp/server/operations';
import Stripe from 'stripe';
import type { StripePaymentResult } from '../shared/types';
import { fetchStripeCustomer, createStripeCheckoutSession } from './payments/stripeUtils.js';
import { TierIds } from '../shared/constants.js';

const FASTAGENCY_SERVER_URL = process.env.FASTAGENCY_SERVER_URL || 'http://127.0.0.1:8000';

export const stripePayment: StripePayment<string, StripePaymentResult> = async (tier, context) => {
if (!context.user || !context.user.email) {
throw new HttpError(401);
Expand Down Expand Up @@ -82,3 +89,27 @@ export const updateCurrentUser: UpdateCurrentUser<Partial<User>, User> = async (
data: user,
});
};

export const getModels: GetModels<void, any> = async (user, context) => {
if (!context.user) {
throw new HttpError(401);
}

try {
const response = await fetch(`${FASTAGENCY_SERVER_URL}/models/llms/schemas`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' },
});
const json: any = (await response.json()) as { detail?: string }; // Parse JSON once

if (!response.ok) {
const errorMsg = json.detail || `HTTP error with status code ${response.status}`;
console.error('Server Error:', errorMsg);
throw new Error(errorMsg);
}

return json;
} catch (error: any) {
throw new HttpError(500, error.message);
}
};

0 comments on commit 84966d3

Please sign in to comment.