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

Gpt 4o mini #92

Open
wants to merge 7 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
21 changes: 21 additions & 0 deletions .github/workflows/external-dependencies-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: External Dependencies Tests

on:
pull_request:
branches: [main]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we test on staging as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gh-action runs the external-dependencies tests directory.
The external dependencies test directory should be limited to only PR to main because we call openai chat completion in there and that has a cost/million token.

I'm looking at this directory to hold tests that requires API calls or dependencies you wouldn't want running too often, and on PR to main seems like a good approach


jobs:
ext-deps-tests:
name: Test external dependencies
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20
cache: "yarn"
- run: yarn install --frozen-lockfile
- name: Run external dependencies tests
run: yarn test-ext-deps
21 changes: 21 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Unit Test

on:
pull_request:
branches: []
Emmanuel-Develops marked this conversation as resolved.
Show resolved Hide resolved

jobs:
ext-deps-tests:
name: Unit Test
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20
cache: "yarn"
- run: yarn install --frozen-lockfile
- name: Run Unit tests
run: yarn test-unit
209 changes: 209 additions & 0 deletions jest.config.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the unused comments in this file

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its autogenerated by jest initialization. They are config options with description of what they do, it looks it will be helpful for any future changes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can always get them from the docs. No need keeping them if we aren't using it

Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
/**
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
*/

import type { Config } from 'jest'
import nextJest from 'next/jest.js'

const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './',
})

const config: Config = {
// All imported modules in your tests should be mocked automatically
// automock: false,

// Stop running tests after `n` failures
// bail: 0,

// The directory where Jest should store its cached dependency information
// cacheDirectory: "/private/var/folders/nj/05bhys9s46x1mtgqm2cq1q_w0000gq/T/jest_dz",

// Automatically clear mock calls, instances, contexts and results before every test
clearMocks: true,

// Indicates whether the coverage information should be collected while executing the test
collectCoverage: true,

// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,

// The directory where Jest should output its coverage files
coverageDirectory: "coverage",

// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "/node_modules/"
// ],

// Indicates which provider should be used to instrument code for coverage
coverageProvider: "v8",

// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
// "json",
// "text",
// "lcov",
// "clover"
// ],

// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: undefined,

// A path to a custom dependency extractor
// dependencyExtractor: undefined,

// Make calling deprecated APIs throw helpful error messages
// errorOnDeprecated: false,

// The default configuration for fake timers
// fakeTimers: {
// "enableGlobally": false
// },

// Force coverage collection from ignored files using an array of glob patterns
// forceCoverageMatch: [],

// A path to a module which exports an async function that is triggered once before all test suites
// globalSetup: undefined,

// A path to a module which exports an async function that is triggered once after all test suites
// globalTeardown: undefined,

// A set of global variables that need to be available in all test environments
// globals: {},

// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",

// An array of directory names to be searched recursively up from the requiring module's location
// moduleDirectories: [
// "node_modules"
// ],

// An array of file extensions your modules use
// moduleFileExtensions: [
// "js",
// "mjs",
// "cjs",
// "jsx",
// "ts",
// "tsx",
// "json",
// "node"
// ],

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],

// Activates notifications for test results
// notify: false,

// An enum that specifies notification mode. Requires { notify: true }
// notifyMode: "failure-change",

// A preset that is used as a base for Jest's configuration
// preset: undefined,

// Run tests from one or more projects
// projects: undefined,

// Use this configuration option to add custom reporters to Jest
// reporters: undefined,

// Automatically reset mock state before every test
// resetMocks: false,

// Reset the module registry before running each individual test
// resetModules: false,

// A path to a custom resolver
// resolver: undefined,

// Automatically restore mock state and implementation before every test
// restoreMocks: false,

// The root directory that Jest should scan for tests and modules within
// rootDir: undefined,

// A list of paths to directories that Jest should use to search for files in
// roots: [
// "<rootDir>"
// ],

// Allows you to use a custom runner instead of Jest's default test runner
// runner: "jest-runner",

// The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: [],

// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: [],

// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,

// A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [],

// The test environment that will be used for testing
// testEnvironment: "jest-environment-node",

// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},

// Adds a location field to test results
// testLocationInResults: false,

// The glob patterns Jest uses to detect test files
testMatch: [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[tj]s?(x)"
],

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
testPathIgnorePatterns: [
"/node_modules/",
"/__mocks__/"
],

// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],

// This option allows the use of a custom results processor
// testResultsProcessor: undefined,

// This option allows use of a custom test runner
// testRunner: "jest-circus/runner",

// A map from regular expressions to paths to transformers
// transform: undefined,

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
// "/node_modules/",
// "\\.pnp\\.[^\\/]+$"
// ],

// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,

// Indicates whether each individual test should be reported during the run
// verbose: undefined,

// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
// watchPathIgnorePatterns: [],

