Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search with Context Similarity #2

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
3de383f
chore(deps): openAi
Keyrxng Jul 12, 2024
bf8d492
chore: settings config
Keyrxng Jul 12, 2024
d8de447
chore: remove supabase
Keyrxng Jul 12, 2024
12cbcc4
feat: add commnt with diff styles
Keyrxng Jul 12, 2024
b9c1ab5
feat: simple openai chat fn
Keyrxng Jul 12, 2024
7643b3f
feat: issue related functions
Keyrxng Jul 12, 2024
bfac23d
fix: improved context issue filtering
Keyrxng Jul 12, 2024
554f3f8
chore: types and plugin entry
Keyrxng Jul 13, 2024
55d5b2a
feat: issue utils
Keyrxng Jul 13, 2024
bd790b5
feat: chat ready
Keyrxng Jul 13, 2024
6063f36
fix: cspell, eslint
Keyrxng Jul 13, 2024
1d51869
feat: ubiquibot-logger
Keyrxng Jul 13, 2024
6b0333b
fix: ignore all bot comments
Keyrxng Jul 13, 2024
a72c97b
chore: use string arrays, remove never configs
Keyrxng Jul 13, 2024
c7b6605
feat: deeper linked context fetching
Keyrxng Jul 13, 2024
94d65e5
chore: types and eslint ignore .wrangler
Keyrxng Jul 14, 2024
154a9b2
chore: simplify main handler
Keyrxng Jul 14, 2024
2b86ab2
feat: comments handler
Keyrxng Jul 14, 2024
7e6582b
chore: improved context handling
Keyrxng Jul 14, 2024
8a0a796
chore: refactor chat formatting, remove no diff error log
Keyrxng Jul 14, 2024
834a570
refactor: optimizing
Keyrxng Jul 14, 2024
c684530
chore: remove env and init tests
Keyrxng Jul 23, 2024
c08b9d0
chore: test env setup
Keyrxng Jul 23, 2024
93e9cd4
refactor: handle PluginInputs separately for better tests
Keyrxng Jul 23, 2024
042bcc0
chore: setup tests
Keyrxng Jul 23, 2024
6ce964d
chore: chat history and linked context tests
Keyrxng Jul 23, 2024
64bf785
chore: remove depth
Keyrxng Jul 23, 2024
f724b85
chore: diff comments from logs
Keyrxng Jul 23, 2024
053856e
chore: fix test
Keyrxng Jul 23, 2024
7bd0557
ci: knip
Keyrxng Jul 23, 2024
442dacb
chore: update .lock file
Keyrxng Jul 23, 2024
9f39f24
chore: fix key
Keyrxng Jul 23, 2024
8b682c8
chore: code cleanup
Keyrxng Jul 23, 2024
230abe0
chore: add another bot comment filter
Keyrxng Jul 23, 2024
f9a8aa4
chore(deps): types/jest for namespace
Keyrxng Jul 24, 2024
1fd9414
chore: eslint style and optimizing handlers
Keyrxng Jul 24, 2024
1160999
chore: unused ternary
Keyrxng Jul 24, 2024
4771e02
chore: system msg format fix
Keyrxng Jul 24, 2024
d9d440a
feat: ubiquity_os_app_slug config item
Keyrxng Sep 24, 2024
0834e09
chore: move api key into env, remove isEnabled, add manifest
Keyrxng Sep 24, 2024
de5a65c
chore: remove workflow items, correct test imports, update logger
Keyrxng Sep 24, 2024
b547300
chore: worker workflows, dotenv, utils > helpers
Keyrxng Sep 25, 2024
96f2a8b
chore: throw LogReturn and bubble up error comment
Keyrxng Sep 25, 2024
68e7938
chore: use regex for slug capture
Keyrxng Sep 25, 2024
d7ceafa
chore: refactor env var name and tests
Keyrxng Sep 25, 2024
3ca8740
chore: format
Keyrxng Sep 25, 2024
742678a
chore: slight fetch and handling improvements
Keyrxng Sep 25, 2024
1701446
chore: more robust key creation, minor fixes
Keyrxng Sep 25, 2024
c687b8b
chore: format and add hashMatch from body
Keyrxng Sep 25, 2024
7d2cc57
chore: optional chaining, try catch blocks
Keyrxng Sep 25, 2024
c498500
chore: add token usage in html comment
Keyrxng Sep 25, 2024
ef080c9
chore: typo
Keyrxng Sep 25, 2024
c4e98b6
chore: readme
Keyrxng Sep 26, 2024
48faffb
chore: camelCase and add config test
Keyrxng Sep 26, 2024
5076ec8
chore: hardcode bot name
Keyrxng Sep 26, 2024
d8bd296
chore: remove t.optional and add baseUrl check
Keyrxng Sep 26, 2024
283d6c7
chore: fix typo
Keyrxng Sep 26, 2024
6b05fdb
chore: optional endpoint, remove packageManager
Keyrxng Sep 30, 2024
a1e47df
Merge pull request #1 from ubq-testing/development
sshivaditya2019 Oct 3, 2024
e133616
fix: project setup and supabase setup
sshivaditya Oct 5, 2024
51454d4
fix: tests
sshivaditya Oct 5, 2024
0f82015
feat: basic chat rag works
sshivaditya Oct 6, 2024
fa67948
fix: cspell
sshivaditya Oct 6, 2024
d1b4514
fix: ci passing locally and cleanup
sshivaditya Oct 12, 2024
dd4c334
fix: tests
sshivaditya Oct 12, 2024
e37f585
fix: tests and knip
sshivaditya Oct 12, 2024
a55fb00
Update package.json
0x4007 Oct 16, 2024
0f00dd4
fix: type rename and add tsx
sshivaditya Oct 17, 2024
6c7f136
fix: knip
sshivaditya Oct 17, 2024
9583286
feat: added instruction to the embedding
sshivaditya Oct 17, 2024
baec08a
fix: tests
sshivaditya Oct 17, 2024
1edbd21
fix: inverted the scale on similarity threshold
sshivaditya Oct 17, 2024
b417cd5
fix: removed jest commas
sshivaditya Oct 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions .cspell.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
{
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
"version": "0.2",
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log", "./src/adapters/supabase/**/**.ts"],
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log", "./src/adapters/supabase/**/**.ts", "/supabase/*"],
"useGitignore": true,
"language": "en",
"words": ["Nektos", "dataurl", "devpool", "outdir", "servedir", "Supabase", "SUPABASE", "typebox", "ubiquibot", "Smee"],
"words": [
"mswjs",
"Nektos",
"dataurl",
"devpool",
"outdir",
"servedir",
"Supabase",
"SUPABASE",
"typebox",
"ubiquibot",
"Smee",
"sonarjs",
"knip",
"mischeck",
"convo",
"ubqbot",
"behaviour",
"voyageai",
"Rerankers",
"reranker",
"rerank",
"reranked",
"mixtral",
"nemo",
"Reranking",
"mistralai"
],
"dictionaries": ["typescript", "node", "software-terms"],
"import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"],
"ignoreRegExpList": ["[0-9a-fA-F]{6}"]
Expand Down
5 changes: 4 additions & 1 deletion .dev.vars.example
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
MY_SECRET="MY_SECRET"
OPENAI_API_KEY=""
SUPABASE_URL=""
SUPABASE_KEY=""
VOYAGEAI_API_KEY=""
1 change: 0 additions & 1 deletion .env.example

This file was deleted.

2 changes: 1 addition & 1 deletion .github/knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const config: KnipConfig = {
ignore: ["src/types/config.ts", "**/__mocks__/**", "**/__fixtures__/**"],
ignoreExportsUsedInFile: true,
// eslint can also be safely ignored as per the docs: https://knip.dev/guides/handling-issues#eslint--jest
ignoreDependencies: ["eslint-config-prettier", "eslint-plugin-prettier", "@mswjs/data"],
ignoreDependencies: ["eslint-config-prettier", "eslint-plugin-prettier", "tsx"],
eslint: true,
};

Expand Down
44 changes: 0 additions & 44 deletions .github/workflows/compute.yml

This file was deleted.

44 changes: 44 additions & 0 deletions .github/workflows/worker-delete.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Delete Deployment

on:
delete:

jobs:
delete:
runs-on: ubuntu-latest
name: Delete Deployment
steps:
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20.10.0"

- name: Enable corepack
run: corepack enable

- uses: actions/checkout@v4

- name: Get Deleted Branch Name
id: get_branch
run: |
branch_name=$(echo '${{ github.event.ref }}' | sed 's#refs/heads/##' | sed 's#[^a-zA-Z0-9]#-#g')
echo "branch_name=$branch_name" >> $GITHUB_ENV
- name: Retrieve and Construct Full Worker Name
id: construct_worker_name
run: |
base_name=$(grep '^name = ' wrangler.toml | head -n 1 | sed 's/^name = "\(.*\)"$/\1/')
full_worker_name="${base_name}-${{ env.branch_name }}"
# Make sure that it doesnt exceed 63 characters or it will break RFC 1035
full_worker_name=$(echo "${full_worker_name}" | cut -c 1-63)
echo "full_worker_name=$full_worker_name" >> $GITHUB_ENV
- name: Delete Deployment with Wrangler
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: delete --name ${{ env.full_worker_name }}

- name: Output Deletion Result
run: |
echo "### Deployment URL" >> $GITHUB_STEP_SUMMARY
echo 'Deployment `${{ env.full_worker_name }}` has been deleted.' >> $GITHUB_STEP_SUMMARY
48 changes: 48 additions & 0 deletions .github/workflows/worker-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Deploy Worker

on:
push:
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
steps:
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20.10.0"

- name: Enable corepack
run: corepack enable

- uses: actions/checkout@v4

- name: Update wrangler.toml Name Field
run: |
branch_name=$(echo '${{ github.event.ref }}' | sed 's#refs/heads/##' | sed 's#[^a-zA-Z0-9]#-#g')
# Extract base name from wrangler.toml
base_name=$(grep '^name = ' wrangler.toml | head -n 1 | sed 's/^name = "\(.*\)"$/\1/')
# Concatenate branch name with base name
new_name="${base_name}-${branch_name}"
# Truncate the new name to 63 characters for RFC 1035
new_name=$(echo "$new_name" | cut -c 1-63)
# Update the wrangler.toml file
sed -i '0,/^name = .*/{s/^name = .*/name = "'"$new_name"'"/}' wrangler.toml
echo "Updated wrangler.toml name to: $new_name"
- name: Deploy with Wrangler
id: wrangler_deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
secrets: |
OPENAI_API_KEY
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

- name: Write Deployment URL to Summary
run: |
echo "### Deployment URL" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.wrangler_deploy.outputs.deployment-url }}" >> $GITHUB_STEP_SUMMARY
100 changes: 24 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,93 +1,41 @@
# `@ubiquibot/plugin-template`
# `@ubiquity-os/command-ask`

