Skip to content

Commit

Permalink
Optionally record logs
Browse files Browse the repository at this point in the history
  • Loading branch information
arcticfly committed Jan 15, 2025
1 parent 4f5a3cf commit bc3b549
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 17 additions & 2 deletions src/common/SetAPIKey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const ModelDropdown = () => {
}));

const [openAIKey, setOpenAIKey] = React.useState('');
const [openPipeKey, setOpenPipeKey] = React.useState('');
const [showPassword, setShowPassword] = React.useState(false);

return (
Expand Down Expand Up @@ -42,13 +43,27 @@ const ModelDropdown = () => {
{showPassword ? 'Hide' : 'Show'}
</Button>
</HStack>
<HStack w="full">
<Input
placeholder="OpenPipe API Key (optional)"
value={openPipeKey}
onChange={(event) => setOpenPipeKey(event.target.value)}
type={showPassword ? 'text' : 'password'}
/>
<Button
onClick={() => setShowPassword(!showPassword)}
variant="outline"
>
{showPassword ? 'Hide' : 'Show'}
</Button>
</HStack>
<Button
onClick={() => updateSettings({ openAIKey })}
onClick={() => updateSettings({ openAIKey, openPipeKey })}
w="full"
disabled={!openAIKey}
colorScheme="blue"
>
Save Key
Save Keys
</Button>
</VStack>
);
Expand Down
15 changes: 9 additions & 6 deletions src/helpers/determineNextAction.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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++) {
Expand All @@ -63,10 +67,9 @@ export async function determineNextAction(
reasoning_effort: model === 'o1' ? 'low' : undefined,
temperature: model === 'o1' ? undefined : 0,
stop: ['</Action>'],
store: openPipeKey ? true : false,
});

console.log('completion', completion);

return {
usage: completion.usage,
prompt,
Expand Down
2 changes: 2 additions & 0 deletions src/state/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { MyStateCreator } from './store';

export type SettingsSlice = {
openAIKey: string | null;
openPipeKey: string | null;
selectedModel: string;
actions: {
update: (values: Partial<SettingsSlice>) => void;
};
};
export const createSettingsSlice: MyStateCreator<SettingsSlice> = (set) => ({
openAIKey: null,
openPipeKey: null,
selectedModel: 'gpt-3.5-turbo',
actions: {
update: (values) => {
Expand Down
46 changes: 43 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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==

[email protected]:
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"
Expand Down Expand Up @@ -4552,6 +4572,15 @@ [email protected]:
resolved "https://registry.yarnpkg.com/form-data-encoder/-/form-data-encoder-1.7.2.tgz#1f1ae3dccf58ed4690b86d87e4f57c654fbab040"
integrity sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A==

[email protected]:
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"
Expand Down Expand Up @@ -5036,7 +5065,7 @@ [email protected]:
dependencies:
safer-buffer ">= 2.1.2 < 3"

[email protected], iconv-lite@^0.6.3:
[email protected], 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==
Expand Down Expand Up @@ -6284,7 +6313,7 @@ [email protected]:
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==
Expand Down Expand Up @@ -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==
Expand All @@ -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"
Expand Down

0 comments on commit bc3b549

Please sign in to comment.