ai ollama backend

This commit is contained in:
Patrick_Pluto 2024-09-18 11:52:40 +02:00
parent 091a37cb57
commit a7f89058b0
3 changed files with 34 additions and 5 deletions

12
app/backend/ai_api.ts Normal file
View file

@ -0,0 +1,12 @@
import ollama from 'ollama'
async function name(model: string, prompt: string, system: string,) {
var message = [{ role: 'user', content: prompt }, { role: 'system', content: system }]
var response = await ollama.chat({ model: model, messages: message, stream: true })
for await (const part of response) {
process.stdout.write(part.message.content)
}
}

16
package-lock.json generated
View file

@ -9,6 +9,7 @@
"version": "0.1.0",
"dependencies": {
"next": "14.2.12",
"ollama": "^0.5.9",
"react": "^18",
"react-dom": "^18"
},
@ -3703,6 +3704,15 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/ollama": {
"version": "0.5.9",
"resolved": "https://registry.npmjs.org/ollama/-/ollama-0.5.9.tgz",
"integrity": "sha512-F/KZuDRC+ZsVCuMvcOYuQ6zj42/idzCkkuknGyyGVmNStMZ/sU3jQpvhnl4SyC0+zBzLiKNZJnJeuPFuieWZvQ==",
"license": "MIT",
"dependencies": {
"whatwg-fetch": "^3.6.20"
}
},
"node_modules/once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
@ -5061,6 +5071,12 @@
"dev": true,
"license": "MIT"
},
"node_modules/whatwg-fetch": {
"version": "3.6.20",
"resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.20.tgz",
"integrity": "sha512-EqhiFU6daOA8kpjOWTL0olhVOF3i7OrFzSYiGsEMB8GcXS+RrzauAERX65xMeNWVqxA6HXH2m69Z9LaKKdisfg==",
"license": "MIT"
},
"node_modules/which": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",

View file

@ -9,18 +9,19 @@
"lint": "next lint"
},
"dependencies": {
"next": "14.2.12",
"ollama": "^0.5.9",
"react": "^18",
"react-dom": "^18",
"next": "14.2.12"
"react-dom": "^18"
},
"devDependencies": {
"typescript": "^5",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.2.12",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"eslint": "^8",
"eslint-config-next": "14.2.12"
"typescript": "^5"
}
}