AI JS Update

This commit is contained in:
2024-09-14 17:16:51 -04:00
parent 3847781c65
commit 7bd191f27c
3 changed files with 56 additions and 1 deletions

View File

@@ -28,6 +28,7 @@
"dotenv": "^16.4.5", "dotenv": "^16.4.5",
"express": "^4.21.0", "express": "^4.21.0",
"mongoose": "^8.6.2", "mongoose": "^8.6.2",
"ms": "^2.1.3" "ms": "^2.1.3",
"ollama": "^0.5.9"
} }
} }

23
pnpm-lock.yaml generated
View File

@@ -8,6 +8,9 @@ importers:
.: .:
dependencies: dependencies:
'@propelauth/javascript':
specifier: ^2.0.17
version: 2.0.17
'@sveltejs/adapter-node': '@sveltejs/adapter-node':
specifier: ^5.2.2 specifier: ^5.2.2
version: 5.2.2(@sveltejs/kit@2.5.27(@sveltejs/vite-plugin-svelte@3.1.2(svelte@4.2.19)(vite@5.4.5))(svelte@4.2.19)(vite@5.4.5)) version: 5.2.2(@sveltejs/kit@2.5.27(@sveltejs/vite-plugin-svelte@3.1.2(svelte@4.2.19)(vite@5.4.5))(svelte@4.2.19)(vite@5.4.5))
@@ -32,6 +35,9 @@ importers:
ms: ms:
specifier: ^2.1.3 specifier: ^2.1.3
version: 2.1.3 version: 2.1.3
ollama:
specifier: ^0.5.9
version: 0.5.9
devDependencies: devDependencies:
'@sveltejs/adapter-auto': '@sveltejs/adapter-auto':
specifier: ^3.0.0 specifier: ^3.0.0
@@ -234,6 +240,9 @@ packages:
'@polka/url@1.0.0-next.25': '@polka/url@1.0.0-next.25':
resolution: {integrity: sha512-j7P6Rgr3mmtdkeDGTe0E/aYyWEWVtc5yFXtHCRHs28/jptDEWfaVOc5T7cblqy1XKPPfCxJc/8DwQ5YgLOZOVQ==} resolution: {integrity: sha512-j7P6Rgr3mmtdkeDGTe0E/aYyWEWVtc5yFXtHCRHs28/jptDEWfaVOc5T7cblqy1XKPPfCxJc/8DwQ5YgLOZOVQ==}
'@propelauth/javascript@2.0.17':
resolution: {integrity: sha512-oXnsNSaYPP5+6bhcC+ewhaai23LDO+Wng+63+eynYEDvbCzLWJa0EzpGZr/CCyeY33Q4iStAAng/sC15Pk5QMA==}
'@rollup/plugin-commonjs@26.0.1': '@rollup/plugin-commonjs@26.0.1':
resolution: {integrity: sha512-UnsKoZK6/aGIH6AdkptXhNvhaqftcjq3zZdT+LY5Ftms6JR06nADcDsYp5hTU9E2lbJUEOhdlY5J4DNTneM+jQ==} resolution: {integrity: sha512-UnsKoZK6/aGIH6AdkptXhNvhaqftcjq3zZdT+LY5Ftms6JR06nADcDsYp5hTU9E2lbJUEOhdlY5J4DNTneM+jQ==}
engines: {node: '>=16.0.0 || 14 >= 14.17'} engines: {node: '>=16.0.0 || 14 >= 14.17'}
@@ -886,6 +895,9 @@ packages:
resolution: {integrity: sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g==} resolution: {integrity: sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g==}
engines: {node: '>= 0.4'} engines: {node: '>= 0.4'}
ollama@0.5.9:
resolution: {integrity: sha512-F/KZuDRC+ZsVCuMvcOYuQ6zj42/idzCkkuknGyyGVmNStMZ/sU3jQpvhnl4SyC0+zBzLiKNZJnJeuPFuieWZvQ==}
on-finished@2.4.1: on-finished@2.4.1:
resolution: {integrity: sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==} resolution: {integrity: sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==}
engines: {node: '>= 0.8'} engines: {node: '>= 0.8'}
@@ -1141,6 +1153,9 @@ packages:
resolution: {integrity: sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==} resolution: {integrity: sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==}
engines: {node: '>=12'} engines: {node: '>=12'}
whatwg-fetch@3.6.20:
resolution: {integrity: sha512-EqhiFU6daOA8kpjOWTL0olhVOF3i7OrFzSYiGsEMB8GcXS+RrzauAERX65xMeNWVqxA6HXH2m69Z9LaKKdisfg==}
whatwg-url@13.0.0: whatwg-url@13.0.0:
resolution: {integrity: sha512-9WWbymnqj57+XEuqADHrCJ2eSXzn8WXIW/YSGaZtb2WKAInQ6CHfaUUcTyyver0p8BDg5StLQq8h1vtZuwmOig==} resolution: {integrity: sha512-9WWbymnqj57+XEuqADHrCJ2eSXzn8WXIW/YSGaZtb2WKAInQ6CHfaUUcTyyver0p8BDg5StLQq8h1vtZuwmOig==}
engines: {node: '>=16'} engines: {node: '>=16'}
@@ -1269,6 +1284,8 @@ snapshots:
'@polka/url@1.0.0-next.25': {} '@polka/url@1.0.0-next.25': {}
'@propelauth/javascript@2.0.17': {}
'@rollup/plugin-commonjs@26.0.1(rollup@4.21.3)': '@rollup/plugin-commonjs@26.0.1(rollup@4.21.3)':
dependencies: dependencies:
'@rollup/pluginutils': 5.1.0(rollup@4.21.3) '@rollup/pluginutils': 5.1.0(rollup@4.21.3)
@@ -1892,6 +1909,10 @@ snapshots:
object-inspect@1.13.2: {} object-inspect@1.13.2: {}
ollama@0.5.9:
dependencies:
whatwg-fetch: 3.6.20
on-finished@2.4.1: on-finished@2.4.1:
dependencies: dependencies:
ee-first: 1.1.1 ee-first: 1.1.1
@@ -2157,6 +2178,8 @@ snapshots:
webidl-conversions@7.0.0: {} webidl-conversions@7.0.0: {}
whatwg-fetch@3.6.20: {}
whatwg-url@13.0.0: whatwg-url@13.0.0:
dependencies: dependencies:
tr46: 4.1.1 tr46: 4.1.1

31
server/ai.js Normal file
View File

@@ -0,0 +1,31 @@
import {Ollama} from 'ollama'
const ollama = new Ollama({ host: '172.29.186.121:11434' })
const response = await ollama.chat({
model: 'llama3:latest',
messages: [{ role: 'user', content:
`Generate a recipe for blueberry muffins:
Format it in a json object like this and don't send any other text:
{
"name": "Blueberry Muffins",
"description": "A delicious and healthy blueberry muffin recipe",
"nutritional_information": {},
ingredients: [
{
"name": "flour",
"quantity": "2 cups"
}
],
instructions: [
"Preheat oven to 350 degrees"
]
}
`
}],
});
console.log(response)
console.log(response.message.content)