Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/commands/changelog/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import { logSuccess } from '../../lib/ui/logSuccess'
import { getDiffForCommit } from '../../lib/simple-git/getDiffForCommit'
import { getDiffForBranch } from '../../lib/simple-git/getDiffForBranch'
import {
ChangelogArgv,
ChangelogOptions,
ChangelogResponseSchema
ChangelogArgv,
ChangelogOptions,
ChangelogResponse,
ChangelogResponseSchema,
} from './config'
import { CHANGELOG_PROMPT } from './prompt'

Expand Down Expand Up @@ -161,7 +162,8 @@ export const handler: CommandHandler<ChangelogArgv> = async (argv, logger) => {
factory,
parser,
agent: async (context, options) => {
const parser = createSchemaParser(ChangelogResponseSchema, llm)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const parser: any = createSchemaParser(ChangelogResponseSchema, llm)

const prompt = getPrompt({
template: options.prompt,
Expand All @@ -181,7 +183,7 @@ export const handler: CommandHandler<ChangelogArgv> = async (argv, logger) => {
? 'At the end of each item, attribute the author and include a reference to the commit hash, like this: `by @author_name (f6dbe61)`. Use the first 7 characters of the hash.'
: 'At the end of each item, include a reference to the commit hash, like this: `(f6dbe61)`. Use the first 7 characters of the hash.'

const changelog = await executeChain({
const changelog = await executeChain<ChangelogResponse>({
llm,
prompt,
variables: {
Expand Down
5 changes: 3 additions & 2 deletions src/commands/recap/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,10 @@ export const handler: CommandHandler<RecapArgv> = async (argv, logger) => {
})

try {
const parser = createSchemaParser(RecapLlmResponseSchema, llm)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const parser: any = createSchemaParser(RecapLlmResponseSchema, llm)

const response = await executeChain({
const response = await executeChain<{ title: string; summary: string }>({
llm,
prompt,
variables: {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/review/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ export const handler: CommandHandler<ReviewArgv> = async (argv, logger) => {
factory,
parser,
agent: async (context, options) => {
const parser = createSchemaParser(ReviewFeedbackResponseSchema, llm)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const parser: any = createSchemaParser(ReviewFeedbackResponseSchema, llm)

const formatInstructions =
"Respond with a valid JSON object, containing four fields:'title' a string, 'summary' a short summary of the problem (include line number if big file), 'severity' a numeric enum up to ten, 'category' an enum string, and 'filePath' a relative filepath to file as string."
Expand Down
11 changes: 7 additions & 4 deletions src/lib/langchain/utils/createSchemaParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ export interface SchemaParserOptions {
* @returns StructuredOutputParser configured with the provided schema
* @throws LangChainExecutionError if parser creation fails
*/
export function createSchemaParser<S extends z.ZodType>(
schema: S,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function createSchemaParser(
schema: z.ZodType,
llm: ReturnType<typeof getLlm>,
options: SchemaParserOptions = {}
): StructuredOutputParser<S> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): any {
validateRequired(schema, 'schema', 'createSchemaParser')
validateRequired(llm, 'llm', 'createSchemaParser')
validateRequired(options, 'options', 'createSchemaParser')
Expand Down Expand Up @@ -52,7 +54,8 @@ export function createSchemaParser<S extends z.ZodType>(
}

try {
return StructuredOutputParser.fromZodSchema(schema)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return StructuredOutputParser.fromZodSchema(schema as any)
} catch (error) {
handleLangChainError(error, 'createSchemaParser: Failed to create schema parser', {
schemaName: schema.constructor.name,
Expand Down
8 changes: 4 additions & 4 deletions src/lib/langchain/utils/executeChain.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { BaseOutputParser } from '@langchain/core/output_parsers'
import { PromptTemplate } from '@langchain/core/prompts'
import { RunnableRetry } from '@langchain/core/runnables'
import { Runnable } from '@langchain/core/runnables'
import { handleLangChainError, isNetworkError } from '../errorHandler'
import { LangChainExecutionError, LangChainNetworkError } from '../errors'
import { validateRequired } from '../validation'
Expand All @@ -10,7 +9,8 @@ type ExecuteChainInput<T> = {
variables: Record<string, unknown>
prompt: PromptTemplate
llm: ReturnType<typeof getLlm>
parser: BaseOutputParser<T> | RunnableRetry
// eslint-disable-next-line @typescript-eslint/no-explicit-any
parser: Runnable<any, T>
/** Optional provider name for better error messages */
provider?: string
/** Optional endpoint URL for better error messages */
Expand Down Expand Up @@ -79,7 +79,7 @@ export const executeChain = async <T>({

try {
const chain = prompt.pipe(llm).pipe(parser)
const result = await chain.invoke(variables)
const result = (await chain.invoke(variables)) as T

if (result === null || result === undefined) {
throw new LangChainExecutionError(
Expand Down
3 changes: 2 additions & 1 deletion src/lib/langchain/utils/executeChainWithSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export async function executeChainWithSchema<T>(
...parserOptions
} = options

const parser = createSchemaParser(schema, llm, parserOptions)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const parser: any = createSchemaParser(schema, llm, parserOptions)

const operation = async (): Promise<T> => {
const result = await executeChain({
Expand Down
Loading