Query OpenAI API for completion. Retry with back-off until they respond
(**kwargs)
| 36 | |
| 37 | |
| 38 | def oa_completion(**kwargs): |
| 39 | """Query OpenAI API for completion. |
| 40 | |
| 41 | Retry with back-off until they respond |
| 42 | """ |
| 43 | import openai |
| 44 | |
| 45 | backoff_time = 3 |
| 46 | while True: |
| 47 | try: |
| 48 | return openai.Completion.create(**kwargs) |
| 49 | except openai.error.OpenAIError: |
| 50 | import traceback |
| 51 | |
| 52 | traceback.print_exc() |
| 53 | time.sleep(backoff_time) |
| 54 | backoff_time *= 1.5 |
| 55 | |
| 56 | |
| 57 | class GPT3LM(BaseLM): |
no outgoing calls
no test coverage detected