ChatDev icon indicating copy to clipboard operation
ChatDev copied to clipboard

make incremental mode language angostic

Open realies opened this issue 1 year ago • 1 comments

at the moment, it looks for .py files; it can be language agnostic with something like this:

import os
import openai

def _load_from_hardware(self, directory) -> None:
    all_files = [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]
    
    if len(all_files) == 0:
        raise ValueError(f"No files found in {directory}")

    for filename in all_files:
        file_path = os.path.join(directory, filename)
        with open(file_path, "r", encoding="utf-8") as file:
            content = file.read()
        
        # Use LLM to identify the language
        language = self._identify_language(content)
        
        self.codebooks[filename] = {
            'content': self._format_code(content),
            'language': language
        }
    
    log_visualize(f"{len(self.codebooks)} files read from {directory}")

def _identify_language(self, content):
    prompt = f"Identify the programming language of the following code:\n\n{content[:1000]}"
    response = openai.ChatCompletion.create(
        model="gpt-4-turbo",
        messages=[
            {"role": "system", "content": "You are a code language identifier. Respond with only the name of the programming language."},
            {"role": "user", "content": prompt}
        ]
    )
    return response.choices[0].message.content.strip()

realies avatar Aug 04 '24 19:08 realies

Thank you for your support. The default generated software is a Python program, which is usually not recognized as another programming language. However, you can make modifications to the repo according to your needs. Thank you again for your contribution!

moonlandar avatar Aug 06 '24 13:08 moonlandar

is it truly completed?

realies avatar Oct 08 '24 02:10 realies

At present, the default generated software is a Python program, so the implementation focuses specifically on handling .py files. Please feel free to make any modifications to the repository as needed, and we would greatly appreciate a pull request. Thank you once again for your valuable contribution!

NA-Wen avatar Oct 08 '24 03:10 NA-Wen

Why did you close the issue when it has not been completed?

realies avatar Oct 08 '24 10:10 realies