|
5 | 5 |
|
6 | 6 | class ModuleLLM: |
7 | 7 | """ |
8 | | - Currently supports OpenAI, Anthropic, xIA, Huggingface, Ollama, OpenRouter, NovitaAI |
| 8 | + A module that provides a simple interface for using LLMs |
| 9 | +
|
| 10 | + Note : Currently supports OpenAI, Anthropic, xAI, Huggingface, Ollama, OpenRouter, NovitaAI |
9 | 11 | """ |
10 | 12 |
|
11 | 13 | def __init__(self, api_key: str, model: str): |
| 14 | + """ |
| 15 | + Initialize the LLM module |
| 16 | +
|
| 17 | + Args: |
| 18 | + api_key: The API key for the LLM provider |
| 19 | + model: The model to use for the LLM |
| 20 | + """ |
12 | 21 | self.api_key = api_key |
13 | 22 | provider = model.split("/")[0].upper() |
14 | 23 |
|
15 | 24 | os.environ[f"{provider}_API_KEY"] = self.api_key |
16 | 25 |
|
17 | | - def generate(self, prompt: str, system_prompt: str = None) -> str: |
| 26 | + def generate(self, prompt: str, system_prompt: str | None = None) -> str: |
| 27 | + """ |
| 28 | + Generate a response from the LLM |
| 29 | + """ |
18 | 30 | if system_prompt: |
19 | 31 | messages = [ |
20 | 32 | {"role": "system", "content": system_prompt}, |
21 | | - {"role": "user", "content": prompt} |
| 33 | + {"role": "user", "content": prompt}, |
22 | 34 | ] |
23 | 35 | else: |
24 | | - messages = [ |
25 | | - {"role": "user", "content": prompt} |
26 | | - ] |
27 | | - |
28 | | - response = completion( |
29 | | - model="openai/gpt-4o", |
30 | | - messages=messages |
31 | | - ) |
| 36 | + messages = [{"role": "user", "content": prompt}] |
| 37 | + |
| 38 | + response = completion(model="openai/gpt-4o", messages=messages) |
32 | 39 | return response |
33 | 40 |
|
34 | 41 |
|
|
0 commit comments