Skip to content

Commit

Permalink
Update a missed imports
Browse files Browse the repository at this point in the history
  • Loading branch information
stwiname committed Oct 29, 2024
1 parent 0e5e74f commit 8efc559
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/tools/ragTool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IContext } from "../context/context.ts";
import type { IContext } from "../context/types.ts";
import { FunctionTool } from "./tool.ts";

export class RagTool extends FunctionTool {
Expand Down
32 changes: 15 additions & 17 deletions src/tools/tool.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import type { Tool } from "ollama";
import type { FunctionToolType } from "../project/project.ts";
import type { IContext } from "../context/context.ts";
import type { IContext } from "../context/types.ts";

type Parameters = Tool["function"]["parameters"];

// Utility type to map the "type" string to actual TypeScript types
type MapToTypes<T extends string> = T extends "string"
? string
: T extends "number"
? number
: T extends "boolean"
? boolean
type MapToTypes<T extends string> = T extends "string" ? string
: T extends "number" ? number
: T extends "boolean" ? boolean
: unknown;

// Extract required and optional parameters
Expand All @@ -21,15 +18,17 @@ type ExtractParameters<P extends Tool["function"]["parameters"]> = {
};

type RequiredParams<P extends Parameters> = {
[K in keyof ExtractParameters<P> as K extends P["required"][number]
? K
: never]: ExtractParameters<P>[K];
[
K in keyof ExtractParameters<P> as K extends P["required"][number] ? K
: never
]: ExtractParameters<P>[K];
};

type OptionalParams<P extends Parameters> = {
[K in keyof ExtractParameters<P> as K extends P["required"][number]
? never
: K]?: ExtractParameters<P>[K];
[
K in keyof ExtractParameters<P> as K extends P["required"][number] ? never
: K
]?: ExtractParameters<P>[K];
};

export type ITool<P extends Parameters = Parameters> = FunctionToolType & {
Expand All @@ -38,15 +37,14 @@ export type ITool<P extends Parameters = Parameters> = FunctionToolType & {

// TODO map paramaters type to call args, it doesn't seem to be able to inferred with typescript without being explicit on the generic param
export abstract class FunctionTool<P extends Parameters = Parameters>
implements ITool<P>
{
implements ITool<P> {
name = this.constructor.name;

abstract parameters: P;
abstract description: string;
abstract call(
args: unknown /*RequiredParams<P> & OptionalParams<P>*/,
ctx: IContext
args: unknown, /*RequiredParams<P> & OptionalParams<P>*/
ctx: IContext,
): Promise<string | null>;

toTool(): Tool {
Expand Down

0 comments on commit 8efc559

Please sign in to comment.