I’m trying to collect human feedbacks on answers provided by LLMs.
The workflow is the following:
- The user inserts input (query, context, parameters …)
- The API calls the model and generates the answer, displayed to the user
- The user uses a boolean to rate the answer (widget)
- The answer is saved on postgres with the feedback
However, looking at postgres database, the script saves the right feedback but with a new answer generated (I think because the script run again from top to bottom when the collection widget is activated).
# OpenAI API call fuction
def ask_function(model, context, prompt, temperature, top_p, max_tokens):
completion = openai.ChatCompletion.create(
model = model,
temperature = temperature,
top_p = top_p ,
max_tokens = max_tokens,
messages=[
{"role": "system", "content": context},
{"role": "user", "content": prompt}
]
)
return completion
# 1) Collection of input (not displayed for simplicity)
# 2) Function calling with user input
gpt35 = ask_function("gpt-3.5-turbo", context, prompt, temperature, top_p, max_tokens)
answer_gpt35 = gpt35.choices[0].message
tokens_gpt35 = gpt35["usage"]["completion_tokens"]
st.info(answer_gpt35['content'], icon=None)
# 3) + 4) Feedback collection and writing in Postgres
st.checkbox(key = "gpt35love", label="I prefer GPT-3.5-turbo answer", on_change = write_postgres(answer_gpt35['content'], st.session_state.gpt35love)
# where write_postgres is a function savings the answer and the feedback in a postgres database.
Someone can help me?