Skip to content

Commit

Permalink
feat: speech connected
Browse files Browse the repository at this point in the history
  • Loading branch information
nekomeowww committed Jan 5, 2025
1 parent 33768dc commit 3385b8b
Show file tree
Hide file tree
Showing 8 changed files with 523 additions and 95 deletions.
1 change: 1 addition & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ words:
- intlify
- Kawaii
- kwaa
- libsodium
- live2dcubismcore
- live2dcubismframework
- Llmmarker
Expand Down
1 change: 1 addition & 0 deletions packages/stage/src/stores/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { AssistantMessage, Message } from '@xsai/shared-chat'
import { defineStore, storeToRefs } from 'pinia'
import { ref } from 'vue'
import { useI18n } from 'vue-i18n'

import { useLlmmarkerParser } from '../composables/llmmarkerParser'
import SystemPromptV2 from '../constants/prompts/system-v2'
import { useLLM } from '../stores/llm'
Expand Down
9 changes: 0 additions & 9 deletions packages/stage/src/typed-router.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,5 @@ declare module 'vue-router/auto-routes' {
* Route name map generated by unplugin-vue-router
*/
export interface RouteNamedMap {
'/': RouteRecordInfo<'/', '/', Record<never, never>, Record<never, never>>,
'/[...all]': RouteRecordInfo<'/[...all]', '/:all(.*)', { all: ParamValue<true> }, { all: ParamValue<false> }>,
'/audio': RouteRecordInfo<'/audio', '/audio', Record<never, never>, Record<never, never>>,
'/devtools/image': RouteRecordInfo<'/devtools/image', '/devtools/image', Record<never, never>, Record<never, never>>,
'/queue': RouteRecordInfo<'/queue', '/queue', Record<never, never>, Record<never, never>>,
'/test/filter-message': RouteRecordInfo<'/test/filter-message', '/test/filter-message', Record<never, never>, Record<never, never>>,
'/test/queues/delays': RouteRecordInfo<'/test/queues/delays', '/test/queues/delays', Record<never, never>, Record<never, never>>,
'/test/queues/emotions': RouteRecordInfo<'/test/queues/emotions', '/test/queues/emotions', Record<never, never>, Record<never, never>>,
'/test/queues/messages': RouteRecordInfo<'/test/queues/messages', '/test/queues/messages', Record<never, never>, Record<never, never>>,
}
}
16 changes: 8 additions & 8 deletions packages/stage/src/utils/jsonFormat.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Infer, Schema } from '@typeschema/valibot'
import type { CommonProviderOptions } from '@xsai/providers'
import type { ProviderOptions } from '@xsai/providers'
import type { Message } from '@xsai/shared-chat'

import { toJSONSchema, validate } from '@typeschema/valibot'
import { generateText } from '@xsai/generate-text'
import { user } from '@xsai/shared-chat'
import { message } from '@xsai/shared-chat'

type SchemaOrString<S extends Schema | undefined | unknown> = S extends unknown ? string : S extends Schema ? Infer<S> : never

async function parseJSONFormat<S extends Schema, R extends SchemaOrString<S>>(content: string, options: { messages: Message[], apiKey?: string, baseURL: string, model: string } & CommonProviderOptions, schema?: S, erroredValue?: string, errorMessage?: string): Promise<R> {
async function parseJSONFormat<S extends Schema, R extends SchemaOrString<S>>(content: string, options: { messages: Message[], apiKey?: string, baseURL: string, model: string } & ProviderOptions, schema?: S, erroredValue?: string, errorMessage?: string): Promise<R> {
if (!schema)
return content as unknown as R

Expand All @@ -26,7 +26,7 @@ async function parseJSONFormat<S extends Schema, R extends SchemaOrString<S>>(co
catch (parseError) {
console.error('Error parsing JSON:', parseError, content)

options.messages.push(user(`
options.messages.push(message.user(`
${correctionPrompt}The response was not valid JSON:
${JSON.stringify(content)}
Expand All @@ -45,7 +45,7 @@ ${JSON.stringify(await toJSONSchema(schema))}`))
}

console.error('Schema validation failed:', validation.issues, parsedContent)
options.messages.push(user(`
options.messages.push(message.user(`
${correctionPrompt}The response failed schema validation:
${JSON.stringify(parsedContent)}
Expand All @@ -67,9 +67,9 @@ ${JSON.stringify(await toJSONSchema(schema))}`))
/**
* Processes user input and generates LLM response along with thought nodes.
*/
async function call<S extends Schema, R extends SchemaOrString<S>>(options: { messages: Message[], apiKey?: string, baseURL: string, model: string } & CommonProviderOptions, schema?: S): Promise<R> {
async function call<S extends Schema, R extends SchemaOrString<S>>(options: { messages: Message[], apiKey?: string, baseURL: string, model: string } & ProviderOptions, schema?: S): Promise<R> {
if (schema != null) {
options.messages.push(user(`Your response must follow the following schema:
options.messages.push(message.user(`Your response must follow the following schema:
${JSON.stringify(await toJSONSchema(schema))}
Without any extra markups such as \`\`\` in markdown, or descriptions.`))
Expand All @@ -85,6 +85,6 @@ Without any extra markups such as \`\`\` in markdown, or descriptions.`))
return await parseJSONFormat<S, R>(response.text || '', options, schema)
}

export async function generateObject<S extends Schema, R extends SchemaOrString<S>>(options: { messages: Message[], model: string, apiKey?: string, baseURL: string } & CommonProviderOptions, schema?: S): Promise<R> {
export async function generateObject<S extends Schema, R extends SchemaOrString<S>>(options: { messages: Message[], model: string, apiKey?: string, baseURL: string } & ProviderOptions, schema?: S): Promise<R> {
return await call(options, schema)
}
Loading

0 comments on commit 3385b8b

Please sign in to comment.