dai-motoki / zoltraak

GNU General Public License v3.0
364 stars 39 forks source link

Error due to 'GEMINI_API_KEY' not being defined. #152

Open ynott opened 1 month ago

ynott commented 1 month ago

When running Zoltraak, if "GEMINI_API_KEY" is not defined, the following error will occur.

(.venv) C:\Users\tetuy\zoltraak-workspace\hirokichi>zoltraak -v
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\tetuy\zoltraak-workspace\.venv\Scripts\zoltraak.exe\__main__.py", line 4, in <module>
  File "C:\Users\tetuy\zoltraak-workspace\.venv\Lib\site-packages\zoltraak\cli.py", line 9, in <module>
    from zoltraak.converter import MarkdownToPythonConverter
  File "C:\Users\tetuy\zoltraak-workspace\.venv\Lib\site-packages\zoltraak\converter.py", line 11, in <module>
    from zoltraak.gencode import TargetCodeGenerator
  File "C:\Users\tetuy\zoltraak-workspace\.venv\Lib\site-packages\zoltraak\gencode.py", line 6, in <module>
    import zoltraak.llms.gemini as gemini
  File "C:\Users\tetuy\zoltraak-workspace\.venv\Lib\site-packages\zoltraak\llms\gemini.py", line 13, in <module>
    genai.configure(api_key=os.environ["GEMINI_API_KEY"])
                            ~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "<frozen os>", line 679, in __getitem__
KeyError: 'GEMINI_API_KEY'

Versions

Habatakurikei commented 1 month ago

Hi @ynott you need to set a google (gemini) api key to enable function. Zoltraak calls external LLMs and API tokens shall be paid by user. For mac/linux, export GEMINI_API_KEY="your_key". For windows, SET GEMINI_API_KEY=your_key. Thanks.

mininobu commented 1 month ago

横から失礼します。 現行のバージョンでは、GEMINI_API_KEYを環境変数に設定することが必須と理解しました。 質問なのですが、READMEを読む限り、ANTHROPIC_API_KEYも設定すると思いますが、実際に使用されるLLMはClaudeとGeminiどちらが使用されるのでしょうか?

Habatakurikei commented 1 month ago

@mininobu さん、コード確認しました。 結論はAPIキーはClaude, Geminiとも必要です。ただし実際に使用しているのはClaudeのみです。 Geminiによるコード生成部分はコメントアウトされているのですが、 APIキーだけは実行前に指定していないと ynottさんのようなエラーになります。 現行バージョンにてAIモデルを指定した生成はできないようです。ご不便をおかけしております。

mininobu commented 1 month ago

@Habatakurikei APIキーだけ必要なんですね。ご確認ありがとうございました!

jasagiri commented 3 weeks ago

Gemini側の仕様が変わったのかわかりませんが、先ほど試していると、有料アカウントを有効にしていないとAPIの上限のようなエラーが出るようになりました。利用していないなら設定しなくても良いようにできないでしょうか。

Macbook Air M2(2022) zoltraak 0.1.33

WARNING: All log messages before absl::InitializeLog() is called are written to STDERR I0000 00:00:1723900915.921626 13092470 check_gcp_environment_no_op.cc:29] ALTS: Platforms other than Linux and Windows are not supported Please provide me with a prompt! I need more information to understand what you'd like me to do. For example, you could provide:

The more detail you provide, the better I can understand your request and provide a helpful response.

WARNING: All log messages before absl::InitializeLog() is called are written to STDERR I0000 00:00:1723900920.619837 13092711 check_gcp_environment_no_op.cc:29] ALTS: Platforms other than Linux and Windows are not supported Traceback (most recent call last): File "/Users/jasagiri/.asdf/installs/python/3.12.4/bin/zoltraak", line 5, in from zoltraak.cli import main File "/Users/jasagiri/src/zoltraak/zoltraak/cli.py", line 9, in from zoltraak.converter import MarkdownToPythonConverter File "/Users/jasagiri/src/zoltraak/zoltraak/converter.py", line 11, in from zoltraak.gencode import TargetCodeGenerator File "/Users/jasagiri/src/zoltraak/zoltraak/gencode.py", line 6, in import zoltraak.llms.gemini as gemini File "/Users/jasagiri/src/zoltraak/zoltraak/llms/gemini.py", line 53, in response_text = generate_response("gemini-1.5-pro", "prompt", 8192, 1) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jasagiri/src/zoltraak/zoltraak/llms/gemini.py", line 48, in generate_response response = chat_session.send_message(prompt) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jasagiri/.asdf/installs/python/3.12.4/lib/python3.12/site-packages/google/generativeai/generative_models.py", line 578, in send_message response = self.model.generate_content( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jasagiri/.asdf/installs/python/3.12.4/lib/python3.12/site-packages/google/generativeai/generative_models.py", line 331, in generate_content response = self._client.generate_content( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jasagiri/.asdf/installs/python/3.12.4/lib/python3.12/site-packages/google/ai/generativelanguage_v1beta/services/generative_service/client.py", line 827, in generate_content response = rpc( ^^^^ File "/Users/jasagiri/.asdf/installs/python/3.12.4/lib/python3.12/site-packages/google/api_core/gapic_v1/method.py", line 131, in call return wrapped_func(*args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jasagiri/.asdf/installs/python/3.12.4/lib/python3.12/site-packages/google/api_core/retry/retry_unary.py", line 293, in retry_wrapped_func return retry_target( ^^^^^^^^^^^^^ File "/Users/jasagiri/.asdf/installs/python/3.12.4/lib/python3.12/site-packages/google/api_core/retry/retry_unary.py", line 153, in retry_target _retry_error_helper( File "/Users/jasagiri/.asdf/installs/python/3.12.4/lib/python3.12/site-packages/google/api_core/retry/retry_base.py", line 212, in _retry_error_helper raise final_exc from source_exc File "/Users/jasagiri/.asdf/installs/python/3.12.4/lib/python3.12/site-packages/google/api_core/retry/retry_unary.py", line 144, in retry_target result = target() ^^^^^^^^ File "/Users/jasagiri/.asdf/installs/python/3.12.4/lib/python3.12/site-packages/google/api_core/timeout.py", line 120, in func_with_timeout return func(args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/Users/jasagiri/.asdf/installs/python/3.12.4/lib/python3.12/site-packages/google/api_core/grpc_helpers.py", line 78, in error_remapped_callable raise exceptions.from_grpc_error(exc) from exc google.api_core.exceptions.ResourceExhausted: 429 Resource has been exhausted (e.g. check quota).

Habatakurikei commented 3 weeks ago

@jasagiri さんご確認ありがとうございます。 こちら修正すべきなのですが、現状作業負荷的に修正が厳しい状態と思われます。

僭越ながら、私の方でZoltraakのエッセンスをPythonクラス化したKleinというパッケージを開発しております。 Zoltraak Klein リンク先は現状デモバージョンのみですが、来週正式版をリリースします。その際はCloneもpipどちらも利用可能になります。

もしご興味あればこちらですとそのようなエラーは回避できますのでお試しいただけると幸いです。