ju-bezdek / langchain-decorators

syntactic sugar 🍭 for langchain
MIT License
228 stars 11 forks source link

ChatOpenAI being loaded despite using settings with ChatAnthropic #2

Closed lukestanley closed 1 year ago

lukestanley commented 1 year ago

Maybe I'm using it wrong but there is an error after I try setting the LLM in both ways shown in the README.

from langchain.chat_models import ChatAnthropic

from langchain_decorators import GlobalSettings

GlobalSettings.define_settings(
    default_llm=ChatAnthropic(temperature=0.0),
    default_streaming_llm=ChatAnthropic(temperature=0.0,streaming=True),
)

PromptTypes.AGENT_REASONING.llm = ChatAnthropic()

  File "/workspaces/langchain-decorators/src/test.py", line 6, in <module>
    from langchain_decorators import GlobalSettings
  File "/workspaces/langchain-decorators/src/langchain_decorators/__init__.py", line 1, in <module>
    from .common import LogColors, GlobalSettings, print_log, PromptTypes, PromptTypeSettings
  File "/workspaces/langchain-decorators/src/langchain_decorators/common.py", line 12, in <module>
    class GlobalSettings(BaseModel):
  File "/workspaces/langchain-decorators/src/langchain_decorators/common.py", line 27, in GlobalSettings
    default_llm=ChatOpenAI(temperature=0.0),
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for ChatOpenAI
__root__
  Did not find openai_api_key, please add an environment variable `OPENAI_API_KEY` which contains it, or pass  `openai_api_key` as a named parameter. (type=value_error)```
ju-bezdek commented 1 year ago

It looks correct to me... will look into it

ju-bezdek commented 1 year ago

Oh... obviously ... I put the ChatOpenAI as a default into the function declaration, so it initializes during import... I didn't realize that langchain validates this before invoking the LLM...

gonna fix it, it he meantime you can just define any OPENAI_API_KEY in your ENVs ... should work since you are overriding the default settings (your code is invoked later)

lukestanley commented 1 year ago

I have a fix. Sorting PR now.

lukestanley commented 1 year ago

It would be best to sort out the code formatting before so the diff is more obvious. Sorry I didn't split it into two commits! https://github.com/ju-bezdek/langchain-decorators/pull/3/files @ju-bezdek

lukestanley commented 1 year ago

I used Anthropic's big context window to look at your files to quickly suggest the fix: https://gist.github.com/lukestanley/ddfd48489ecb5bc97e4d2bca24ca229f ;)

ju-bezdek commented 1 year ago

That's super cool 🤣🚀 gonna review your PR now

ju-bezdek commented 1 year ago

fixed in v0.0.3