danielmiessler / fabric

fabric is an open-source framework for augmenting humans using AI. It provides a modular framework for solving specific problems using a crowdsourced set of AI prompts that can be used anywhere.
https://danielmiessler.com/p/fabric-origin-story
MIT License
24.25k stars 2.61k forks source link

[Bug]: .env file reset on error in --setup #997

Closed fonteijne closed 1 month ago

fonteijne commented 1 month ago

What happened?

Goal

I want to use a custom hosted OpenAI LLM model instead of the one hosted by OpenAI. Therefore I want to change OPENAI_API_BASE_URL.

What happened

Using fabric --setup I filled in my custom base url. Running fabric -d showed the error "incorrect key for OpenAI". Running fabric --setup again showed me OPENAI_API_BASE_URL was reset to https://api.openai.com/v1

Testing some more

This also happens if I use GROQ_API_BASE_URL (I was just trying out what was happening)

I've also tried editing the .env file directly (using terminal and VS Code), both with the same result. The .env file is reset after choosing a model in fabric -d.

For demontration purposes; I'll be using example.com as custom base url.

What I expected

I expected the .env file not to be updated, as I never gave the instruction to do so. I expect the error message that my API Key is incorrect for the domain 'example.com'

Version check

Relevant log output

~/.c/fabric  cat .env                                                                                                                                                                     do 26 sep 15:52:32 2024
DEFAULT_VENDOR=Ollama
DEFAULT_MODEL=llama3:latest
PATTERNS_LOADER_GIT_REPO_URL=https://github.com/danielmiessler/fabric.git
PATTERNS_LOADER_GIT_REPO_PATTERNS_FOLDER=patterns
ANTHROPIC_API_BASE_URL=https://api.anthropic.com/v1
ANTHROPIC_API_KEY=xxx
OPENAI_API_KEY=xxx
OPENAI_API_BASE_URL=https://example.com
OLLAMA_API_URL=http://localhost:11434
GROQ_API_KEY=xxx
GROQ_API_BASE_URL=https://api.groq.com/openai/v1
YOUTUBE_API_KEY=xxx
JINA_AI_API_KEY=xxx

 ~/.c/fabric  fabric -d                                                                                                                                                                    do 26 sep 15:53:45 2024
OpenAI error, status code: 401, message: Incorrect API key provided: ********************. You can find your API key at https://platform.openai.com/account/api-keys.

Available vendor models:

Anthropic

    [1] claude-3-haiku-20240307
    [2] claude-3-opus-20240229
    [3] claude-3-opus-20240229
    [4] claude-2.0
    [5] claude-2.1
    [6] claude-instant-1.2
    [7] claude-3-5-sonnet-20240620

DryRun

    [8] dry-run-model

Groq

    [9] whisper-large-v3
    [10]    llama-3.2-1b-preview
    [11]    llama-guard-3-8b
    [12]    llama3-8b-8192
    [13]    llama-3.2-90b-text-preview
    [14]    llama-3.1-70b-versatile
    [15]    llama3-70b-8192
    [16]    llama-3.2-3b-preview
    [17]    llama3-groq-70b-8192-tool-use-preview
    [18]    distil-whisper-large-v3-en
    [19]    llava-v1.5-7b-4096-preview
    [20]    mixtral-8x7b-32768
    [21]    llama-3.1-8b-instant
    [22]    llama-3.2-11b-text-preview
    [23]    llama3-groq-8b-8192-tool-use-preview
    [24]    gemma2-9b-it
    [25]    gemma-7b-it

Ollama

    [26]    mistral:latest
    [27]    psychologist:latest
    [28]    llama2:latest
    [29]    codegemma:latest
    [30]    llama3:latest

[Default]

Enter the index the name of your default model (leave empty for 'llama3:latest' or type 'reset' to remove the value):

DEFAULT_VENDOR: Ollama
DEFAULT_MODEL: llama3:latest

 ~/.c/fabric  cat .env                                                                                                                                                            3019ms  do 26 sep 15:53:55 2024
DEFAULT_VENDOR=Ollama
DEFAULT_MODEL=llama3:latest
PATTERNS_LOADER_GIT_REPO_URL=https://github.com/danielmiessler/fabric.git
PATTERNS_LOADER_GIT_REPO_PATTERNS_FOLDER=patterns
ANTHROPIC_API_BASE_URL=https://api.anthropic.com/v1
ANTHROPIC_API_KEY=xxx
OPENAI_API_KEY=xxx
OPENAI_API_BASE_URL=https://api.openai.com/v1
OLLAMA_API_URL=http://localhost:11434
GROQ_API_KEY=xxx
GROQ_API_BASE_URL=https://api.groq.com/openai/v1
YOUTUBE_API_KEY=xxx
JINA_AI_API_KEY=xxx

Relevant screenshots (optional)

No response

eugeis commented 1 month ago

Thank you for the bug report. Please retest it in the 1.4.24 release.

fonteijne commented 1 month ago

Awesome! Thnx for the quick fix!

Retested and got the expected behaviour. 🚀