Skip to content

Commit

Permalink
time and ai
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhattin committed Nov 19, 2024
1 parent 20e31c4 commit 5678171
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/api/routers/ai/ai_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { z } from 'zod';

export const translation_out_schema = z
.object({
text: z.string().describe('The trnalstion text'),
text: z.string().describe('The translation text'),
shloka_num: z
.number()
.describe('The index of shlokas to be generated, use 0 for starting and -1 for ending.')
})
.array()
.describe('This array will contain the text and the index of the shlokas to be generated.');
.describe(
'This object will contain the translated text and the index of the shloka to be generated.'
);

export const text_models_enum = z.enum(['gpt-4o', 'claude-3.5-sonnet']);

Expand All @@ -24,7 +25,7 @@ export const sarga_translate_schema = {
.array()
}),
output: z.union([
z.object({ success: z.literal(true), translations: translation_out_schema }),
z.object({ success: z.literal(true), translations: translation_out_schema.array() }),
z.object({ success: z.literal(false) })
])
};
1 change: 0 additions & 1 deletion src/api/routers/ai/trigger_funcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { sarga_translate_schema } from '~/api/routers/ai/ai_types';
import { JWT_SECRET } from '~/tools/jwt.server';
import { jwtVerify, SignJWT } from 'jose';
import type { lang_list_type } from '~/tools/lang_list';
import prettyMilliseconds from 'pretty-ms';

auth.configure({
secretKey: env.TRIGGER_SECRET_KEY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import Icon from '~/tools/Icon.svelte';
import { get_result_from_trigger_run_id } from '~/tools/trigger';
import pretty_ms from 'pretty-ms';
import { OiStopwatch16 } from 'svelte-icons-pack/oi';
const query_client = useQueryClient();
const modal_store = getModalStore();
Expand Down Expand Up @@ -148,4 +149,9 @@
<option value={key} title={value[1]}>{value[0]}</option>
{/each}
</select>
{:else if $editing_status_on && $translate_sarga_mut.isSuccess}
<span class="ml-4 select-none text-xs text-stone-500 dark:text-stone-300">
<Icon src={OiStopwatch16} class="text-base" />
{pretty_ms($translate_sarga_mut.data.time_taken)}
</span>
{/if}
8 changes: 6 additions & 2 deletions src/trigger/ai/sarga_translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ export const translate_sarga = task({
'claude-3.5-sonnet': anthropic_text_model('claude-3-5-sonnet-latest')
}[model],
messages,
schema: z.object({ translations: translation_out_schema })
output: 'array',
schema: translation_out_schema,
schemaDescription:
'This should be an array of objects, each object containing the translation text and the index of the shloka to be generated.',
schemaName: 'ai_translations_text_schema'
});
return { ...response.object, success: true };
return { translations: response.object, success: true };
} catch (e) {
console.log(e);
return { success: false };
Expand Down

0 comments on commit 5678171

Please sign in to comment.