Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
nekomeowww committed Jan 16, 2025
1 parent a6976ad commit 555b915
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 90 deletions.
4 changes: 2 additions & 2 deletions docs/components/ui/hover-border-gradient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export function HoverBorderGradient({
duration = 1,
...props
}: React.PropsWithChildren<
{
React.HTMLAttributes<HTMLElement> & {
as?: React.ElementType
className?: string
clockwise?: boolean
containerClassName?: string
duration?: number
} & React.HTMLAttributes<HTMLElement>
}
>) {
const [hovered, setHovered] = useState<boolean>(false)
const [direction, setDirection] = useState<Direction>('TOP')
Expand Down
2 changes: 1 addition & 1 deletion docs/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Config } from 'tailwindcss'

import { createPreset } from 'fumadocs-ui/tailwind-plugin'
import animate from 'tailwindcss-animate'
// @ts-expect-error missing types
import flattenColorPalette from 'tailwindcss/lib/util/flattenColorPalette'
import animate from 'tailwindcss-animate'

function addVariablesForColors({ addBase, theme }: any) {
const allColors = flattenColorPalette(theme('colors'))
Expand Down
2 changes: 1 addition & 1 deletion packages/embed/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { embed, embed as default, type EmbedOptions, type EmbedResponseUsage, type EmbedResult } from './utils/embed'
export { embed as default, embed, type EmbedOptions, type EmbedResponseUsage, type EmbedResult } from './utils/embed'
export { embedMany, type EmbedManyOptions, type EmbedManyResult } from './utils/embed-many'
2 changes: 1 addition & 1 deletion packages/embed/src/utils/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface EmbedResponse {
object: 'embedding'
}[]
model: string
object: 'list' | ({} & string)
object: 'list' | (string & {})
system_fingerprint?: string
usage: EmbedResponseUsage
}
Expand Down
32 changes: 16 additions & 16 deletions packages/generate-text/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@ export interface GenerateTextResponse {
usage: Usage
}

export interface ToolCall {
args: string
toolCallId: string
toolCallType: 'function'
toolName: string
}

export interface ToolResult {
args: Record<string, unknown>
result: string
toolCallId: string
toolName: string
}

