(self, config)
| 73 | |
| 74 | class OpenAILLM(LLM): |
| 75 | def __init__(self, config): |
| 76 | super().__init__(config) |
| 77 | if "openai_api_key" in config: |
| 78 | openai_api_key = config["openai_api_key"] |
| 79 | elif "OPENAI_API_KEY" in os.environ: |
| 80 | openai_api_key = os.environ["OPENAI_API_KEY"] |
| 81 | else: |
| 82 | assert False, "OpenAI API key not found" |
| 83 | self.client = OpenAI( |
| 84 | api_key=openai_api_key, |
| 85 | ) |
| 86 | |
| 87 | def __call__(self, prompt: str): |
| 88 | # The line `prompt = truncate_tokens(prompt, encoding_name=self.config["model"], |