Skip to content

Commit

Permalink
chore: fix start.sh for all environments
Browse files Browse the repository at this point in the history
  • Loading branch information
tnunamak committed Mar 4, 2024
1 parent 7a338f4 commit d8bf74d
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 34 deletions.
62 changes: 43 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,45 @@

# Selfie

[Jump to Quick Start](#quick-start)

Bring your personal data to life! Selfie offers OpenAI-compatible APIs that bring your data into LLM awareness. Selfie also empowers you to directly search your data with natural language. Selfie runs 100% locally by default to keep your data private.

<img alt="selfie-augmentation" src="./docs/images/playground-augmentation.png" width="100%">
## Features

* Mix your data into text completions using OpenAI-compatible clients like [OpenAI SDKs](https://platform.openai.com/docs/libraries) and [SillyTavern](https://sillytavernai.com).
* Quickly drop in any text file, with enhanced support for conversations exported from messaging platforms.
* Runs locally by default to keep your data private.
* Hosted LLMs from OpenAI, Replicate, etc. are supported too.
* APIs for directly and selectively querying your data in natural language.

### Personalized Chat

<img alt="selfie-augmentation" src="./docs/images/playground-use-data.png" height="300px">

### Natural Search

<img alt="selfie-search" src="./docs/images/playground-search.png" height="250px">

### API Support

```bash
curl -X POST 'http://localhost:8181/v1/chat/completions' \
-H 'Content-Type: application/json' \
-d '{
"messages": [{"role": "user", "content": "As Alice, what is your proudest garden achievement?"}]
}' | jq '.choices[0].message.content'

# "I grew a 10-pound tomato!"
```

[Jump to API Usage](#api-usage-guide)

[//]: # (TODO: build out integration recipes)
[//]: # (*Check out [Integration Recipes]&#40;#integration-recipes&#41; for some example of what you can do with Selfie.*)

[//]: # (* Load data using any [LlamaHub loader]&#40;https://llamahub.ai/?tab=loaders&#41;.)
[//]: # (* Easy deployment with Docker and pre-built executables.)

## Quick Start

Expand All @@ -23,17 +59,6 @@ Bring your personal data to life! Selfie offers OpenAI-compatible APIs that brin
> **Tip**: On macOS you can run `brew install poetry nodejs` with [brew](https://brew.sh).
## Features

* Mix your data into text completions using OpenAI-compatible clients like [OpenAI SDKs](https://platform.openai.com/docs/libraries) and [SillyTavern](https://sillytavernai.com).
* Quickly drop in any text file, with enhanced support for conversations exported from messaging platforms.
* Runs locally by default to keep your data private.
* Unopinionated compatibility with hosted LLMs from OpenAI, Replicate, etc.
* APIs for directly and selectively querying your data in natural language.

[//]: # (* Load data using any [LlamaHub loader]&#40;https://llamahub.ai/?tab=loaders&#41;.)
[//]: # (* Easy deployment with Docker and pre-built executables.)

## Overview

Selfie is designed to compose well with tools on both sides of the text generation process. You can think of it as middleware that intelligently mixes your data into a request.
Expand Down Expand Up @@ -196,7 +221,7 @@ Selfie can be used to augment text generation in a variety of applications. Here

### Powering the OpenAI SDK

The OpenAI SDK is a popular way to access OpenAI's text generation models. You can use Selfie to augment the text completions that the SDK generates by setting the `apiBase` and `apiKey` parameters.
The OpenAI SDK is a popular way to access OpenAI's text generation models. You can use Selfie to augment the text completions that the SDK generates simply by setting the `apiBase` and `apiKey` parameters.

```js
import OpenAI from 'openai';
Expand All @@ -206,17 +231,16 @@ const openai = new OpenAI({
apiKey: ''
});

const name = 'Alice';
const chatCompletion = await openai.chat.completions.create({
// model: 'TheBloke/Mistral-7B-Instruct-v0.2-GGUF/mistral-7b-instruct-v0.2.Q5_K_M.gguf', // Optionally, customize the model used
messages: [
{ role: 'system', content: `Write ${name}'s next reply in a fictional chat with ${name} and their friends.` },
{ role: 'user', content: 'Favorite ice cream?' },
{ role: 'system', content: `Write Alice's next reply.` },
{ role: 'user', content: 'What are your favorite snacks?' },
]
} as any);
});

console.log(chatCompletion.choices[0].message.content);
// "Alice enjoys Bahn Mi and Vietnamese coffee."

// "I enjoy Bahn Mi and Vietnamese coffee."
```

### Powering SillyTavern
Expand Down
Binary file added docs/images/playground-search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/playground-use-data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added pre-commit.yaml
Empty file.
15 changes: 8 additions & 7 deletions selfie-ui/src/app/components/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,21 @@ export const Chat = ({

const chatMessageStyle = {
default: {
ai: { bubble: { backgroundColor: 'oklch(var(--b2))', color: 'oklch(var(--bc))' } }, // Slightly darker base color for AI bubble
ai: { bubble: { backgroundColor: 'oklch(var(--b3))', color: 'oklch(var(--bc))' } },
user: { bubble: { backgroundColor: 'oklch(var(--p))', color: 'oklch(var(--pc))' } },
},
loading: {
bubble: { backgroundColor: 'oklch(var(--b2))', color: 'oklch(var(--bc))' },
}
// loading: {
// bubble: { backgroundColor: 'oklch(var(--b3))', color: 'oklch(var(--bc))' },
// }
};

const chatInputStyle = {
styles: {
container: {
backgroundColor: 'oklch(var(--b3))', // Even more darker base color for input container
backgroundColor: 'oklch(var(--b3))',
border: 'unset',
color: 'oklch(var(--bc))' // Base content color
}
color: 'oklch(var(--bc))'
},
},
placeholder: { text: "Say anything here...", style: { color: 'oklch(var(--bc))' } } // Use base-200 color for placeholder
};
Expand Down
8 changes: 4 additions & 4 deletions selfie-ui/src/app/components/DocumentTable/DocumentTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useMemo, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { FaRegTrashAlt } from 'react-icons/fa';
import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/20/solid";
import { Document } from "@/app/types";
Expand Down Expand Up @@ -80,13 +80,13 @@ const DocumentTable: React.FC<DocumentTableProps> = ({ data, onDeleteDocuments,
return acc;
}, {});
});
}, [data]);;
}, [data]);

useEffect(() => {
onSelectionChange(Object.keys(selectedRows).filter((id) => selectedRows[id]));
}, [selectedRows, onSelectionChange]);

const toggleAllRowsSelected = () => {
const toggleAllRowsSelected = useCallback(() => {
if (allRowsSelected) {
setSelectedRows({});
} else {
Expand All @@ -96,7 +96,7 @@ const DocumentTable: React.FC<DocumentTableProps> = ({ data, onDeleteDocuments,
});
setSelectedRows(newSelectedRows);
}
};
}, [allRowsSelected, data, setSelectedRows])

const handleSelectRow = (id: string) => {
setSelectedRows((prev) => ({
Expand Down
2 changes: 1 addition & 1 deletion selfie-ui/src/app/components/Playground/PlaygroundChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const PlaygroundChat = ({ disabled = false, hasIndexedDocuments = true }: { disa

<input
type="checkbox"
className="toggle mx-2 toggle-sm"
className="toggle mx-2 toggle-sm toggle-primary"
title={!hasIndexedDocuments ? 'Add and index some documents to enable augmentation.' : ''}
disabled={disabled}
checked={hasIndexedDocuments && !disableAugmentation}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const PlaygroundQuery = () => {
<span className="label-text">Include Summary</span>
<input
type="checkbox"
className="toggle toggle-sm"
className="toggle toggle-sm toggle-primary"
checked={includeSummary}
onChange={(e) => setIncludeSummary(e.target.checked)}
/>
Expand Down
6 changes: 4 additions & 2 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ else
fi

MISSING_DEPENDENCIES=""
command -v python >/dev/null 2>&1 || MISSING_DEPENDENCIES="${MISSING_DEPENDENCIES} Python (https://www.python.org/downloads/)\n"

PYTHON_COMMAND=$(command -v python3 || { command -v python &>/dev/null && python --version 2>&1 | grep -q "Python 3" && echo python; })
[ -z "$PYTHON_COMMAND" ] && MISSING_DEPENDENCIES="${MISSING_DEPENDENCIES} Python 3 (https://www.python.org/downloads/)\n"
command -v poetry >/dev/null 2>&1 || MISSING_DEPENDENCIES="${MISSING_DEPENDENCIES} Poetry (https://python-poetry.org/docs/#installation)\n"
command -v yarn >/dev/null 2>&1 || MISSING_DEPENDENCIES="${MISSING_DEPENDENCIES} Yarn (https://yarnpkg.com/getting-started/install)\n"

Expand Down Expand Up @@ -38,4 +40,4 @@ else
fi

echo "Running selfie..."
poetry run python -m selfie $ACCELERATION_FLAG
poetry run $PYTHON_COMMAND -m selfie $ACCELERATION_FLAG

0 comments on commit d8bf74d

Please sign in to comment.