Skip to content

feat: passing data back and forth between Tauri client and Python#22

Merged
sergioramos merged 18 commits into
mainfrom
gjreda/poc-sidecar-passing
May 23, 2023
Merged

feat: passing data back and forth between Tauri client and Python#22
sergioramos merged 18 commits into
mainfrom
gjreda/poc-sidecar-passing

Conversation

@gjreda

@gjreda gjreda commented May 20, 2023

Copy link
Copy Markdown
Collaborator

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

cguedes commented May 22, 2023

Copy link
Copy Markdown
Collaborator

@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

gjreda commented May 22, 2023

Copy link
Copy Markdown
Collaborator Author

@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

hammer commented May 22, 2023

Copy link
Copy Markdown
Contributor

@cguedes perhaps you could be the reviewer here?

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

cguedes commented May 23, 2023

Copy link
Copy Markdown
Collaborator

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

I've run poetry install and also yarn python

image

@cguedes cguedes left a comment

Copy link
Copy Markdown
Collaborator

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).

Comment thread src-tauri/tauri.conf.json
@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

@danvk danvk left a comment

Copy link
Copy Markdown
Collaborator

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.

Comment thread src/views/AIView.tsx
const aiReply = await invoke<string>('interact_with_ai', {
selection,
});
const command = Command.sidecar('bin/python/main', ['--text', `${selection}`]);

Copy link
Copy Markdown
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.

Comment thread src/views/AIView.tsx
});
const command = Command.sidecar('bin/python/main', ['--text', `${selection}`]);
const output = await command.execute();
if (output.stderr) throw new Error(output.stderr);

Copy link
Copy Markdown
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.

@danvk danvk left a comment

Copy link
Copy Markdown
Collaborator

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.

5 participants