From a7f89058b05adf84ed4e1bfff5282a48b591655d Mon Sep 17 00:00:00 2001 From: Patrick_Pluto Date: Wed, 18 Sep 2024 11:52:40 +0200 Subject: [PATCH] ai ollama backend --- app/backend/ai_api.ts | 12 ++++++++++++ package-lock.json | 16 ++++++++++++++++ package.json | 11 ++++++----- 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 app/backend/ai_api.ts diff --git a/app/backend/ai_api.ts b/app/backend/ai_api.ts new file mode 100644 index 0000000..5cafa54 --- /dev/null +++ b/app/backend/ai_api.ts @@ -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) + } +} + + + diff --git a/package-lock.json b/package-lock.json index 6b43faa..ec2f85c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index be692b2..2aea3c5 100644 --- a/package.json +++ b/package.json @@ -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" } }