octaviuslabs / walter

AI-powered software development assistant built right into GitHub so it can act as your junior developer.
MIT License
8 stars 1 forks source link

Better Branch Names #80

Open jsfour opened 1 year ago

jsfour commented 1 year ago

Within CodeEdit here https://github.com/octaviuslabs/walter/blob/main/src/code-generator.ts#L240 we need to return a short super descriptor of the code changes that can be used in a branch name. Any thoughts on what we can do?

imwalterbot commented 1 year ago

Within CodeEdit here https://github.com/octaviuslabs/walter/blob/main/src/code-generator.ts#L240 we need to return a short super descriptor of the code changes that can be used in a branch name. Any thoughts on what we can do?

Queued for processing...

imwalterbot commented 1 year ago

To generate a short super descriptor of the code changes that can be used in a branch name, you can use the following steps in pseudocode:

  1. Extract the main action or intent from the job.action string.
  2. Sanitize the extracted action to remove any special characters or spaces.
  3. Generate a timestamp or a unique identifier.
  4. Combine the sanitized action and the unique identifier to form the branch name.

Here's the pseudocode for the solution:

function generateBranchName(job):
    action = extractMainAction(job.action)
    sanitizedAction = sanitizeString(action)
    uniqueID = generateUniqueID()
    branchName = combineStrings(sanitizedAction, uniqueID)
    return branchName

function extractMainAction(actionString):
    // Extract the main action or intent from the action string
    // This can be done using natural language processing techniques or simple string manipulation

function sanitizeString(string):
    // Remove any special characters or spaces from the string
    // Replace spaces with hyphens or underscores

function generateUniqueID():
    // Generate a timestamp or a unique identifier

function combineStrings(string1, string2):
    // Combine the two strings with a separator, e.g., hyphen or underscore

You can integrate this pseudocode into the createEdit function to generate the branch name and return it as part of the CodeEdit object.

jsfour commented 1 year ago

What natural language processing technique are you thinking for the extraction?

imwalterbot commented 1 year ago

What natural language processing technique are you thinking for the extraction?

Queued for processing...

imwalterbot commented 1 year ago

For extracting the main action or intent from the action string, you can use the following natural language processing techniques:

  1. Keyword extraction: Extract important keywords from the action string that represent the main action. You can use libraries like spaCy, TextBlob, or NLTK for this purpose.

Here's a simple pseudocode for keyword extraction using spaCy:

function extractMainAction(actionString):
    import spacy

    nlp = spacy.load("en_core_web_sm")
    doc = nlp(actionString)

    keywords = []
    for token in doc:
        if token.pos_ in ["NOUN", "VERB"]:
            keywords.append(token.lemma_)

    mainAction = '-'.join(keywords)
    return mainAction
  1. Text summarization: Use text summarization techniques to generate a shorter version of the action string. You can use extractive summarization methods like Gensim's TextRank or abstractive summarization techniques using pre-trained models like OpenAI's GPT-3.

Here's a simple pseudocode for extractive summarization using Gensim's TextRank:

function extractMainAction(actionString):
    import gensim.summarization

    summary = gensim.summarization.summarize(actionString, ratio=0.3, split=True)
    mainAction = '-'.join(summary)
    return mainAction

Please note that these techniques might require additional preprocessing of the action string, like converting it to lowercase, removing special characters, and tokenizing the text. You can choose the technique that best fits your requirements and available resources.

jsfour commented 1 year ago

Is this possible in typescript?

imwalterbot commented 1 year ago

Is this possible in typescript?

Queued for processing...

imwalterbot commented 1 year ago

Yes, it is possible to implement natural language processing techniques in TypeScript. You can use the following libraries for this purpose:

  1. For keyword extraction, you can use the compromise library. It's a lightweight NLP library for JavaScript/TypeScript.

Here's a simple example of keyword extraction using compromise:

import * as nlp from 'compromise';

function extractMainAction(actionString: string): string {
  const doc = nlp(actionString);
  const keywords = doc
    .nouns()
    .concat(doc.verbs())
    .out('array');
  const mainAction = keywords.join('-');
  return mainAction;
}
  1. For text summarization, there aren't many readily available libraries in TypeScript. However, you can use a pre-trained model from the Hugging Face Model Hub via their API. You can make an HTTP request to their API for text summarization using a library like axios.

Here's a simple example of text summarization using the Hugging Face API and axios:

import axios from 'axios';

async function extractMainAction(actionString: string): Promise<string> {
  const response = await axios.post(
    'https://api-inference.huggingface.co/models/t5-small',
    {
      inputs: `summarize: ${actionString}`,
    },
    {
      headers: {
        'Content-Type': 'application/json',
        Authorization: `Bearer YOUR_API_KEY`,
      },
    }
  );

  const summary = response.data[0].generated_text;
  const mainAction = summary.replace(/\s+/g, '-');
  return mainAction;
}

Please note that you need to replace YOUR_API_KEY with your Hugging Face API key.

Keep in mind that using external libraries or APIs may have an impact on the performance and resource usage of your application. Choose the approach that best fits your requirements and available resources.

jsfour commented 1 year ago

what about the openai api?

imwalterbot commented 1 year ago

what about the openai api?

Queued for processing...

imwalterbot commented 1 year ago

You can use the OpenAI API to perform text summarization or extract the main action from the action string using GPT-3. To do this in TypeScript, you can use the axios library to make an HTTP request to the OpenAI API.

Here's a simple example of text summarization using the OpenAI API and axios:

import axios from 'axios';

async function extractMainAction(actionString: string): Promise<string> {
  const response = await axios.post(
    'https://api.openai.com/v1/engines/davinci-codex/completions',
    {
      prompt: `summarize: ${actionString}`,
      max_tokens: 20,
      n: 1,
      stop: null,
      temperature: 0.5,
    },
    {
      headers: {
        'Content-Type': 'application/json',
        Authorization: `Bearer YOUR_API_KEY`,
      },
    }
  );

  const summary = response.data.choices[0].text;
  const mainAction = summary.trim().replace(/\s+/g, '-');
  return mainAction;
}

Please note that you need to replace YOUR_API_KEY with your OpenAI API key.

Before using the OpenAI API, make sure you have an API key and are aware of the usage limits and costs associated with it. You can find more information about the OpenAI API and GPT-3 in the official documentation.