(self, prompt: str, stop: Optional[List[str]] = None)
| 19 | self.chatio = SimpleChatIO() |
| 20 | |
| 21 | def prediction(self, prompt: str, stop: Optional[List[str]] = None) -> str: |
| 22 | max_try = 10 |
| 23 | while True: |
| 24 | openai.api_key = self.openai_key |
| 25 | try: |
| 26 | response = openai.Completion.create( |
| 27 | engine=self.model, |
| 28 | prompt=prompt, |
| 29 | temperature=0.5, |
| 30 | max_tokens=512, |
| 31 | top_p=1, |
| 32 | frequency_penalty=0, |
| 33 | presence_penalty=0, |
| 34 | stop="End Action" |
| 35 | ) |
| 36 | result = response['choices'][0]['text'].strip() |
| 37 | break |
| 38 | except Exception as e: |
| 39 | print(e) |
| 40 | max_try -= 1 |
| 41 | if max_try < 0: |
| 42 | result = "Exceed max retry times. Please check your davinci api calling." |
| 43 | break |
| 44 | return result, response["usage"] |
| 45 | |
| 46 | def add_message(self, message): |
| 47 | self.conversation_history.append(message) |
no outgoing calls
no test coverage detected