Skip to content

Commit

Permalink
fix: attempt fix
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminshafii committed Jan 6, 2025
1 parent f2ec440 commit 3e12279
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pipes/auto-pay/src/agents/payment-detector-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ function paymentDetailsToPaymentInfo(details: PaymentDetails): PaymentInfo {

export async function runPaymentDetector(
recognizedItemId: string,
openaiApiKey: string,
addStep: (recognizedItemId: string, step: any) => void,
updateStepResult: (recognizedItemId: string, stepId: string, result: string) => void,
onProgress?: (message: string) => void,
signal?: AbortSignal
): Promise<PaymentDetectionResult> {
try {
// Clear any existing steps for this item
useAgentStepsStore.getState().clearSteps(recognizedItemId);
const apiKey = useSettings().settings?.openaiApiKey;
const openai = createOpenAI({ apiKey });
const openai = createOpenAI({ apiKey: openaiApiKey });

// Check if already aborted
if (signal?.aborted) {
Expand Down Expand Up @@ -286,6 +286,9 @@ export function usePaymentDetector(recognizedItemId: string) {
const [isProcessing, setIsProcessing] = useState(false);
const toastShownRef = useRef(false);
const abortControllerRef = useRef<AbortController | null>(null);
const { settings } = useSettings();
const addStep = useAgentStepsStore((state) => state.addStep);
const updateStepResult = useAgentStepsStore((state) => state.updateStepResult);

const abort = useCallback(() => {
if (abortControllerRef.current) {
Expand All @@ -308,10 +311,14 @@ export function usePaymentDetector(recognizedItemId: string) {

// Create new abort controller
abortControllerRef.current = new AbortController();
console.log('settings', settings);

// Run the payment detection
const result = await runPaymentDetector(
recognizedItemId,
settings?.openaiApiKey || '',
addStep,
updateStepResult,
(message) => {
if (!toastShownRef.current) {
toast({
Expand Down
1 change: 1 addition & 0 deletions pipes/auto-pay/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default function Home() {

const handleDetect = async () => {
setStep('detecting');
useAgentStepsStore.getState().clearSteps(recognizedItemId);
const result = await detectPayments();
if (result.payments.length > 0) {
setStep('detected');
Expand Down

0 comments on commit 3e12279

Please sign in to comment.