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: passing data back and forth between Tauri client and Python #22

Merged
merged 18 commits into from
May 23, 2023

Conversation

gjreda
Copy link
Collaborator

@gjreda gjreda commented May 20, 2023

This updates the sidecar PoC. It does the following:

  • Adds a python function that takes an input of text and counts the words in the text, outputting json to stdout
  • Updates the AIView so that when text is highlights, the sidecar word count function is called, the response is read back into the tauri client and ultimately displayed in the view.

It's fun to see it working!

@cguedes
Copy link
Collaborator

cguedes commented May 22, 2023

@gjreda I noticed that after running yarn python files are created insrc-tauri/bin and also the root file main.spec.
Should these be ignored (added to .gitignore) or tracked in git?

@gjreda
Copy link
Collaborator Author

gjreda commented May 22, 2023

@cguedes good catch! yes, we should ignore them from the repo since they will be specific to each of our local machines.

@gjreda gjreda marked this pull request as ready for review May 22, 2023 18:01
@gjreda gjreda requested a review from sergioramos May 22, 2023 19:18
@hammer
Copy link
Contributor

hammer commented May 22, 2023

@cguedes perhaps you could be the reviewer here?

@cguedes cguedes self-requested a review May 23, 2023 07:56
@cguedes
Copy link
Collaborator

cguedes commented May 23, 2023

@gjreda I'm having this error when using python via sidecar.

I've run poetry install and also yarn python

image

Copy link
Collaborator

@cguedes cguedes left a comment

Choose a reason for hiding this comment

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

@gjreda after merging main into this branch and installing all the dependencies again (yarn install, poetry install and yarn python) the app is now working fine 🎉

image

@sergioramos I think you can merge this PoC into main (before #25 that is still in progress).

src-tauri/tauri.conf.json Show resolved Hide resolved
@sergioramos sergioramos changed the title Sidecar PoC: Passing data back and forth between Tauri client and Python feat: passing data back and forth between Tauri client and Python May 23, 2023
@sergioramos sergioramos merged commit 3817319 into main May 23, 2023
@sergioramos sergioramos deleted the gjreda/poc-sidecar-passing branch May 23, 2023 13:05
Copy link
Collaborator

@danvk danvk left a comment

Choose a reason for hiding this comment

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

I saw Command.sidecar in code, got curious and left some comments.

const aiReply = await invoke<string>('interact_with_ai', {
selection,
});
const command = Command.sidecar('bin/python/main', ['--text', `${selection}`]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@cguedes @gjreda Is the idea here that main will eventually be the entrypoint for all Python commands? Or that we'll have separate Python scripts for all commands? I initially misread bin/python/main as being the python binary itself and started getting worried about security.

});
const command = Command.sidecar('bin/python/main', ['--text', `${selection}`]);
const output = await command.execute();
if (output.stderr) throw new Error(output.stderr);
Copy link
Collaborator

Choose a reason for hiding this comment

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

More idiomatic to check output.code for errors here.

Copy link
Collaborator

@danvk danvk left a comment

Choose a reason for hiding this comment

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

I saw Command.sidecar in code, got curious and left some comments.

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.

None yet

5 participants