Skip to content

Commit

Permalink
thread
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelgj committed Oct 9, 2024
1 parent f9a14a8 commit 81b1054
Show file tree
Hide file tree
Showing 10 changed files with 478 additions and 450 deletions.
2 changes: 1 addition & 1 deletion js/ai/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ export async function generate<
config: {
...resolvedModel.config,
version: resolvedModel.version,
...resolvedOptions.config
...resolvedOptions.config,
},
output: resolvedOptions.output && {
format: resolvedOptions.output.format,
Expand Down
2 changes: 1 addition & 1 deletion js/ai/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ export interface ModelReference<CustomOptions extends z.ZodTypeAny> {
configSchema?: CustomOptions;
info?: ModelInfo;
version?: string;
config?: z.infer<CustomOptions>,
config?: z.infer<CustomOptions>;
}

/** Cretes a model reference. */
Expand Down
60 changes: 29 additions & 31 deletions js/genkit/src/genkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
retrieve,
RetrieverParams,
ToolAction,
ToolConfig
ToolConfig,
} from '@genkit-ai/ai';
import {
CallableFlow,
Expand Down Expand Up @@ -84,7 +84,6 @@ import {
} from './model.js';
import { lookupAction, Registry, runWithRegistry } from './registry.js';
import {
BaseGenerateOptions,
Environment,
getCurrentSession,
Session,
Expand Down Expand Up @@ -700,43 +699,42 @@ export class Genkit {

chat<S extends z.ZodTypeAny = z.ZodTypeAny>(
options?: SessionOptions<S>
): Session<S>;

chat<S extends z.ZodTypeAny = z.ZodTypeAny>(
requestBase: BaseGenerateOptions,
options?: SessionOptions<S>
): Session<S>;

chat<S extends z.ZodTypeAny = z.ZodTypeAny>(
requestBaseOrOpts?: SessionOptions<S> | BaseGenerateOptions,
maybeOptions?: SessionOptions<S>
): Session<S> {
// parse overloaded args
let baseGenerateOptions: BaseGenerateOptions | undefined = undefined;
let options: SessionOptions<S> | undefined = undefined;
if (maybeOptions !== undefined) {
options = maybeOptions;
baseGenerateOptions = requestBaseOrOpts as BaseGenerateOptions;
} else if (requestBaseOrOpts !== undefined) {
if (
(requestBaseOrOpts as SessionOptions<S>).state ||
(requestBaseOrOpts as SessionOptions<S>).store ||
(requestBaseOrOpts as SessionOptions<S>).schema
) {
options = requestBaseOrOpts as SessionOptions<S>;
} else {
baseGenerateOptions = requestBaseOrOpts as BaseGenerateOptions;
return new Session(
this,
{
...options,
},
{
sessionData: {
state: options?.state,
},
stateSchema: options?.stateSchema,
store: options?.store,
}
}
);
}

async loadChat<S extends z.ZodTypeAny = z.ZodTypeAny>(
sessionId: string,
options: SessionOptions<S>
): Promise<Session<S>> {
if (!options.store) {
throw new Error('options.store is required for loading chat sessions');
}
const sessionData = await options.store.get(sessionId);
if (!sessionData) {
throw new Error(`chat session ${sessionId} not found`);
}
return new Session(
this,
{
...baseGenerateOptions,
...options,
},
{
state: options?.state,
schema: options?.schema,
id: sessionId,
sessionData,
stateSchema: options?.stateSchema,
store: options?.store,
}
);
Expand Down
Loading

0 comments on commit 81b1054

Please sign in to comment.