From bc3b5497173648d8792d7909467b2764eeaaedea Mon Sep 17 00:00:00 2001 From: arcticfly Date: Wed, 15 Jan 2025 15:52:09 -0800 Subject: [PATCH] Optionally record logs --- package.json | 1 + src/common/SetAPIKey.tsx | 19 ++++++++++-- src/helpers/determineNextAction.ts | 15 ++++++---- src/state/settings.ts | 2 ++ yarn.lock | 46 ++++++++++++++++++++++++++++-- 5 files changed, 72 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 88051d0..8dd4ed6 100755 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "immer": "^9.0.21", "lodash": "^4.17.21", "openai": "^4.78.1", + "openpipe": "^0.43.0", "prettier": "^2.8.4", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/src/common/SetAPIKey.tsx b/src/common/SetAPIKey.tsx index d42f5aa..1f786b2 100644 --- a/src/common/SetAPIKey.tsx +++ b/src/common/SetAPIKey.tsx @@ -8,6 +8,7 @@ const ModelDropdown = () => { })); const [openAIKey, setOpenAIKey] = React.useState(''); + const [openPipeKey, setOpenPipeKey] = React.useState(''); const [showPassword, setShowPassword] = React.useState(false); return ( @@ -42,13 +43,27 @@ const ModelDropdown = () => { {showPassword ? 'Hide' : 'Show'} + + setOpenPipeKey(event.target.value)} + type={showPassword ? 'text' : 'password'} + /> + + ); diff --git a/src/helpers/determineNextAction.ts b/src/helpers/determineNextAction.ts index ca3d2d6..933aff7 100644 --- a/src/helpers/determineNextAction.ts +++ b/src/helpers/determineNextAction.ts @@ -1,4 +1,4 @@ -import { OpenAI } from 'openai'; +import OpenAI from 'openpipe/openai'; import { useAppState } from '../state/store'; import { availableActions } from './availableActions'; import { ParsedResponseSuccess } from './parseResponse'; @@ -37,15 +37,19 @@ export async function determineNextAction( ) { const model = useAppState.getState().settings.selectedModel; const prompt = formatPrompt(taskInstructions, previousActions, simplifiedDOM); - const key = useAppState.getState().settings.openAIKey; - if (!key) { + const openAIKey = useAppState.getState().settings.openAIKey; + const openPipeKey = useAppState.getState().settings.openPipeKey; + if (!openAIKey) { notifyError?.('No OpenAI key found'); return null; } const openai = new OpenAI({ - apiKey: key, + apiKey: openAIKey, dangerouslyAllowBrowser: true, + openpipe: { + apiKey: openPipeKey ?? undefined, + }, }); for (let i = 0; i < maxAttempts; i++) { @@ -63,10 +67,9 @@ export async function determineNextAction( reasoning_effort: model === 'o1' ? 'low' : undefined, temperature: model === 'o1' ? undefined : 0, stop: [''], + store: openPipeKey ? true : false, }); - console.log('completion', completion); - return { usage: completion.usage, prompt, diff --git a/src/state/settings.ts b/src/state/settings.ts index adbbad7..414043e 100644 --- a/src/state/settings.ts +++ b/src/state/settings.ts @@ -2,6 +2,7 @@ import { MyStateCreator } from './store'; export type SettingsSlice = { openAIKey: string | null; + openPipeKey: string | null; selectedModel: string; actions: { update: (values: Partial) => void; @@ -9,6 +10,7 @@ export type SettingsSlice = { }; export const createSettingsSlice: MyStateCreator = (set) => ({ openAIKey: null, + openPipeKey: null, selectedModel: 'gpt-3.5-turbo', actions: { update: (values) => { diff --git a/yarn.lock b/yarn.lock index ed580a8..3fc25cb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10,6 +10,19 @@ "@jridgewell/gen-mapping" "^0.1.0" "@jridgewell/trace-mapping" "^0.3.9" +"@anthropic-ai/sdk@^0.32.1": + version "0.32.1" + resolved "https://registry.yarnpkg.com/@anthropic-ai/sdk/-/sdk-0.32.1.tgz#d22c8ebae2adccc59d78fb416e89de337ff09014" + integrity sha512-U9JwTrDvdQ9iWuABVsMLj8nJVwAyQz6QXvgLsVhryhCEPkLsbcP/MXxm+jYcAwLoV8ESbaTTjnD4kuAFa+Hyjg== + dependencies: + "@types/node" "^18.11.18" + "@types/node-fetch" "^2.6.4" + abort-controller "^3.0.0" + agentkeepalive "^4.2.1" + form-data-encoder "1.7.2" + formdata-node "^4.3.2" + node-fetch "^2.6.7" + "@babel/code-frame@^7.0.0", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.18.6": version "7.18.6" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.18.6.tgz#3b25d38c89600baa2dcc219edfa88a74eb2c427a" @@ -3841,6 +3854,13 @@ encodeurl@~1.0.2: resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59" integrity sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w== +encoding@0.1.13: + version "0.1.13" + resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.13.tgz#56574afdd791f54a8e9b2785c0582a2d26210fa9" + integrity sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A== + dependencies: + iconv-lite "^0.6.2" + enhanced-resolve@^5.0.0, enhanced-resolve@^5.10.0: version "5.12.0" resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.12.0.tgz#300e1c90228f5b570c4d35babf263f6da7155634" @@ -4552,6 +4572,15 @@ form-data-encoder@1.7.2: resolved "https://registry.yarnpkg.com/form-data-encoder/-/form-data-encoder-1.7.2.tgz#1f1ae3dccf58ed4690b86d87e4f57c654fbab040" integrity sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A== +form-data@4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.1.tgz#ba1076daaaa5bfd7e99c1a6cb02aa0a5cff90d48" + integrity sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw== + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.8" + mime-types "^2.1.12" + form-data@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" @@ -5036,7 +5065,7 @@ iconv-lite@0.4.24: dependencies: safer-buffer ">= 2.1.2 < 3" -iconv-lite@0.6.3, iconv-lite@^0.6.3: +iconv-lite@0.6.3, iconv-lite@^0.6.2, iconv-lite@^0.6.3: version "0.6.3" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.6.3.tgz#a52f80bf38da1952eb5c681790719871a1a72501" integrity sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw== @@ -6284,7 +6313,7 @@ node-domexception@1.0.0: resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5" integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ== -node-fetch@^2.6.7: +node-fetch@2.7.0, node-fetch@^2.6.7: version "2.7.0" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d" integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A== @@ -6438,7 +6467,7 @@ open@^8.0.9: is-docker "^2.1.1" is-wsl "^2.2.0" -openai@^4.78.1: +openai@^4.78.0, openai@^4.78.1: version "4.78.1" resolved "https://registry.yarnpkg.com/openai/-/openai-4.78.1.tgz#44c3b195d239891be9c9c53722539ad8a1fcc5f2" integrity sha512-drt0lHZBd2lMyORckOXFPQTmnGLWSLt8VK0W9BhOKWpMFBEoHMoz5gxMPmVq5icp+sOrsbMnsmZTVHUlKvD1Ow== @@ -6451,6 +6480,17 @@ openai@^4.78.1: formdata-node "^4.3.2" node-fetch "^2.6.7" +openpipe@^0.43.0: + version "0.43.0" + resolved "https://registry.yarnpkg.com/openpipe/-/openpipe-0.43.0.tgz#685184a5444b8460da191e24a4592ef2c0b4f2ad" + integrity sha512-kWUACzzUK5RLfgODJwknCVqtZ3E2At0Q88s9sEh09vMMvNRUnqk913Ax3XlKajCzyqQH6UNBs23tBjkyIi/0vQ== + dependencies: + "@anthropic-ai/sdk" "^0.32.1" + encoding "0.1.13" + form-data "4.0.1" + node-fetch "2.7.0" + openai "^4.78.0" + optionator@^0.8.1: version "0.8.3" resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.3.tgz#84fa1d036fe9d3c7e21d99884b601167ec8fb495"