10clouds / 10minions-vscode

Your Army of GPT-4 Powered Coding Buddies (Boost Your Productivity)
https://marketplace.visualstudio.com/items?itemName=10Clouds.10minions
MIT License
2 stars 0 forks source link

ADD and creating code that does not compile ... #70

Closed cielecki closed 1 year ago

cielecki commented 1 year ago

//////////////////////////////////////////////////////////////////////////////// // Stage 1: Starting ... ////////////////////////////////////////////////////////////////////////////////

File: openai.ts Task: Refactor this, extract common aspect with. the other call

//////////////////////////////////////////////////////////////////////////////// // Stage 2: Understanding ... ////////////////////////////////////////////////////////////////////////////////

LocalChange

Classification: LocalChange

//////////////////////////////////////////////////////////////////////////////// // Stage 3: Conceptualising ... ////////////////////////////////////////////////////////////////////////////////

Step 1: Identify the common aspects between both the success and error cases.

Step 2: Create a function to report the OpenAI call to Analytics. The function will take two parameters: the result and the error. Only one of them will be defined at any given time.

Here's the refactored function:

function reportOpenAICallToAnalytics(result?: string, error?: any) {
  AnalyticsManager.instance.reportOpenAICall(
    {
      model,
      messages: [
        {
          role: "user",
          content: fullPrompt,
        },
      ],
      max_tokens: maxTokens,
      temperature,
    },
    {
      result,
      error,
    }
  );
}

Step 3: Replace the two calls to AnalyticsManager.instance.reportOpenAICall with calls to our new function, reportOpenAICallToAnalytics.

Here's the final refactored code:

      reportOpenAICallToAnalytics(result);
      // ...
    } catch (error) {
      console.error(`Error on attempt ${attempt}: ${error}`);
      reportOpenAICallToAnalytics(undefined, error);
      // ...
    }
  }

So now, in the gptExecute function, replace the two calls to AnalyticsManager.instance.reportOpenAICall with calls to the reportOpenAICallToAnalytics function we created.

//////////////////////////////////////////////////////////////////////////////// // Stage 4: Preparing Changes ... ////////////////////////////////////////////////////////////////////////////////

I will create a new function called reportOpenAICallToAnalytics that takes two parameters: result and error. This function will be responsible for calling AnalyticsManager.instance.reportOpenAICall with the appropriate parameters. Then, I will replace the two calls to AnalyticsManager.instance.reportOpenAICall in the gptExecute function with calls to the new reportOpenAICallToAnalytics function.

REPLACE AnalyticsManager.instance.reportOpenAICall( { model, messages: [ { role: "user", content: fullPrompt, }, ], max_tokens: maxTokens, temperature, }, { result, } );

  // Step 3: On successful run, break the loop early and return the result.
  return result;
} catch (error) {
  // Step 2: Add error handling for exceptions.
  // Step 4: Log the error and retry the process for up to 2 more times.
  console.error(`Error on attempt ${attempt}: ${error}`);

  AnalyticsManager.instance.reportOpenAICall(
    {
      model,
      messages: [
        {
          role: "user",
          content: fullPrompt,
        },
      ],
      max_tokens: maxTokens,
      temperature,
    },
    {
      error,
    }
  );

WITH function reportOpenAICallToAnalytics(result?: string, error?: any) { AnalyticsManager.instance.reportOpenAICall( { model, messages: [ { role: "user", content: fullPrompt, }, ], max_tokens: maxTokens, temperature, }, { result, error, } ); }

  reportOpenAICallToAnalytics(result);

  // Step 3: On successful run, break the loop early and return the result.
  return result;
} catch (error) {
  // Step 2: Add error handling for exceptions.
  // Step 4: Log the error and retry the process for up to 2 more times.
  console.error(`Error on attempt ${attempt}: ${error}`);

  reportOpenAICallToAnalytics(undefined, error);

END_REPLACE

//////////////////////////////////////////////////////////////////////////////// // Stage 5: Applying Changes ... ////////////////////////////////////////////////////////////////////////////////

Error in applying consolidation: Error: Failed replace

replaceText: AnalyticsManager.instance.reportOpenAICall( { model, messages: [ { role: "user", content: fullPrompt, }, ], max_tokens: maxTokens, temperature, }, { result, } );

  // Step 3: On successful run, break the loop early and return the result.
  return result;
} catch (error) {
  // Step 2: Add error handling for exceptions.
  // Step 4: Log the error and retry the process for up to 2 more times.
  console.error(`Error on attempt ${attempt}: ${error}`);

  AnalyticsManager.instance.reportOpenAICall(
    {
      model,
      messages: [
        {
          role: "user",
          content: fullPrompt,
        },
      ],
      max_tokens: maxTokens,
      temperature,
    },
    {
      error,
    }
  );

originalCode: import fetch, { Response } from "node-fetch"; import * as vscode from "vscode"; import AsyncLock = require("async-lock"); import { CANCELED_STAGE_NAME } from "./ui/ExecutionInfo"; import { AnalyticsManager } from "./AnalyticsManager";

type AVAILABLE_MODELS = "gpt-4" | "gpt-3.5-turbo";

let openAILock = new AsyncLock();

/* The extractParsedLines function takes a chunk string as input and returns

/* The queryOpenAI function takes a fullPrompt and other optional parameters to

/* The processOpenAIResponseStream function processes the response from the

/* The gptExecute function is the main exported function, which combines all the

I will create a new function called reportOpenAICallToAnalytics that takes two parameters: result and error. This function will be responsible for calling AnalyticsManager.instance.reportOpenAICall with the appropriate parameters. Then, I will replace the two calls to AnalyticsManager.instance.reportOpenAICall in the gptExecute function with calls to the new reportOpenAICallToAnalytics function.

REPLACE AnalyticsManager.instance.reportOpenAICall( { model, messages: [ { role: "user", content: fullPrompt, }, ], max_tokens: maxTokens, temperature, }, { result, attempt, } ); WITH reportOpenAICallToAnalytics(result);

REPLACE AnalyticsManager.instance.reportOpenAICall( { model, messages: [ { role: "user", content: fullPrompt, }, ], max_tokens: maxTokens, temperature, }, { error, attempt, } ); WITH reportOpenAICallToAnalytics(undefined, error);

ADD function reportOpenAICallToAnalytics(result?: string, error?: any) { AnalyticsManager.instance.reportOpenAICall( { model, messages: [ { role: "user", content: fullPrompt, }, ], max_tokens: maxTokens, temperature, }, { result, error, } ); } END_REPLACE

//////////////////////////////////////////////////////////////////////////////// // Stage 7: Applying Changes (retry) ... ////////////////////////////////////////////////////////////////////////////////

CONSOLIDATION SUCCESFULY APPLIED

//////////////////////////////////////////////////////////////////////////////// // Stage 8: Applying changes as comment (fall back) ... ////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////// // Stage 9: Finishing ... ////////////////////////////////////////////////////////////////////////////////

Finished (Execution Time: 00:01:53)