You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm developing a custom plugin and encountering an issue.
The issue is that the user_input argument that is passed from the query method to my custom method often contains an empty string even though the arg variable contains the input from the user from the Wox bar.
It turns out that for unknown reasons, very rarely the method does receive a portion of the user input. I invoke the script with Wox using the format "f text that should be passed as user_input", where f triggers the script. I have tested and tried everything. The HelloWorld example works flawlessly. Why is there nondeterministic behavior in parameter passing? Additionally, the arg variable is always populated with the user input as expected.
I'm not using a context menu as demonstrated in the HelloWorld plugin.
Here is my code. The variables arg and user_input are important for my explanation. arg contains what the user inputs in the Wox bar, and user_input is what the executing logic receives.
#` -*- coding: utf-8 -*-importjsonimportwebbrowserimportopenaiimportpyperclipfromwoximportWox, WoxAPIimportsubprocess# Import the subprocess moduleclassHelloWorld(Wox):
"""Example Python plugin for querying OpenAI GPT model and handling web shortcuts."""defquery(self, arg):
"""Searches for a query string in titles and subtitles and returns results. Additionally, saves the structure of 'arg' to a JSON file."""# Return the correct JsonRPCAction with a parameter listreturn [{
'Title': 'Clipboard GPT',
'JsonRPCAction': {
'method': 'gpt_clipboard',
'parameters': [arg], # Ensure parameters are passed as a list'dontHideAfterAction': False,
}
}]
defgpt_clipboard(self, user_input):
"""Handles clipboard operations for GPT responses."""# Deserialize the 'user_input' if necessary (depends on how it's sent from 'query')command="You are an assistant that answers with main information only. Here is your task: "+str(user_input)
try:
response=openai.chat.completions.create(
model="gpt-4-turbo",
messages=[{"role": "user", "content": command}]
)
answer=response.choices[0].message.contentpyperclip.copy(answer) # Copy the answer directly to clipboardreflection=command+" "+answer+" Here is your task. Check if the constraints are met. If not respond only with the piece of information the user needs for his clipboard. for example, the code, the link, the command, the number and so on."response=openai.chat.completions.create(
model="gpt-4-turbo",
messages=[{"role": "user", "content": reflection}]
)
answer=response.choices[0].message.contentpyperclip.copy(answer) # Copy the answer directly to clipboardreturn [{
'Title': 'AI Response',
'SubTitle': answer,
'IcoPath': 'Images/app.png'
}]
exceptExceptionase:
return [{
'Title': 'Error',
'SubTitle': f'An error occurred: {str(e)}',
'IcoPath': 'Images/app.png'
}]
if__name__=="__main__":
HelloWorld()
The issue is that the user_input argument in the gpt_clipboard method often contains an empty string. It turns out that for unknown reasons, very rarely the method does receive a portion of the user input. I invoke the script with Wox using the format "f text that should be passed as user_input", where f triggers the script. I have tested and tried everything. The HelloWorld example works flawlessly. Why is there nondeterministic behavior in parameter passing? Additionally, the arg variable is always populated with the user input as expected.
Thank you for your help in resolving this issue.
The text was updated successfully, but these errors were encountered:
NG-Bullseye
changed the title
Custom Plugin, arg variable wont be passed to the RPCActionMethod.
Custom Plugin, arg variable won't be passed to the RPCActionMethod and becomes an empty String.
May 28, 2024
Version 1.4.1196
Platform
Description
I'm developing a custom plugin and encountering an issue.
The issue is that the user_input argument that is passed from the query method to my custom method often contains an empty string even though the arg variable contains the input from the user from the Wox bar.
It turns out that for unknown reasons, very rarely the method does receive a portion of the user input. I invoke the script with Wox using the format "f text that should be passed as user_input", where f triggers the script. I have tested and tried everything. The HelloWorld example works flawlessly. Why is there nondeterministic behavior in parameter passing? Additionally, the arg variable is always populated with the user input as expected.
I'm not using a context menu as demonstrated in the HelloWorld plugin.
Here is my code. The variables arg and user_input are important for my explanation. arg contains what the user inputs in the Wox bar, and user_input is what the executing logic receives.
The issue is that the user_input argument in the gpt_clipboard method often contains an empty string. It turns out that for unknown reasons, very rarely the method does receive a portion of the user input. I invoke the script with Wox using the format "f text that should be passed as user_input", where f triggers the script. I have tested and tried everything. The HelloWorld example works flawlessly. Why is there nondeterministic behavior in parameter passing? Additionally, the arg variable is always populated with the user input as expected.
Thank you for your help in resolving this issue.
The text was updated successfully, but these errors were encountered: