feat(follow-up/ollama): support ollama provider (#3795)

This commit is contained in:
Ahmed Rowaihi
2025-01-07 23:43:43 +03:00
committed by GitHub
parent 9a417bdc95
commit e429af139e
6 changed files with 199 additions and 124 deletions
+2 -1
View File
@@ -428,7 +428,8 @@ export enum FollowUpPromptProvider {
GOOGLE_GENAI = 'chatGoogleGenerativeAI',
MISTRALAI = 'chatMistralAI',
OPENAI = 'chatOpenAI',
GROQ = 'groqChat'
GROQ = 'groqChat',
OLLAMA = 'ollama'
}
export type FollowUpPromptProviderConfig = {
@@ -8,6 +8,7 @@ import { z } from 'zod'
import { PromptTemplate } from '@langchain/core/prompts'
import { StructuredOutputParser } from '@langchain/core/output_parsers'
import { ChatGroq } from '@langchain/groq'
import ollama from 'ollama'
const FollowUpPromptType = z
.object({
@@ -119,6 +120,38 @@ export const generateFollowUpPrompts = async (
const structuredResponse = await structuredLLM.invoke(followUpPromptsPrompt)
return structuredResponse
}
case FollowUpPromptProvider.OLLAMA: {
const response = await ollama.chat({
model: providerConfig.modelName,
messages: [
{
role: 'user',
content: followUpPromptsPrompt
}
],
format: {
type: 'object',
properties: {
questions: {
type: 'array',
items: {
type: 'string'
},
minItems: 3,
maxItems: 3,
description: 'Three follow-up questions based on the conversation history'
}
},
required: ['questions'],
additionalProperties: false
},
options: {
temperature: parseFloat(`${providerConfig.temperature}`)
}
})
const result = FollowUpPromptType.parse(JSON.parse(response.message.content))
return result
}
}
} else {
return undefined