Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: repo-query support #15

Merged
merged 11 commits into from Aug 7, 2023
Merged

Conversation

diivi
Copy link
Contributor

@diivi diivi commented Aug 1, 2023

Description

Fixes #14

What type of PR is this? (check all applicable)

  • πŸ• Feature
  • πŸ› Bug Fix
  • πŸ“ Documentation Update
  • 🎨 Style
  • πŸ§‘β€πŸ’» Code Refactor
  • πŸ”₯ Performance Improvements
  • βœ… Test
  • πŸ€– Build
  • πŸ” CI
  • πŸ“¦ Chore (Release)
  • ⏩ Revert

Related Tickets & Documents

#14

Mobile & Desktop Screenshots/Recordings

Peek 2023-08-01 23-28

Implemented a loop for QnA after I recorded this GIF.

Added tests?

  • πŸ‘ yes
  • πŸ™… no, because they aren't needed
  • πŸ™‹ no, because I need help

Added to documentation?

  • πŸ“œ README.md
  • πŸ““ docs.opensauced.pizza
  • πŸ• dev.to/opensauced
  • πŸ“• storybook
  • πŸ™… no documentation needed

[optional] Are there any post-deployment tasks we need to perform?

[optional] What gif best describes this PR or how it makes you feel?

@diivi
Copy link
Contributor Author

diivi commented Aug 1, 2023

solved doubt (ignore) This is mostly done (except reviews), but there's this error that I get after a repo gets indexed:
Checking if pawurb/ecto_psql_extras is indexed by us...⏳
Repo not found❗
Indexing repo...⏳
Fetching Repository from GitHub...
Embedding Repository...
Saving the embeddings to our database...
Indexing Complete. You can now ask questions about this repository! πŸŽ‰
Error: EOF
Usage:
  pizza repo-query url [flags]

Flags:
  -b, --branch string   The branch to index (default "HEAD")
  -h, --help            help for repo-query

2023/08/02 00:25:50 EOF
exit status 1

here's the code for sending the indexing request:
https://github.com/diivi/pizza-cli/blob/57d49f5b1cb41a29ba10ecfbc81b77e3399d30f2/cmd/repo-query/repo-query.go#L145-L146
Can you help me understand what might be wrong here?

@diivi
Copy link
Contributor Author

diivi commented Aug 1, 2023

Nevermind, I fixed it.

@bdougie
Copy link
Member

bdougie commented Aug 1, 2023

I noticed that but after I asked a question, I got exit 1 error.

go run main.go repo-query https://github.com/open-sauced/insights --branch beta
Checking if open-sauced/insights is indexed by us...⏳
Repo found βœ…

Want to ask a question about open-sauced/insights?
> what is the test plan?
Searching the codebase for your query...πŸ”
Searching tests/lib/utils/truncate.test.ts for your query...πŸ”
Generating a response...🧠

The test plan for the repository \"open-sauced/insights\" can be found in the file \"tests/lib/utils/truncate.test.ts\". Here are some relevant test cases from that file:\n\n1. Test case: \"string should be returned unchanged\"\n   - Test code: `test(\"string should be returned unchanged\", () => { const string = \"test/testtesttest\"; const result = truncateString(string, 17); expect(result).toBe(\"test/testtesttest\"); });`\n\n2. Test case: \"string should truncate with length\"\n   - Test code: `test(\"string should truncate with length\", () => { const string = \"test/testtesttest\"; const result = truncateString(string, 9); expect(result).toBe(\"test/test...\"); });`\n\nPlease note that these are just a few examples. There might be more test cases in the test plan
Error: EOF
Usage:
  pizza repo-query url [flags]

Flags:
  -b, --branch string   The branch to index (default "HEAD")
  -h, --help            help for repo-query

2023/08/01 11:59:53 EOF
exit status 1

@diivi
Copy link
Contributor Author

diivi commented Aug 1, 2023

I noticed that but after I asked a question, I got exit 1 error.

Fixed with the last commit πŸ˜…

@diivi diivi marked this pull request as ready for review August 1, 2023 19:21
cmd/repo-query/repo-query.go Outdated Show resolved Hide resolved
cmd/repo-query/repo-query.go Outdated Show resolved Hide resolved
cmd/repo-query/repo-query.go Outdated Show resolved Hide resolved
cmd/repo-query/repo-query.go Outdated Show resolved Hide resolved
cmd/repo-query/repo-query.go Outdated Show resolved Hide resolved
cmd/repo-query/repo-query.go Show resolved Hide resolved
cmd/repo-query/repo-query.go Show resolved Hide resolved
cmd/repo-query/repo-query.go Outdated Show resolved Hide resolved
cmd/repo-query/repo-query.go Show resolved Hide resolved
cmd/repo-query/repo-query.go Show resolved Hide resolved
@diivi
Copy link
Contributor Author