## Prerequisites
This is a highly context aware GitHub organization integrated bot that uses the OpenAI GPT-4o model to provide highly relevant answers to questions and queries in GitHub issues and pull requests.

- A good understanding of how the [kernel](https://github.com/ubiquity/ubiquibot-kernel) works and how to interact with it.
- A basic understanding of the Ubiquibot configuration and how to define your plugin's settings.
## Usage

## Getting Started
In any repository where your Ubiquity OS app is installed, both issues and pull requests alike, you simply mention `@UbiquityOS` with your question or query and using the latest OpenAi GPT-4o model, the bot will provide you with a highly relevant answer.

1. Create a new repository using this template.
2. Clone the repository to your local machine.
3. Install the dependencies preferably using `yarn` or `bun`.
## How it works

## Creating a new plugin
With it's huge context window, we are able to feed the entire conversational history to the model which we obtain by recursively fetching any referenced issues or pull requests from the chat history. This allows the model to have a very deep understanding of the current scope and provide highly relevant answers.

- If your plugin is to be used as a slash command which should have faster response times as opposed to longer running GitHub action tasks, you should use the `worker` type.
As it receives everything from discussions to pull request diffs and review comments, it is a highly versatile and capable bot that can assist in a wide range of scenarios.

1. Ensure you understand and have setup the [kernel](https://github.com/ubiquity/ubiquibot-kernel).
2. Update [compute.yml](./.github/workflows/compute.yml) with your plugin's name and update the `id`.
3. Update [context.ts](./src/types/context.ts) with the events that your plugin will fire on.
4. Update [plugin-inputs.ts](./src/types/plugin-inputs.ts) to match the `with:` settings in your org or repo level configuration.
## Installation

- Your plugin config should look similar to this:
`ubiquibot-config.yml`:

```yml
- plugin: <plugin-org/owner>/<plugin-repo-name>:compute.yml@development
name: plugin-name
id: plugin-name-command
description: "Plugin description" # small description of what the plugin does
command: "<regex for command>" # if you are creating a plugin with a slash command
example: "<example usage>" # how to invoke the slash command
with: # these are the example settings, the kernel passes these to the plugin.
disabledCommands: []
timers:
reviewDelayTolerance: 86000
taskStaleTimeoutDuration: 2580000
miscellaneous:
maxConcurrentTasks: 3
labels:
time: []
priority: []
plugins:
- uses:
- plugin: http://localhost:4000
with:
model: ""
openAiBaseUrl: ""
```

###### At this stage, your plugin will fire on your defined events with the required settings passed in from the kernel. You can now start writing your plugin's logic.
`.dev.vars` (for local testing):

5. Start building your plugin by adding your logic to the [plugin.ts](./src/plugin.ts) file.
```sh
# OpenAI API key
OPENAI_API_KEY=your-api-key
UBIQUITY_OS_APP_NAME="UbiquityOS"

## Testing a plugin

### Worker Plugins

- `yarn/bun worker` - to run the worker locally.
- To trigger the worker, `POST` requests to http://localhost:4000/ with an event payload similar to:

```ts
await fetch("http://localhost:4000/", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
stateId: "",
eventName: "",
eventPayload: "",
settings: "",
ref: "",
authToken: "",
}),
});
```

A full example can be found [here](https://github.com/ubiquibot/assistive-pricing/blob/623ea3f950f04842f2d003bda3fc7b7684e41378/tests/http/request.http).

### Action Plugins

- Ensure the kernel is running and listening for events.
- Fire an event in/to the repo where the kernel is installed. This can be done in a number of ways, the easiest being via the GitHub UI or using the GitHub API, such as posting a comment, opening an issue, etc in the org/repo where the kernel is installed.
- The kernel will process the event and dispatch it using the settings defined in your `.ubiquibot-config.yml`.
- The `compute.yml` workflow will run and execute your plugin's logic.
- You can view the logs in the Actions tab of your repo.
## Testing

[Nektos Act](https://github.com/nektos/act) - a tool for running GitHub Actions locally.

## More information

- [Full Ubiquibot Configuration](https://github.com/ubiquity/ubiquibot/blob/0fde7551585499b1e0618ec8ea5e826f11271c9c/src/types/configuration-types.ts#L62) - helpful for defining your plugin's settings as they are strongly typed and will be validated by the kernel.
- [Ubiquibot V1](https://github.com/ubiquity/ubiquibot) - helpful for porting V1 functionality to V2, helper/utility functions, types, etc. Everything is based on the V1 codebase but with a more modular approach. When using V1 code, keep in mind that most all code will need refactored to work with the new V2 architecture.

## Examples

- [Start/Stop Slash Command](https://github.com/ubq-testing/start-stop-module) - simple
- [Assistive Pricing Plugin](https://github.com/ubiquibot/assistive-pricing) - complex
- [Conversation Rewards](https://github.com/ubiquibot/conversation-rewards) - really complex
```sh
yarn test
```
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default tsEslint.config({
"@typescript-eslint": tsEslint.plugin,
"check-file": checkFile,
},
ignores: [".github/knip.ts"],
ignores: [".github/knip.ts", ".wrangler/**/*.ts", ".wrangler/**/*.js"],
extends: [eslint.configs.recommended, ...tsEslint.configs.recommended, sonarjs.configs.recommended],
languageOptions: {
parser: tsEslint.parser,
Expand Down
5 changes: 5 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "command-ask",
"description": "A highly context aware organization integrated chatbot",
"ubiquity:listeners": ["issue_comment.created"]
}
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "plugin-template",
"name": "@ubiquity-os/command-ask",
"version": "1.0.0",
"description": "Ubiquibot plugin template repository with TypeScript support.",
"description": "A highly context aware organization integrated chatbot",
"author": "Ubiquity DAO",
"license": "MIT",
"main": "src/worker.ts",
Expand All @@ -17,7 +17,7 @@
"knip-ci": "knip --no-exit-code --reporter json --config .github/knip.ts",
"prepare": "husky install",
"test": "jest --setupFiles dotenv/config --coverage",
"worker": "wrangler dev --env dev --port 4000"
"worker": "wrangler dev --env dev --port 5000"
},
"keywords": [
"typescript",
Expand All @@ -27,14 +27,16 @@
"open-source"
],
"dependencies": {
"@actions/core": "1.10.1",
"@actions/github": "6.0.0",
"@mswjs/data": "^0.16.2",
"@octokit/rest": "20.1.1",
"@octokit/webhooks": "13.2.7",
"@sinclair/typebox": "0.32.33",
"@supabase/supabase-js": "2.43.5",
"dotenv": "16.4.5",
"typebox-validators": "0.3.5"
"@supabase/supabase-js": "^2.45.4",
"@ubiquity-dao/ubiquibot-logger": "^1.3.0",
"dotenv": "^16.4.5",
"openai": "^4.63.0",
"typebox-validators": "0.3.5",
"voyageai": "^0.0.1-5"
},
"devDependencies": {
"@commitlint/cli": "19.3.0",
Expand All @@ -44,7 +46,7 @@
"@cspell/dict-typescript": "3.1.5",
"@eslint/js": "9.5.0",
"@jest/globals": "29.7.0",
"@mswjs/data": "0.16.1",
"@types/jest": "^29.5.12",
"@types/node": "20.14.5",
"cspell": "8.9.0",
"eslint": "9.5.0",
Expand Down
Loading