-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
225 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
publish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# @novachat/plugin-openai | ||
|
||
NovaChat OpenAI Plugin. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "@novachat/plugin-ollama", | ||
"private": true, | ||
"keywords": [ | ||
"novachat", | ||
"novachat-plugin" | ||
], | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
"type": "module", | ||
"files": [ | ||
"publish" | ||
], | ||
"scripts": { | ||
"setup": "pnpm build", | ||
"build": "tsup", | ||
"dev": "pnpm build --watch" | ||
}, | ||
"sideEffects": false, | ||
"devDependencies": { | ||
"ollama": "^0.5.9", | ||
"tsup": "^8.3.0", | ||
"typescript": "^5.3.3", | ||
"vitest": "^1.2.2" | ||
}, | ||
"dependencies": { | ||
"@novachat/plugin": "workspace:*" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org/" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as novachat from '@novachat/plugin' | ||
import ollama from 'ollama/browser' | ||
|
||
function convertMessages(messages: novachat.QueryRequest['messages']) { | ||
return messages.map((it) => ({ | ||
role: it.role, | ||
content: it.content, | ||
images: it.attachments?.map((it) => it.url), | ||
})) | ||
} | ||
|
||
export async function activate() { | ||
const list = await ollama.list() | ||
await novachat.model.registerProvider({ | ||
name: 'Ollama', | ||
models: list.models.map((it) => ({ id: it.name, name: it.name })), | ||
async invoke(query) { | ||
const r = await ollama.chat({ | ||
model: query.model, | ||
messages: convertMessages(query.messages), | ||
}) | ||
return { | ||
content: r.message.content, | ||
} | ||
}, | ||
async *stream(query) { | ||
const r = await ollama.chat({ | ||
model: query.model, | ||
messages: convertMessages(query.messages), | ||
stream: true, | ||
}) | ||
for await (const it of r) { | ||
yield { | ||
content: it.message.content, | ||
} | ||
} | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"id": "novachat.ollama", | ||
"name": "Ollama", | ||
"description": "Ollama Provider", | ||
"version": "0.1.0", | ||
"author": "NovaChat" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"lib": ["ESNext"], | ||
"outDir": "./dist", | ||
"skipLibCheck": true, | ||
"esModuleInterop": true, | ||
"strict": true, | ||
"module": "ESNext", | ||
"moduleResolution": "bundler", | ||
"sourceMap": true, | ||
"declaration": true, | ||
"declarationMap": true | ||
}, | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import JSZip from 'jszip' | ||
import { defineConfig } from 'tsup' | ||
import manifest from './src/plugin.json' | ||
import { mkdir, readFile, writeFile } from 'fs/promises' | ||
|
||
export default defineConfig({ | ||
entry: ['src/index.ts'], | ||
format: ['esm'], | ||
bundle: true, | ||
splitting: false, | ||
sourcemap: 'inline', | ||
esbuildOptions: (options) => { | ||
options.platform = 'browser' | ||
}, | ||
plugins: [ | ||
{ | ||
name: 'plugin-novachat', | ||
async buildEnd() { | ||
const zip = new JSZip() | ||
zip.file('plugin.json', JSON.stringify(manifest)) | ||
zip.file('index.js', await readFile('dist/index.js')) | ||
await mkdir('publish', { recursive: true }) | ||
await writeFile( | ||
'publish/plugin.zip', | ||
await zip.generateAsync({ type: 'nodebuffer' }), | ||
) | ||
await writeFile( | ||
'publish/plugin.json', | ||
JSON.stringify(manifest, null, 2), | ||
) | ||
}, | ||
}, | ||
], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters