Hi,
I want to use GPTChat API to ask questions in KNIME during my analysis. I was thinking to use the Python Snippet for that. Therefore, I let GPT generate this code. I think it needs some tweaking to obtain the code from an input table and deliver the answer in an output text. Any ideas?
Code:
Import the necessary libraries
import openai
import pandas as pd
Set your API key
openai.api_key = “YOUR_API_KEY”
Read the input table as a Pandas DataFrame
df = pd.DataFrame(knime.in_table)
Extract the prompt from the DataFrame
prompt = df.iloc[0][“prompt”]
Use the GPT-3 API to generate a completion for the prompt
response = openai.Completion.create(engine=“text-davinci-002”, prompt=prompt, max_tokens=1024, n=1,stop=None,temperature=0.5)
completion = response[“choices”][0][“text”]
Create a Pandas DataFrame with the completion
output_df = pd.DataFrame({“completion”: [completion]})
Output the DataFrame as an output table in KNIME
knime.out_table = output_df
Thanks in advance,
AG