export interface GenerateTextResult {
finishReason: FinishReason
steps: StepResult[]
Expand All @@ -64,12 +50,26 @@ export interface StepResult {
usage: Usage
}

/** @internal */
type RawGenerateTextTrampoline<T> = Promise<(() => RawGenerateTextTrampoline<T>) | T>
export interface ToolCall {
args: string
toolCallId: string
toolCallType: 'function'
toolName: string
}

export interface ToolResult {
args: Record<string, unknown>
result: string
toolCallId: string
toolName: string
}

/** @internal */
type RawGenerateText = (options: GenerateTextOptions) => RawGenerateTextTrampoline<GenerateTextResult>

/** @internal */
type RawGenerateTextTrampoline<T> = Promise<(() => RawGenerateTextTrampoline<T>) | T>

/** @internal */
const rawGenerateText: RawGenerateText = async (options: GenerateTextOptions) =>
await chat({
Expand Down
4 changes: 2 additions & 2 deletions packages/providers/src/providers/ollama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { generateCRO } from '../utils/generate-cro'

export const createOllama = (userOptions?: ProviderOptions<false>):
/** @see {@link https://ollama.com/search} */
ChatProvider<'gemma2' | 'llama3.1' | 'llama3.2' | 'llama3.2-vision' | 'llama3.3' | 'qwen2.5' | 'qwen2.5-coder' | 'qwq' | ({} & string)>
& EmbedProvider<'all-minilm' | 'mxbai-embed-large' | 'nomic-embed-text' | ({} & string)>
ChatProvider<'gemma2' | 'llama3.1' | 'llama3.2' | 'llama3.2-vision' | 'llama3.3' | 'qwen2.5' | 'qwen2.5-coder' | 'qwq' | (string & {})>
& EmbedProvider<'all-minilm' | 'mxbai-embed-large' | 'nomic-embed-text' | (string & {})>
& ModelProvider => {
const options: ProviderResult = {
...userOptions,
Expand Down
26 changes: 13 additions & 13 deletions packages/providers/src/types/provider.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import type { CommonRequestOptions } from '@xsai/shared'

/** T: required apiKey */
export type ProviderOptions<T extends boolean = false> =
T extends true
? Partial<Omit<ProviderResult, 'apiKey'>> & Required<Pick<ProviderResult, 'apiKey'>>
: Partial<ProviderResult>

export type ProviderResult = Omit<CommonRequestOptions, 'model'> & Partial<Pick<CommonRequestOptions, 'model'>>

export interface ChatProvider<T extends string = string> {
chat: (model: ({} & string) | T) => CommonRequestOptions
chat: (model: (string & {}) | T) => CommonRequestOptions
}

export interface EmbedProvider<T extends string = string> {
embed: (model: ({} & string) | T) => CommonRequestOptions
embed: (model: (string & {}) | T) => CommonRequestOptions
}

export interface ModelProvider {
model: () => ProviderResult
}

/** T: required apiKey */
export type ProviderOptions<T extends boolean = false> =
T extends true
? Partial<Omit<ProviderResult, 'apiKey'>> & Required<Pick<ProviderResult, 'apiKey'>>
: Partial<ProviderResult>

export type ProviderResult = Omit<CommonRequestOptions, 'model'> & Partial<Pick<CommonRequestOptions, 'model'>>

export interface SpeechProvider<T extends string = string, T2 = undefined> {
speech: T2 extends undefined
? (model: ({} & string) | T) => CommonRequestOptions
: (model: ({} & string) | T, extraOptions?: T2) => CommonRequestOptions & T2
? (model: (string & {}) | T) => CommonRequestOptions
: (model: (string & {}) | T, extraOptions?: T2) => CommonRequestOptions & T2
}

export interface TranscriptionProvider<T extends string = string> {
transcription: (model: ({} & string) | T) => CommonRequestOptions
transcription: (model: (string & {}) | T) => CommonRequestOptions
}
2 changes: 1 addition & 1 deletion packages/shared-chat/src/types/finish-reason.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type FinishReason = 'content_filter' | 'error' | 'length' | 'other' | 'stop' | 'tool-calls' | ({} & string)
export type FinishReason = 'content_filter' | 'error' | 'length' | 'other' | 'stop' | 'tool-calls' | (string & {})
32 changes: 16 additions & 16 deletions packages/shared-chat/src/types/message-part.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
export type Part =
| AudioPart
| ImagePart
| RefusalPart
| TextPart
export interface AudioBase64 {
/**
* Base64 encoded audio data.
*/
data: string
format: 'mp3' | 'wav'
}

export interface AudioPart extends CommonPart<'input_audio'> {
input_audio: AudioBase64
}

export interface CommonPart<T extends string> {
type: T
Expand All @@ -24,17 +30,11 @@ export interface ImageURLorBase64 {
url: string
}

export interface AudioPart extends CommonPart<'input_audio'> {
input_audio: AudioBase64
}

export interface AudioBase64 {
/**
* Base64 encoded audio data.
*/
data: string
format: 'mp3' | 'wav'
}
export type Part =
| AudioPart
| ImagePart
| RefusalPart
| TextPart

export interface RefusalPart extends CommonPart<'refusal'> {
refusal: string
Expand Down
38 changes: 19 additions & 19 deletions packages/shared-chat/src/types/message.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import type { AudioPart, ImagePart, Part, RefusalPart, TextPart } from './message-part'

type Optional<T, K extends keyof T> = Omit<T, K> & Pick<Partial<T>, K>
export interface AssistantMessage extends Optional<CommonMessage<'assistant', AssistantMessagePart>, 'content'> {
refusal?: null | string
tool_calls?: ToolCall[]
// TODO: audio
}

export type Message = AssistantMessage | SystemMessage | ToolMessage | UserMessage
export type AssistantMessagePart = RefusalPart | TextPart

export interface AssistantMessageResponse extends Omit<AssistantMessage, 'content'> {
content?: string
}

export interface CommonMessage<T extends string, P extends Part> {
content: Array<P> | string
name?: string
role: T
}

export type SystemMessagePart = TextPart
export type Message = AssistantMessage | SystemMessage | ToolMessage | UserMessage

export interface SystemMessage extends CommonMessage<'system', SystemMessagePart> {}

export type UserMessagePart = AudioPart | ImagePart | TextPart

export interface UserMessage extends CommonMessage<'user', UserMessagePart> { }

export type AssistantMessagePart = RefusalPart | TextPart
export type SystemMessagePart = TextPart

export interface ToolCall {
function: {
Expand All @@ -29,18 +33,14 @@ export interface ToolCall {
type: 'function'
}

export interface AssistantMessage extends Optional<CommonMessage<'assistant', AssistantMessagePart>, 'content'> {
refusal?: null | string
tool_calls?: ToolCall[]
// TODO: audio
}

export interface AssistantMessageResponse extends Omit<AssistantMessage, 'content'> {
content?: string
export interface ToolMessage extends Omit<CommonMessage<'tool', ToolMessagePart>, 'name'> {
tool_call_id: string
}

export type ToolMessagePart = TextPart

export interface ToolMessage extends Omit<CommonMessage<'tool', ToolMessagePart>, 'name'> {
tool_call_id: string
}
export interface UserMessage extends CommonMessage<'user', UserMessagePart> { }

export type UserMessagePart = AudioPart | ImagePart | TextPart

type Optional<T, K extends keyof T> = Omit<T, K> & Pick<Partial<T>, K>
36 changes: 18 additions & 18 deletions packages/stream-text/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ import {
type Usage,
} from '@xsai/shared-chat'

// TODO: improve chunk type
export interface ChunkResult {
choices: {
delta: {
content: string
role: 'assistant'
}
finish_reason?: FinishReason
index: number
}[]
created: number
id: string
model: string
object: 'chat.completion.chunk'
system_fingerprint: string
usage?: Usage
}

export interface StreamTextOptions extends ChatOptions {
onChunk?: (chunk: ChunkResult) => Promise<void> | void
/** if you want to disable stream, use `@xsai/generate-{text,object}` */
Expand All @@ -26,24 +44,6 @@ export interface StreamTextResult {
usage?: Usage
}

// TODO: improve chunk type
export interface ChunkResult {
choices: {
delta: {
content: string
role: 'assistant'
}
finish_reason?: FinishReason
index: number
}[]
created: number
id: string
model: string
object: 'chat.completion.chunk'
system_fingerprint: string
usage?: Usage
}

const chunkHeaderPrefix = 'data: '
const chunkErrorPrefix = `{"error":`

Expand Down

0 comments on commit 555b915

Please sign in to comment.