diff --git a/docs/.gitignore b/docs/.gitignore
new file mode 100644
index 0000000..6240da8
--- /dev/null
+++ b/docs/.gitignore
@@ -0,0 +1,21 @@
+# build output
+dist/
+# generated types
+.astro/
+
+# dependencies
+node_modules/
+
+# logs
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+pnpm-debug.log*
+
+
+# environment variables
+.env
+.env.production
+
+# macOS-specific files
+.DS_Store
diff --git a/docs/.vscode/extensions.json b/docs/.vscode/extensions.json
new file mode 100644
index 0000000..22a1505
--- /dev/null
+++ b/docs/.vscode/extensions.json
@@ -0,0 +1,4 @@
+{
+ "recommendations": ["astro-build.astro-vscode"],
+ "unwantedRecommendations": []
+}
diff --git a/docs/.vscode/launch.json b/docs/.vscode/launch.json
new file mode 100644
index 0000000..d642209
--- /dev/null
+++ b/docs/.vscode/launch.json
@@ -0,0 +1,11 @@
+{
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "command": "./node_modules/.bin/astro dev",
+ "name": "Development server",
+ "request": "launch",
+ "type": "node-terminal"
+ }
+ ]
+}
diff --git a/docs/README.md b/docs/README.md
new file mode 100644
index 0000000..f95661b
--- /dev/null
+++ b/docs/README.md
@@ -0,0 +1,53 @@
+# Starlight Starter Kit: Basics
+
+[](https://starlight.astro.build)
+
+```
+npm create astro@latest -- --template starlight
+```
+
+[](https://stackblitz.com/github/withastro/starlight/tree/main/examples/basics)
+[](https://codesandbox.io/p/sandbox/github/withastro/starlight/tree/main/examples/basics)
+
+> π§βπ **Seasoned astronaut?** Delete this file. Have fun!
+
+## π Project Structure
+
+Inside of your Astro + Starlight project, you'll see the following folders and files:
+
+```
+.
+βββ public/
+βββ src/
+β βββ assets/
+β βββ content/
+β β βββ docs/
+β β βββ config.ts
+β βββ env.d.ts
+βββ astro.config.mjs
+βββ package.json
+βββ tsconfig.json
+```
+
+Starlight looks for `.md` or `.mdx` files in the `src/content/docs/` directory. Each file is exposed as a route based on its file name.
+
+Images can be added to `src/assets/` and embedded in Markdown with a relative link.
+
+Static assets, like favicons, can be placed in the `public/` directory.
+
+## π§ Commands
+
+All commands are run from the root of the project, from a terminal:
+
+| Command | Action |
+| :------------------------ | :----------------------------------------------- |
+| `npm install` | Installs dependencies |
+| `npm run dev` | Starts local dev server at `localhost:4321` |
+| `npm run build` | Build your production site to `./dist/` |
+| `npm run preview` | Preview your build locally, before deploying |
+| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
+| `npm run astro -- --help` | Get help using the Astro CLI |
+
+## π Want to learn more?
+
+Check out [Starlightβs docs](https://starlight.astro.build/), read [the Astro documentation](https://docs.astro.build), or jump into the [Astro Discord server](https://astro.build/chat).
diff --git a/docs/astro.config.mjs b/docs/astro.config.mjs
new file mode 100644
index 0000000..9eacfd1
--- /dev/null
+++ b/docs/astro.config.mjs
@@ -0,0 +1,27 @@
+import { defineConfig } from 'astro/config';
+import starlight from '@astrojs/starlight';
+
+// https://astro.build/config
+export default defineConfig({
+ integrations: [
+ starlight({
+ title: 'My Docs',
+ social: {
+ github: 'https://github.com/withastro/starlight',
+ },
+ sidebar: [
+ {
+ label: 'Guides',
+ items: [
+ // Each item here is one entry in the navigation menu.
+ { label: 'Example Guide', link: '/guides/example/' },
+ ],
+ },
+ {
+ label: 'Reference',
+ autogenerate: { directory: 'reference' },
+ },
+ ],
+ }),
+ ],
+});
diff --git a/docs/package.json b/docs/package.json
new file mode 100644
index 0000000..19ad5d7
--- /dev/null
+++ b/docs/package.json
@@ -0,0 +1,17 @@
+{
+ "name": "docs",
+ "type": "module",
+ "version": "0.0.1",
+ "scripts": {
+ "dev": "astro dev",
+ "start": "astro dev",
+ "build": "astro build",
+ "preview": "astro preview",
+ "astro": "astro"
+ },
+ "dependencies": {
+ "@astrojs/starlight": "^0.11.0",
+ "astro": "^3.2.3",
+ "sharp": "^0.32.5"
+ }
+}
\ No newline at end of file
diff --git a/docs/public/favicon.svg b/docs/public/favicon.svg
new file mode 100644
index 0000000..cba5ac1
--- /dev/null
+++ b/docs/public/favicon.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/docs/src/assets/houston.webp b/docs/src/assets/houston.webp
new file mode 100644
index 0000000..930c164
Binary files /dev/null and b/docs/src/assets/houston.webp differ
diff --git a/docs/src/content/config.ts b/docs/src/content/config.ts
new file mode 100644
index 0000000..9df91b6
--- /dev/null
+++ b/docs/src/content/config.ts
@@ -0,0 +1,7 @@
+import { defineCollection } from 'astro:content';
+import { docsSchema, i18nSchema } from '@astrojs/starlight/schema';
+
+export const collections = {
+ docs: defineCollection({ schema: docsSchema() }),
+ i18n: defineCollection({ type: 'data', schema: i18nSchema() }),
+};
diff --git a/docs/src/content/docs/guides/example.md b/docs/src/content/docs/guides/example.md
new file mode 100644
index 0000000..ebd0f3b
--- /dev/null
+++ b/docs/src/content/docs/guides/example.md
@@ -0,0 +1,11 @@
+---
+title: Example Guide
+description: A guide in my new Starlight docs site.
+---
+
+Guides lead a user through a specific task they want to accomplish, often with a sequence of steps.
+Writing a good guide requires thinking about what your users are trying to do.
+
+## Further reading
+
+- Read [about how-to guides](https://diataxis.fr/how-to-guides/) in the DiΓ‘taxis framework
diff --git a/docs/src/content/docs/index.mdx b/docs/src/content/docs/index.mdx
new file mode 100644
index 0000000..117179d
--- /dev/null
+++ b/docs/src/content/docs/index.mdx
@@ -0,0 +1,36 @@
+---
+title: Welcome to Starlight
+description: Get started building your docs site with Starlight.
+template: splash
+hero:
+ tagline: Congrats on setting up a new Starlight project!
+ image:
+ file: ../../assets/houston.webp
+ actions:
+ - text: Example Guide
+ link: /guides/example/
+ icon: right-arrow
+ variant: primary
+ - text: Read the Starlight docs
+ link: https://starlight.astro.build
+ icon: external
+---
+
+import { Card, CardGrid } from '@astrojs/starlight/components';
+
+## Next steps
+
+
+
+ Edit `src/content/docs/index.mdx` to see this page change.
+
+
+ Add Markdown or MDX files to `src/content/docs` to create new pages.
+
+
+ Edit your `sidebar` and other config in `astro.config.mjs`.
+
+
+ Learn more in [the Starlight Docs](https://starlight.astro.build/).
+
+
diff --git a/docs/src/content/docs/reference/example.md b/docs/src/content/docs/reference/example.md
new file mode 100644
index 0000000..ac8cfa8
--- /dev/null
+++ b/docs/src/content/docs/reference/example.md
@@ -0,0 +1,11 @@
+---
+title: Example Reference
+description: A reference page in my new Starlight docs site.
+---
+
+Reference pages are ideal for outlining how things work in terse and clear terms.
+Less concerned with telling a story or addressing a specific use case, they should give a comprehensive outline of what your documenting.
+
+## Further reading
+
+- Read [about reference](https://diataxis.fr/reference/) in the DiΓ‘taxis framework
diff --git a/docs/src/env.d.ts b/docs/src/env.d.ts
new file mode 100644
index 0000000..acef35f
--- /dev/null
+++ b/docs/src/env.d.ts
@@ -0,0 +1,2 @@
+///
+///
diff --git a/docs/tsconfig.json b/docs/tsconfig.json
new file mode 100644
index 0000000..77da9dd
--- /dev/null
+++ b/docs/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "extends": "astro/tsconfigs/strict"
+}
\ No newline at end of file
diff --git a/main.py b/main.py
index 46ac2e7..267227a 100644
--- a/main.py
+++ b/main.py
@@ -18,7 +18,6 @@
openai.api_key = OPENAI_API_KEY
-
# Initialize logging
logging.basicConfig(level=logging.INFO)
@@ -184,17 +183,22 @@ def solve_problem(mention, issue_number, issue_description):
prompt = generate_gpt_prompt(issue_data)
- out = run_query(
+ ai_response, patch_file = run_query(
prompt,
mention["repository"]["owner"]["login"],
mention["repository"]["name"],
)
- # response = generate_response(issue_description)
- # print(response)
post_comment_to_issue(
issue_number,
- out,
+ ai_response,
+ mention["repository"]["owner"]["login"],
+ mention["repository"]["name"],
+ )
+
+ post_comment_to_issue(
+ issue_number,
+ patch_file,
mention["repository"]["owner"]["login"],
mention["repository"]["name"],
)
@@ -242,16 +246,16 @@ def respond_to_unread_issues():
post_comment_to_issue(
issue_number=issue_number,
comment_text=f"""#### π **Rate Limit Exceeded!**
-
-β **Limit:** {USAGE_LIMIT} requests / day / repository
-π **Refreshes In:** {int(hours)} hours, {int(minutes)} minutes
-
-
-
-π¬ For any inquiries for support or rate limit extension, please contact Support.""",
+
+ β **Limit:** {USAGE_LIMIT} requests / day / repository
+ π **Refreshes In:** {int(hours)} hours, {int(minutes)} minutes
+
+
+
+ π¬ For any inquiries for support or rate limit extension, please contact Support.""",
OWNER=mention["repository"]["owner"]["login"],
REPO=mention["repository"]["name"],
)
@@ -287,7 +291,6 @@ def respond_to_unread_issues():
# response = generate_response(problem_description)
# # Post the response as a comment on the issue
-# post_comment_to_issue(issue_number, response)
# return jsonify({"message": "Webhook processed successfully"})
diff --git a/utils/github_utils.py b/utils/github_utils.py
index 5267e11..edd530c 100644
--- a/utils/github_utils.py
+++ b/utils/github_utils.py
@@ -273,6 +273,8 @@ def setup_repo(owner, repo_name):
print("Repo already exists")
+import difflib
+
def run_query(query: str, owner: str, repo_name: str):
setup_repo(owner, repo_name)
matched_docs = vector_store.similarity_search(
@@ -284,6 +286,69 @@ def run_query(query: str, owner: str, repo_name: str):
current_tokens = 0
+ for doc in matched_docs:
+ doc_content = doc.page_content + "\n\n"
+ doc_tokens = num_tokens_from_string(doc_content)
+ print(matched_docs.index(doc), doc_tokens)
+ if current_tokens + doc_tokens < MAX_TOKENS:
+ code_str += doc_content
+ current_tokens += doc_tokens
+ else:
+ break # stop adding more content if it exceeds the max token limit
+
+ template = """
+ You are Codebase AI. You are a super intelligent AI that answers questions about code bases.
+
+ You are:
+ - helpful & friendly
+ - good at answering complex questions in simple language
+ - an expert in all programming languages
+ - able to infer the intent of the user's question
+
+ The user will ask a question about their codebase, and you will answer it.
+
+ When the user asks their question, you will answer it by searching the codebase for the answer.
+
+ Here is the user's question and code file(s) you found to answer the question:
+
+ Question:
+ {query}
+
+ Code file(s):
+ {code}
+
+ [END OF CODE FILE(S)]w
+
+ Now answer the question using the code file(s) above.
+ """
+
+ chat = ChatOpenAI(
+ streaming=True,
+ callback_manager=CallbackManager([StreamingStdOutCallbackHandler()]),
+ verbose=True,
+ temperature=0.5,
+ )
+ system_message_prompt = SystemMessagePromptTemplate.from_template(template)
+ chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt])
+ chain = LLMChain(llm=chat, prompt=chat_prompt)
+
+ print("running chain...")
+ ai_said = chain.run(code=code_str, query=query)
+ print("chain output...")
+
+ # Generate patch file
+ original_code = code_str.splitlines()
+ modified_code = code_str.replace(query, ai_said).splitlines()
+ diff = difflib.unified_diff(original_code, modified_code)
+ patch_file = '\n'.join(diff)
+
+ return ai_said, patch_file
+
+ code_str = ""
+ MAX_TOKENS = 3500
+
+ current_tokens = 0
+
for doc in matched_docs:
doc_content = doc.page_content + "\n\n"
doc_tokens = num_tokens_from_string(doc_content)