#best generate answer function

1 messages · Page 1 of 1 (latest)

wide fern
#

Hello everyone!
My goal is:
Creating an effective answer generation function in Python entails preprocessing your context vectors and questions, representing the context for meaningful analysis, analyzing user questions to extract key features, skillfully matching the question to the context vectors, and finally crafting an informative answer.
i tried all the openai tutorial generate answer function using ChatCompletion and Completion mode.

exotic blade
#

Can you share your code?

wide fern
#

def generate_answer2(
df,
question,
messages,
model="gpt-3.5-turbo",
max_len=1000,
size="ada",
max_tokens=150,
stop_sequence=None
):
context = create_context(
question,
df,
max_len=max_len,
size=size,
)

try:
    combined_message_content = f"You are Shana , a female cloth store owner specializing in women's clothing. Your knowledge is solely based on the information provided in this conversation and the context beneath. Please respond in a courteous and professional manner, using only the context and conversation. If the answer is not available in the chat, respond with 'I don't know' in the appropriate language.\n\nContext: {context}\n\nQuestion: {question}"
    messages.append({"role": "user", "content": combined_message_content})
    response = openai.ChatCompletion.create(
        model=model,
        messages=messages,
        temperature=0,
        max_tokens=150
    )
    answer = response["choices"][0]["message"]["content"]
    return answer
except Exception as e:
    print(e)
    return str(e)
exotic blade
#

Do you have some debugging examples of the questions and the prompts to ensure the right context is being provided?