feat: certificates, landing pages, ai tutor, website update, compliance
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { BaseApiWithErrors, classroomio } from '$lib/utils/services/api';
|
||||
import { snackbar } from '$features/ui/snackbar/store';
|
||||
import type { GenerateTextRequest } from '../utils/types';
|
||||
|
||||
export class TextGenerationApi extends BaseApiWithErrors {
|
||||
async generate(
|
||||
prompt: string,
|
||||
tone: string,
|
||||
format: 'plain' | 'html' = 'plain',
|
||||
context?: string,
|
||||
courseId?: string
|
||||
): Promise<string | null> {
|
||||
let generatedText: string | null = null;
|
||||
|
||||
await this.execute<GenerateTextRequest>({
|
||||
requestFn: () =>
|
||||
classroomio.agent['generate-text'].$post({
|
||||
json: { prompt, tone: tone as 'professional' | 'casual' | 'expert' | 'friendly', format, context, courseId }
|
||||
}),
|
||||
logContext: 'generating text',
|
||||
onSuccess: (response) => {
|
||||
generatedText = response.data.text;
|
||||
},
|
||||
onError: () => {
|
||||
snackbar.error('Failed to generate text. Please try again.');
|
||||
}
|
||||
});
|
||||
|
||||
return generatedText;
|
||||
}
|
||||
}
|
||||
|
||||
export const textGenerationApi = new TextGenerationApi();
|
||||
@@ -0,0 +1,22 @@
|
||||
<script lang="ts">
|
||||
import { AIGeneratePopover } from '@cio/ui/custom/ai-generate-popover';
|
||||
import { textGenerationApi } from '../api/text-generation.svelte';
|
||||
|
||||
interface Props {
|
||||
onInsert: (text: string) => void;
|
||||
context?: string;
|
||||
format?: 'plain' | 'html';
|
||||
courseId?: string;
|
||||
align?: 'start' | 'center' | 'end';
|
||||
}
|
||||
|
||||
let { onInsert, context, format = 'plain', courseId, align = 'right' }: Props = $props();
|
||||
</script>
|
||||
|
||||
<AIGeneratePopover
|
||||
{align}
|
||||
onGenerate={async (prompt, tone) => {
|
||||
const text = await textGenerationApi.generate(prompt, tone, format, context, courseId);
|
||||
if (text) onInsert(text);
|
||||
}}
|
||||
/>
|
||||
@@ -0,0 +1,4 @@
|
||||
import { classroomio, type InferResponseType } from '$lib/utils/services/api';
|
||||
|
||||
export type GenerateTextRequest = (typeof classroomio.agent)['generate-text']['$post'];
|
||||
export type GenerateTextSuccess = Extract<InferResponseType<GenerateTextRequest>, { success: true }>;
|
||||
Reference in New Issue
Block a user