# OpenAI API error: Unexpected exception - RetryError[<Future at 0x166c1d01be0 state=finished raised APIConnectionError>]

Shorya Kaushik 0 Reputation points
2023-05-08T04:25:12.59+00:00

Hi All,

My prompt-engine-py tool code that I cloned in my system, is mentioned below:


from prompt_engine.prompt_engine import PromptEngineConfig
from prompt_engine.interaction import Interaction 
from prompt_engine.model_config import ModelConfig
from prompt_engine.dynamic_prompt_engine import DynamicPromptEngine, PromptBank
import openai
import os


api_key = "API KEY IS GENERATED AND PASTED IS CODE."

config = PromptEngineConfig(ModelConfig(max_tokens=1024), description_prefix = "###")

description1 = "The following prompts tell you the urgency of a notification"
examples1 = [Interaction("Your flight is going to be delayed! Please check your Delta app for updated schedules", "Urgent"),
    Interaction("Your daughter was just taken to the emergency room. Please call us back immediately.", "Urgent"),
    Interaction("Hey how are you? We should get lunch sometime.", "Low"),
    Interaction("What is the project status? Please send it to me today.", "High"),
    Interaction("Liverpool is now leading in their game vs Aston Villa.", "Medium")]
dynamic_engine = DynamicPromptEngine(openai_key = api_key, config = config, description = description1, examples=examples1, prompt_bank = PromptBank())
del dynamic_engine

description2 = "Extract the monuments from the given text"
examples2 = [Interaction("Can we go to Taj Mahal?", "Taj Mahal"),
Interaction("How old is the Stonehenge?", "Stonehenge"),
Interaction("The Statue of Liberty is such a massive statue, I wonder how they built it", "Statue of Liberty"),
Interaction("What is the name of that big Buddha statue in Asia?", "Big Buddha Statue"),
Interaction("I want to see the Eiffel Tower!", "Eiffel Tower"),
Interaction("Where is The Vatican located in italy?", "The Vatican"),
Interaction("How many steps are there to the top of the Great Pyramid of Giza?", "Great Pyramid of Giza")]
dynamic_engine = DynamicPromptEngine(openai_key = api_key, config = config, description = description2, examples=examples2, prompt_bank = PromptBank())
del dynamic_engine


description = "I want to classify the importance for the notifications"
flow_reset_text = "Ignore the previous queries, start afresh"
dynamic_engine = DynamicPromptEngine(openai_key = api_key, config = config, description = description, flow_reset_text = flow_reset_text, prompt_bank = PromptBank())

while True:
    user_query = input("Enter your query: ")
    if (user_query == "exit"):
         break
    codex_query = dynamic_engine.build_prompt(user_query)

    response = openai.Completion.create(engine="code-davinci-002", 
                                        prompt=codex_query, 
                                        temperature=0.3, 
                                        max_tokens=dynamic_engine.config.model_config.max_tokens, 
                                        stop=[dynamic_engine.config.newline_operator])

    completion_all = response['choices'][0]['text'].strip()
    print (codex_query+completion_all)
    print ("----------------------------------------------------------------------------------------------------------------")

    if (completion_all != ""):
      dynamic_engine.add_interaction(user_query, completion_all)					

While executing the python file code attached above, the "embeddings_cache.pkl" file is created and then I face the issues mentioned below in the Terminal Console:

Computing embedding for unseen interaction!

OpenAI API error: Unexpected exception - RetryError[<Future at 0x166c1d01be0 state=finished raised APIConnectionError>]

Traceback (most recent call last): File "d:\shorya.kaushik\project\prompt-engine-py\examples\dynamic_prompt_example.py", line 22, in <module> dynamic_engine = DynamicPromptEngine(openai_key = api_key, config = config, description = description1, examples=examples1, prompt_bank = PromptBank()) File "C:\Users\shorya.kaushik\AppData\Roaming\Python\Python39\site-packages\prompt_engine\dynamic_prompt_engine.py", line 161, in init self.__add_examples_to_embedding_cache(self.examples, self.description) File "C:\Users\shorya.kaushik\AppData\Roaming\Python\Python39\site-packages\prompt_engine\dynamic_prompt_engine.py", line 201, in __add_examples_to_embedding_cache
raise Exception("Could not get embedding for example, please try again") Exception: Could not get embedding for example, please try again

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
2,218 questions
{count} votes