Skip to content

Instantly share code, notes, and snippets.

@ChunkLightTuna
Created April 22, 2024 03:31
Show Gist options
  • Save ChunkLightTuna/2de88fc39fc0ac7e1eccc5d67fdc226f to your computer and use it in GitHub Desktop.
Save ChunkLightTuna/2de88fc39fc0ac7e1eccc5d67fdc226f to your computer and use it in GitHub Desktop.
import sys
import textwrap
from pathlib import Path
from typing import Annotated
import typer
from llama_index.core.base.llms.types import ChatMessage
from llama_index.llms.ollama import Ollama
app = typer.Typer(add_completion=False)
@app.command()
def main(
question: Annotated[str, typer.Argument(help="What do you want to ask about your codebase.")],
path: Annotated[Path, typer.Option('-p',
exists=True, file_okay=False, dir_okay=True, readable=True,
resolve_path=True,
help="Path to your codebase src files.")] = Path('.'),
filetype: Annotated[str, typer.Option('-f', help="Filter by files ending in this string.")] = '.py'
):
llm = Ollama(
model='deepseek-coder:6.7b',
context_window=16384,
request_timeout=60.0
)
prompt = textwrap.dedent(
"""You are an AI coder who is trying to help the user develop and debug an application based on their file system. The user has provided you with the following files and their contents, finally folllowed by the error message or issue they are facing.
The file list is given between the triple backticks (```), Each file is separated by three dashes (---). There are no files in the project besides the ones listed here.
```
{file_context}
```
The issue is given between the triple hashes (###):
###
{issue_description}
###
If you are not sure what the answer is, say that explicitly.
""")
file_contents = '\n---\n'.join([
path_contents
for file in path.glob(f'**/*{filetype}')
for path_contents in [
'/'.join(file.parts[len(path.parts):]),
file.read_text(encoding='UTF-8')
]
])
for file in path.glob(f'**/*{filetype}'):
print('/'.join(file.parts[len(path.parts):]))
msg = f'{prompt}\n{file_contents}\n###\n{question}\n###'
print(f'char count: {len(msg)}')
for m in llm.stream_chat([ChatMessage.from_str(msg)]):
sys.stdout.write(m.delta)
if __name__ == "__main__":
app()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment