mirror of
https://github.com/khoj-ai/khoj.git
synced 2025-02-17 08:04:21 +00:00
Truncate prompt to not exceed OpenAI prompt limit
Truncate prompt containing the top retrieved entry to 500 words to avoid triggering the max_token limit error
This commit is contained in:
parent
237123d18c
commit
d36da46f7b
1 changed files with 2 additions and 0 deletions
|
@ -174,6 +174,7 @@ def converse(text, model, conversation_history=None, api_key=None, temperature=0
|
|||
Converse with user using OpenAI's GPT
|
||||
"""
|
||||
# Initialize Variables
|
||||
max_words = 500
|
||||
openai.api_key = api_key or os.getenv("OPENAI_API_KEY")
|
||||
|
||||
conversation_primer = f'''
|
||||
|
@ -184,6 +185,7 @@ AI: Hi, I am an AI conversational companion created by OpenAI. How can I help yo
|
|||
|
||||
# Setup Prompt with Primer or Conversation History
|
||||
prompt = message_to_prompt(text, conversation_history or conversation_primer)
|
||||
prompt = ' '.join(prompt.split()[:max_words])
|
||||
|
||||
# Get Response from GPT
|
||||
response = openai.Completion.create(
|
||||
|
|
Loading…
Add table
Reference in a new issue