diivi commented Aug 2, 2023

I added some parsing errors and some documentation here and there. Also abstracted the SSE listening code and added support for CTRL+C/exit.
Let me know if there's anything more than I can improve.

cmd/repo-query/repo-query.go Outdated Show resolved Hide resolved
@bdougie
Copy link
Member

bdougie commented Aug 2, 2023

I think this is in a place to test live, but only after we switch the Azure deployment. open-sauced/repo-query#10

It would also be nice to format the response return a little syntax highlighting. Not sure if that is a repo-query thing (via system prompt asking for syntax highlight) or something we can do with the response in cobra. Here is the output in markdown:

> can you convert hsl(30, 70.0%, 7.2%) to hex code?
Searching the codebase for your query...πŸ”
Searching components/molecules/PaginationGotoPage/pagination-goto-page.tsx for your query...πŸ”
Generating a response...🧠

Yes, there is a function called `hslToHex` in the codebase. It is used in the `components/molecules/PaginationGotoPage/pagination-goto-page.tsx` file. Here is an example of how it is used:\n\n```tsx\nconst PaginationGotoPage = ({ page, name, setPage, totalPage }: PaginationGotoPageProps): JSX.Element => {\n  const [pageNumber, setPageNumber] = useState<number | string>(page);\n  const [value, setValue] = useState<number | string>(\"\");\n\n  const handleGotoPage = (e: React.FormEvent<HTMLFormElement>) => {\n    e.preventDefault();\n    // Convert HSL to Hex using the hslToHex function\n    const hexColor = hslToHex(30, 70.0, 7.2);\n    // Rest of the code...\n  }\n\n  // Rest of the code...\n}\n```\n\nPlease note that the exact implementation of the `hslToHex` function is not provided in the code snippet. You may need to search for its implementation in other files or external dependencies

Here is a screencap from the terminal:

Screen Shot 2023-08-02 at 9 16 13 AM

@diivi
Copy link
Contributor Author

diivi commented Aug 2, 2023

I didn't want to add a dependency without @jpmcb's suggestion. Also, yeah, the response is markdown.

For the "\n"s, it's a known issue, the server sends "\\n", so this gets rendered as a normal string. The markdown parser for the open-sauced/ai interface has the same problem (the prompt needs to fix this server-side).

@jpmcb
Copy link
Member

jpmcb commented Aug 2, 2023

It would also be nice to format the response return a little syntax highlighting

@bdougie - I was thinking the exact same thing. Yes, this is something we can absolutely tackle and would be trivial with the fmt package:

package main

import (
	"fmt"
)

func main() {
	myString := "This is a string\n\nwith newlines"
	fmt.Println(myString)
}

this prints a the string as:

This is a string

with newlines

As far as deeper syntax highlighting (like with backticks ``` or other markdown style editing from the AI model, that would be more difficult since we'd need to inspect the user's TERM env variable and ensure the terminal environment supports 256 colors.

But for now, interpreting the newlines as literal would be a great first step.

@jpmcb
Copy link
Member

jpmcb commented Aug 2, 2023

For the "\n"s, it's a known issue, the server sends "\n", so this gets rendered as a normal string. The markdown parser for the open-sauced/ai interface has the same problem (the prompt needs to fix this server-side).

@diivi - I'd use a string replacer then:

package main

import (
	"fmt"
	"strings"
)

func main() {
	myString := "This is a string\\n\\nwith newlines"
	replacer := strings.NewReplacer(
		"\\n", "\n",
	)
	myString = replacer.Replace(myString)
	fmt.Println(myString)
}

this returns the correct bits for the string to be formated by fmt

@diivi diivi requested a review from jpmcb August 3, 2023 17:04
Copy link
Member

@jpmcb jpmcb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think overall this looks good πŸ‘πŸΌ I'm sure there will be things to iterate on: for example, I'm hoping to integrate a fancier logging library that was made for CLI applications #17

cmd/repo-query/repo-query.go Show resolved Hide resolved
Copy link
Member

@bdougie bdougie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the approach and look forward to seeing how this evolves.

@jpmcb jpmcb merged commit d94853f into open-sauced:main Aug 7, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Repo query command line interface chat
3 participants