Skip to content

Commit

Permalink
Merge pull request #30 from PromptMixerDev/29-add-option-to-send-para…
Browse files Browse the repository at this point in the history
…meters-and-images

Bump version to 1.0.7 in package.json and manifest.json
  • Loading branch information
prompt-mixer authored May 3, 2024
2 parents a7673b3 + 734918f commit 2950906
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 82 deletions.
10 changes: 9 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,18 @@ export const config = {
'llama3:text',
'llama3:70b-text',
],
properties: [
{
id: 'prompt',
name: 'System Prompt',
value: 'You are a helpful assistant.',
type: 'string',
},
],
settings: [],
description:
'Ollama connector runs open-source large language models (LLMs). It supports a variety of LLMs including LLaMA-2, uncensored LLaMA, CodeLLaMA, Falcon, Mistral, Vicuna model, WizardCoder, and Wizard',
author: 'Prompt Mixer team',
author: 'Prompt Mixer',
iconBase64:
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAiIGhlaWdodD0iMjAiIHZpZXdCb3g9IjAgMCAyMCAyMCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik01LjM2MTI5IDEuNUM2LjAxMTY1IDEuNSA2LjU0MDA3IDIuMzMxOTMgNi41NTA3NSAzLjM2NDYxTDYuNTcxMzUgMy4zNTIxMUw2LjU5NTE4IDMuMzM4MDFDNi42MDg3NSAzLjMzMDE1IDYuNjIyMzkgMy4zMjI0IDYuNjM2MTEgMy4zMTQ4MkM3LjA3MDI3IDMuMDc0NzkgNy41NDY4NyAzLjAwNzA0IDcuOTg4NjEgMy4wMDQ4NUg4TDguMDExMzkgMy4wMDQ5MkM4LjQ1MzEzIDMuMDA3MTEgOC45Mjk3MyAzLjA3NDc5IDkuMzYzODkgMy4zMTQ4MkM5LjQwOTc5IDMuMzQwMjEgOS40NTQ3O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5MiA3Ljg1Nzc2QzcuMzI5NTQgNy42MDAyIDcuNjcwMDIgNy40NDA0OSA4LjAyNDg2IDcuNDQwNDlDOC4zNzk3MyA3LjQ0MDQ5IDguNzIwMjIgNy42MDAyIDguOTc4ODQgNy44NTc3NkM5LjI0MjQ2IDguMTIwMzIgOS4zNzUyOSA4LjQzODA4IDkuMzc1MjkgOC42OTM5NFoiIGZpbGw9IiM2RjczN0EiLz4KPHBhdGggZD0iTTEwLjk1NDUgNy4yMzYwOEMxMS4xMDE0IDcuNDg4MjYgMTEuMDQwMyA3Ljc5NTgzIDEwLjgxODEgNy45MjI5OUMxMC41OTYgOC4wNTAxNiAxMC4yOTY4IDcuOTQ4ODEgMTAuMTUgNy42OTY2M0MxMC4wMDMxIDcuNDQ0NDIgMTAuMDY0MiA3LjEzNjg5IDEwLjI4NjQgNy4wMDk2OUMxMC41MDg1IDYuODgyNTIgMTAuODA3NyA2Ljk4Mzg3IDEwLjk1NDUgNy4yMzYwOFoiIGZpbGw9IiM2RjczN0EiLz4KPHBhdGggZD0iTTUuMTQ5NzUgNy44MzkyMUM1LjMzMTE1IDguMDE5MDcgNS42NDY1NiA3Ljk5NzkzIDUuODU0MjUgNy43OTIwNEM2LjA2MTkgNy41ODYxMSA2LjA4MzIyIDcuMjczMzggNS45MDE4MiA3LjA5MzUxQzUuNzIwNDIgNi45MTM2NSA1LjQwNTAxIDYuOTM0NzkgNS4xOTczMiA3LjE0MDcyQzQuOTg5NjcgNy4zNDY2MSA0Ljk2ODM0IDcuNjU5MzQgNS4xNDk3NSA3LjgzOTIxWiIgZmlsbD0iIzZGNzM3QSIvPgo8L3N2Zz4K',
};
44 changes: 42 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import ollama from 'ollama';
import { config } from './config';
import * as fs from 'fs';

interface Message {
role: string;
content: string;
images?: Uint8Array[] | string[];
}

interface Completion {
Expand Down Expand Up @@ -31,18 +33,56 @@ const mapToResponse = (outputs: ChatCompletion[]): ConnectorResponse => {
};
};

function extractImageUrls(prompt: string): string[] {
const imageExtensions = ['.png', '.jpeg', '.jpg', '.webp', '.gif'];
// Updated regex to match both http and local file paths
const urlRegex =
/(https?:\/\/[^\s]+|[a-zA-Z]:\\[^:<>"|?\n]*|\/[^:<>"|?\n]*)/g;
const urls = prompt.match(urlRegex) || [];

return urls.filter((url) => {
const extensionIndex = url.lastIndexOf('.');
if (extensionIndex === -1) {
// If no extension found, return false.
return false;
}
const extension = url.slice(extensionIndex);
return imageExtensions.includes(extension.toLowerCase());
});
}

function encodeImage(imagePath: string): string {
const imageBuffer = fs.readFileSync(imagePath);
return Buffer.from(imageBuffer).toString('base64');
}

async function main(
model: string,
prompts: string[],
properties: Record<string, unknown>,
): Promise<ConnectorResponse> {
const { prompt, ...restProperties } = properties;
const systemPrompt = (prompt ||
config.properties.find((prop) => prop.id === 'prompt')?.value) as string;

const messageHistory: Message[] = [
{ role: 'system', content: 'You are a helpful assistant.' },
{
role: 'system',
content: systemPrompt,
...restProperties,
},
];
const outputs: ChatCompletion[] = [];

try {
for (const prompt of prompts) {
messageHistory.push({ role: 'user', content: prompt });
const imageUrls = extractImageUrls(prompt);
const base64Images = imageUrls.map((imagePath) => encodeImage(imagePath));
messageHistory.push({
role: 'user',
content: prompt,
images: base64Images,
});

const response = await ollama.chat({
model: model,
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "prompt-mixer-ollama-connector",
"name": "Ollama Connector",
"version": "1.0.6",
"version": "1.0.7",
"minAppVersion": "0.1.0",
"description": "Connector for local LLM models installed by Ollama",
"author": "Prompt Mixer",
Expand Down
79 changes: 2 additions & 77 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prompt-mixer-ollama-connector",
"version": "1.0.6",
"version": "1.0.7",
"description": "",
"type": "module",
"main": "main.js",
Expand Down

0 comments on commit 2950906

Please sign in to comment.