Skip to content

Commit

Permalink
feat(follow-up/ollama): support ollama provider (#3795)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedrowaihi authored Jan 7, 2025
1 parent 9a417bd commit e429af1
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 124 deletions.
1 change: 1 addition & 0 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"node-html-markdown": "^1.3.0",
"notion-to-md": "^3.1.1",
"object-hash": "^3.0.0",
"ollama": "^0.5.11",
"openai": "^4.57.3",
"pdf-parse": "^1.1.1",
"pdfjs-dist": "^3.7.107",
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ export enum FollowUpPromptProvider {
GOOGLE_GENAI = 'chatGoogleGenerativeAI',
MISTRALAI = 'chatMistralAI',
OPENAI = 'chatOpenAI',
GROQ = 'groqChat'
GROQ = 'groqChat',
OLLAMA = 'ollama'
}

export type FollowUpPromptProviderConfig = {
Expand Down
33 changes: 33 additions & 0 deletions packages/components/src/followUpPrompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions packages/ui/src/assets/images/ollama.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e429af1

Please sign in to comment.