Mentor.LLM.Adapters.OpenAI (mentor v0.2.2)
View SourceAn adapter for integrating OpenAI's language models with the Mentor framework.
This module implements the Mentor.LLM.Adapter
behaviour, enabling communication between Mentor and OpenAI's API. It facilitates sending prompts and receiving responses, ensuring compatibility with Mentor's expected data structures.
Options
:url
(String.t/0
) - API endpoint to use for sending requests The default value is"https://api.openai.com/v1/chat/completions"
.:api_key
(String.t/0
) - Required. OpenAI API key:model
- Required. The OpenAI model to query on, known models are:["gpt-4o", "gpt-4o-mini", "o1", "o1-mini", "o1-preview", "chatgpt-4o-latest", "gpt-4o-realtime-preview", "gpt-4o-mini-realtime-preview", "gpt-4o-audio-preview"]
:temperature
(float/0
) - What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. The default value is1.0
.:http_options
(keyword/0
) - The default value is[]
.
Usage
To utilize this adapter, configure your Mentor
instance with the appropriate options:
config = [
url: "https://api.openai.com/v1/chat/completions",
api_key: System.get_env("OPENAI_API_KEY"),
model: "gpt-4o"
]
mentor = Mentor.start_chat_with!(Mentor.LLM.Adapters.OpenAI, adapter_config: config)
Considerations
- API Key Security: Ensure your OpenAI API key is stored securely and not exposed in your codebase.
- Model Availability: Verify that the specified model is available and suitable for your use case. Refer to OpenAI's official documentation for the most up-to-date list of models and their capabilities.
- Error Handling: The
complete/1
function returns{:ok, response}
on success or{:error, reason}
on failure. Implement appropriate error handling in your application to manage these scenarios.
By adhering to the Mentor.LLM.Adapter
behaviour, this module ensures seamless integration with OpenAI's API, allowing for efficient and effective language model interactions within the Mentor framework.
Summary
Functions
Same as complete/1
but raises an exception in case of error