Provide OpenAI-compatible API
Purpose By implementing this approach, you won’t need to modify the code for each different LLM provider manually. Most major AI companies, such as Claude (Anthropic), Google Gemini, Grok and DeepSeek, and others, offer OpenAI-compatible APIs. Extra configuration To enhance flexibility and reduce the need for frequent code updates, consider allowing users to configure the following options within the app: API Key (api_key) Base URL (base_url) Model Name (model) Code Example Instead of hardcoding these values, you can update your implementation to dynamically accept user-provided settings, like this: post($base_url . "chat/completions", [ 'headers' => [ 'Authorization' => "Bearer $api_key", 'Content-Type' => 'application/json', ], 'json' => [ 'model' => $model, 'messages' => [ ['role' => 'system', 'content' => 'You are a helpful assistant.'], ['role' => 'user', 'content' => 'Explain to me how AI works'] ], 'temperature' => 0.7 ] ]); $responsedata = jsondecode($response->getBody(), true); echo $response_data'choices''message'; ?> What to Change In Your Code you could just change the class, APIClient in src/php/Translator/OpenAI/APIClient.php. let user fill in line 49 and 80 instead of the constant value. maybe create a bar for user to fill in in setting. More Information please refer to the documentation of OpenAI compatible API Gemini: https://ai.google.dev/gemini-api/docs/openai Claude: https://docs.anthropic.com/en/api/openai-sdk grok: https://docs.x.ai/docs/overview#migrating-from-another-llm-provider List Of Provider And Model If you are going to support more LLM provider and model in the future, the list and source code may help you. This is Cline, an open source for code. link: https://github.com/cline/cline/blob/main/src/shared/api.ts i like your work, and it will be perfect if the addon provide api for grok and claude. i believe OpenAI-compatible API can reduce your workload to support most of the api.


marked this as under-review· 1y


marked this as planned· 1y

