Skip to content

Commit

Permalink
fix: use correct type for proxy request
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-lg committed Dec 4, 2023
1 parent adfc70f commit cda5fa2
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import type { CreateChatCompletionRequest, CreateChatCompletionResponse, ErrorResponse } from 'openai-edge'
import type { CreateChatCompletionResponse, ErrorResponse } from 'openai-edge'
import { TransformStream } from '@web-std/stream'
import type { CursiveAskOptionsWithMessages, CursiveHook, CursiveHooks, CursiveSetupOptions, CursiveStreamDelta } from './types'
import type { TSchema } from '@sinclair/typebox'
import type { CursiveAskOptions, CursiveAskOptionsWithMessages, CursiveHook, CursiveHooks, CursiveSetupOptions, CursiveStreamDelta } from './types'
import { useCursive } from './cursive'
import { randomId } from './util'
import { TSchema } from '@sinclair/typebox'

interface CursiveProxyOptions {
stream?: {
encodeValues?: boolean
}
}

export type CursiveProxyRequest = CreateChatCompletionRequest & {
export type CursiveProxyRequest = CursiveAskOptions & {
schema?: Record<string, any>
}

type CursiveProxy = <R extends CursiveProxyRequest>(request: R) => Promise<CreateChatCompletionResponse | ReadableStream<any> | ErrorResponse>


export function createCursiveProxy(options: CursiveSetupOptions & CursiveProxyOptions = {}) {
const cursive = useCursive(options)

Expand All @@ -38,9 +37,9 @@ export function createCursiveProxy(options: CursiveSetupOptions & CursiveProxyOp
}
}

async function handleRequest<T extends TSchema | undefined = undefined>(request: CreateChatCompletionRequest, cursive: ReturnType<typeof useCursive>) {
async function handleRequest<T extends TSchema | undefined = undefined>(request: CursiveAskOptions<T>, cursive: ReturnType<typeof useCursive>) {
const answer = await cursive.ask(
request as CursiveAskOptionsWithMessages<T>,
request,
)

if (answer.error) {
Expand Down

0 comments on commit cda5fa2

Please sign in to comment.