ju-bezdek / langchain-decorators

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

parse BaseModel error #14

Open yuanjie-ai opened 7 months ago

yuanjie-ai commented 7 months ago
 from langchain_decorators import llm_prompt
  from pydantic import BaseModel, Field

  class TheOutputStructureWeExpect(BaseModel):
      name: str = Field(description="The name of the company")
      headline: str = Field(description="The description of the company (for landing page)")
      employees: list[str] = Field(description="5-8 fake employee names with their positions")

  @llm_prompt()
  def fake_company_generator(company_business: str) -> TheOutputStructureWeExpect:
      """ Generate a fake company that {company_business}
      {FORMAT_INSTRUCTIONS}
      """
      return

  company = fake_company_generator(company_business="sells cookies")

    # print the result nicely formatted
    print("Company name: ", company.name)
    print("company headline: ", company.headline)
    print("company employees: ", company.employees)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/py310/lib/python3.10/site-packages/langchain_decorators/prompt_decorator.py", line 501, in wrapper
    llmChain = build_chain(*args, **kwargs)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/py310/lib/python3.10/site-packages/langchain_decorators/prompt_decorator.py", line 246, in build_chain
    prompt_template = PromptDecoratorTemplate.from_func(
  File "/opt/homebrew/Caskroom/miniforge/base/envs/py310/lib/python3.10/site-packages/langchain_decorators/prompt_template.py", line 297, in from_func
    raise Exception(f"Unsupported return type {return_type}")
Exception: Unsupported return type <class '__main__.TheOutputStructureWeExpect'>
francescoagati commented 7 months ago

Also i have the same problem

ju-bezdek commented 7 months ago

i assume that you are already using pydantic v2

it was tricky to make it compatible with both versions so simple solution is just to do

from pydantic.v1 import BaseModel, Field

but that is not necessarily good solution for everyone