@@ -25,12 +25,26 @@ public function register(): void
2525 $ this ->app ->singleton (Pollingo::class, function ($ app ) {
2626 $ config = $ app ['config ' ]['pollingo ' ];
2727
28+ // Debugging to see the actual config
29+ \Log::debug ('Pollingo config: ' , ['config ' => $ config ]);
30+
31+ $ apiKey = $ config ['openai_api_key ' ] ?? null ;
32+ // If apiKey is null, try to get it from nested structure
33+ if ($ apiKey === null && isset ($ config ['openai ' ]['api_key ' ])) {
34+ $ apiKey = $ config ['openai ' ]['api_key ' ];
35+ }
36+
37+ // Ensure apiKey is a string, not null, to avoid type error
38+ $ apiKey = $ apiKey ?? '' ;
39+
40+ $ model = $ config ['openai_model ' ] ?? $ config ['openai ' ]['model ' ] ?? 'gpt-4o ' ;
41+
2842 /**
2943 * @var Pollingo<TKey> $pollingo
3044 */
3145 $ pollingo = Pollingo::make (
32- apiKey: $ config [ ' openai_api_key ' ] ,
33- model: $ config [ ' openai_model ' ] ,
46+ apiKey: $ apiKey ,
47+ model: $ model ,
3448 );
3549
3650 return $ pollingo ;
@@ -42,8 +56,8 @@ public function register(): void
4256
4357 /** @var OpenAITranslator<TKey> */
4458 $ translator = new OpenAITranslator (
45- apiKey: $ config ['openai ' ]['api_key ' ],
46- model: $ config ['openai ' ]['model ' ],
59+ apiKey: $ config ['openai ' ]['api_key ' ] ?? '' ,
60+ model: $ config ['openai ' ]['model ' ] ?? ' gpt-4o ' ,
4761 );
4862
4963 return $ translator ;
0 commit comments