Skip to content

Add setup method for Tool's state initialization#20

Merged
williamFalcon merged 2 commits into
mainfrom
aniket/add-tool-setup
Jul 30, 2025
Merged

Add setup method for Tool's state initialization#20
williamFalcon merged 2 commits into
mainfrom
aniket/add-tool-setup

Conversation

@aniketmaurya
Copy link
Copy Markdown
Collaborator

@aniketmaurya aniketmaurya commented Jul 30, 2025

Before submitting
  • Was this discussed/agreed via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure to update the docs?
  • Did you write any new necessary tests?

What does this PR do?

from litai import LLM, LitTool

class FAQTool(LitTool):
-    def __init__(self):
-         super().__init__()
-         self.faq = ...
+    def setup(self):
        self.faq = {
            "pricing": "You can view our pricing plans on the website.",
            "support": "Our support team is available 24/7 via chat.",
            "refund": "Refunds are available within 30 days of purchase."
        }

    def run(self, question: str) -> str:
        keyword = question.lower()
        for topic, answer in self.faq.items():
            if topic in keyword:
                return answer
        return "Sorry, I couldn't find an answer for that."

tool = FAQTool()

llm = LLM(model="openai/gpt-4")
response = llm.chat("How do I get a refund?", tools=[tool])
result = llm.call_tool(response, tools=[tool])

print(result)  # → "Refunds are available within 30 days of purchase."
  • Changed the constructor of FAQTool to use a setup method for initialization.
  • Added a setup method to LitTool for state management.
  • Introduced a test for the setup method to ensure state initialization works correctly.

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in GitHub issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

- Changed the constructor of FAQTool to use a setup method for initialization.
- Added a setup method to LitTool for state management.
- Introduced a test for the setup method to ensure state initialization works correctly.
@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79%. Comparing base (ed2bb48) to head (3408c11).
⚠️ Report is 89 commits behind head on main.

Additional details and impacted files
@@        Coverage Diff         @@
##           main   #20   +/-   ##
==================================
+ Coverage    73%   79%   +6%     
==================================
  Files         6     6           
  Lines       294   333   +39     
==================================
+ Hits        215   262   +47     
+ Misses       79    71    -8     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@williamFalcon williamFalcon merged commit eb6bc3d into main Jul 30, 2025
46 of 48 checks passed
@williamFalcon williamFalcon deleted the aniket/add-tool-setup branch July 30, 2025 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants