Connecting GPTChat to KNIME

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

1 Like

Hallo,
have you tried this GPT-3 Info Completion – KNIME Community Hub node ?
Yesterday, I used this node to get information from OpenAI from Knime automaticaly.

By using these node, I only enter my API Key and start writing (a text) what i’m looking for and these node will answer it.

regards,
veni

3 Likes

Hey,

Thanks for the tip. However, I run into the same problem that you have reported before. I got a problem that tell me KeyError: Choise

I try to use my API Key using the display or directly inserting it in the code, but still gives me the same error. Can you tell me how you solved the problem?

Thanks in advance,

AG

The problem was solved

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.