// Whether to use watchman for file crawling
// watchman: true,
};

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
export default createJestConfig(config)
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"test-ext-deps": "jest externalDependency",
"test-unit": "jest unit"
},
"dependencies": {
"@chakra-ui/react": "^2.4.9",
Expand Down Expand Up @@ -51,10 +53,16 @@
"webln": "^0.3.2"
},
"devDependencies": {
"@testing-library/jest-dom": "^6.4.7",
"@testing-library/react": "^16.0.0",
"@types/jest": "^29.5.12",
"@types/next": "^9.0.0",
"@types/react-syntax-highlighter": "^15.5.13",
"@types/uuid": "^9.0.1",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"next-transpile-modules": "^10.0.0",
"ts-node": "^10.9.2",
"webpack": "^5.86.0"
}
}
51 changes: 51 additions & 0 deletions src/__tests__/__mocks__/apiResponse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
export const responseData = `Pay-to-Taproot (P2TR) is a type of ScriptPubKey that locks Bitcoin to a script, which can then be unlocked by either a public key or a Merkelized Alternative Script Tree (MAST). This allows for multiple ways to spend the Bitcoin. Essentially, a P2TR output initially locks Bitcoin to a single Schnorr public key, referred to as Q. However, this public key Q is actually an aggregate of a public key P and another public key M, which is derived from the Merkle root of a list of other ScriptPubKeys [0].

Bitcoin in a P2TR output can be spent in two main ways:

1. **Key Path**: By publishing a signature corresponding to public key P.
2. **Script Path**: By satisfying one of the scripts contained in the Merkle tree.

This dual functionality combines the features of Pay-to-Script-Hash (P2SH) and Pay-to-Public-Key (P2PK) scripts, allowing the owner more flexibility in choosing how to spend their funds. One of the significant advantages of P2TR is its enhancement of user privacy. Only the method used to spend the P2TR output needs to be revealed, while unused alternatives remain private. This undermines many chain analysis heuristics, making all P2TR outputs appear similar and preserving user anonymity [0][4].

Moreover, thanks to Schnorr key aggregation, the public key P can represent a multisig setup without disclosing whether it is indeed a multisig key or a single key. This further adds to the privacy benefits and makes P2TR outputs indistinguishable from each other on the blockchain [0].

--{{ What are the primary benefits of using Pay-to-Taproot (P2TR)? }}--

--{{ How does Pay-to-Taproot (P2TR) enhance user privacy? }}--

--{{ What is the significance of Schnorr key aggregation in P2TR? }}--

--{{ How does Taproot improve scalability and privacy for complex transactions? }}--

[0]: https://river.com/learn/terms/p/pay-to-taproot-p2tr/
[1]: https://bitcoin.stackexchange.com/questions/96025#96567
[2]: https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2018-October/016461.html
[3]: https://bitcoinops.org/en/topics/client-side-validation
[4]: https://bitcoin.stackexchange.com/questions/106445#106449
[5]: https://bitcointalk.org/index.php?topic=5265696.msg54904056#msg54904056`;

export const responseDataBody = `Pay-to-Taproot (P2TR) is a type of ScriptPubKey that locks Bitcoin to a script, which can then be unlocked by either a public key or a Merkelized Alternative Script Tree (MAST). This allows for multiple ways to spend the Bitcoin. Essentially, a P2TR output initially locks Bitcoin to a single Schnorr public key, referred to as Q. However, this public key Q is actually an aggregate of a public key P and another public key M, which is derived from the Merkle root of a list of other ScriptPubKeys [0].

Bitcoin in a P2TR output can be spent in two main ways:

1. **Key Path**: By publishing a signature corresponding to public key P.
2. **Script Path**: By satisfying one of the scripts contained in the Merkle tree.

This dual functionality combines the features of Pay-to-Script-Hash (P2SH) and Pay-to-Public-Key (P2PK) scripts, allowing the owner more flexibility in choosing how to spend their funds. One of the significant advantages of P2TR is its enhancement of user privacy. Only the method used to spend the P2TR output needs to be revealed, while unused alternatives remain private. This undermines many chain analysis heuristics, making all P2TR outputs appear similar and preserving user anonymity [0][4].

Moreover, thanks to Schnorr key aggregation, the public key P can represent a multisig setup without disclosing whether it is indeed a multisig key or a single key. This further adds to the privacy benefits and makes P2TR outputs indistinguishable from each other on the blockchain [0].`

export const responseDataFUQ = `--{{ What are the primary benefits of using Pay-to-Taproot (P2TR)? }}--

--{{ How does Pay-to-Taproot (P2TR) enhance user privacy? }}--

--{{ What is the significance of Schnorr key aggregation in P2TR? }}--

--{{ How does Taproot improve scalability and privacy for complex transactions? }}--`

export const responseDataLinks = `[0]: https://river.com/learn/terms/p/pay-to-taproot-p2tr/
[1]: https://bitcoin.stackexchange.com/questions/96025#96567
[2]: https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2018-October/016461.html
[3]: https://bitcoinops.org/en/topics/client-side-validation
[4]: https://bitcoin.stackexchange.com/questions/106445#106449
[5]: https://bitcointalk.org/index.php?topic=5265696.msg54904056#msg54904056`
48 changes: 48 additions & 0 deletions src/__tests__/__mocks__/mockChatHistory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { ChatHistory } from "@/types";

export const chatHistory: ChatHistory[] = [
{
role: "system",
content: "You are a helpful assistant.",
},
{ role: 'user', content: 'what is the main idea behind taproot' },
{ role: 'user', content: 'what are OP_CODES' },
{
role: 'user',
content: 'What role do OP_CODES play in Bitcoin\'s scripting language?'
}
];

export const chatHistoryContextAware: ChatHistory[] = [
{
role: "system",
content: "You are a helpful assistant.",
},
{ role: 'user', content: 'what is the main idea behind segwit' },
{ role: 'user', content: 'what where the controversies' },
{
role: 'user',
content: 'When was it activated?'
},
{
role: 'user',
content: 'Who proposed it?'
},
];

export const chatHistorySwitchContext: ChatHistory[] = [
{
role: "system",
content: "You are a helpful assistant.",
},
{ role: 'user', content: 'what is the main idea behind segwit' },
{ role: 'user', content: 'what where the controversies' },
{
role: 'user',
content: 'When was it activated?'
},
{
role: 'user',
content: 'Are mining pools decentralized?'
},
];
Loading
Loading