Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/litai/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,27 +452,28 @@ def if_(self, input: str, question: str) -> bool:
response = self.chat(prompt).strip().lower()
return "yes" in response

def classify(self, input: str, *choices: str) -> str:
"""Returns the label the model chooses from the given options.
def classify(self, input: str, choices: List[str]) -> str:
"""Returns the label the model chooses from the given list of options.

Example:
llm.classify("This product sucks.", "positive", "negative") → "negative"
llm.classify("This product sucks.", ["positive", "negative", "neutral"]) → "negative"
"""
normalized_choices = [c.strip().lower() for c in choices]
choices_str = ", ".join(normalized_choices)

prompt = f"""
You are given this input
You are given this input:
<input>
{input}
{input.strip()}
</input>

And the following choices:
<choices>
{choices_str}
</choices>

Answer with only one of the choices
"""
Answer with only one of the choices.
""".strip()

response = self.chat(prompt).strip().lower()

Expand Down
6 changes: 3 additions & 3 deletions tests/test_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,13 @@ def test_llm_classify_method(mock_sdkllm_class):
mock_sdkllm_instance.chat.side_effect = ["positive", "negative", "neutral"]

# Test simple classification
result = llm.classify("this movie was great!", "positive", "negative")
result = llm.classify("this movie was great!", ["positive", "negative"])
assert result == "positive"

# Test another classification
result = llm.classify("this movie was awful.", "positive", "negative")
result = llm.classify("this movie was awful.", ["positive", "negative"])
assert result == "negative"

# Test with multiple classes
result = llm.classify("it was okay.", "positive", "negative", "neutral")
result = llm.classify("it was okay.", ["positive", "negative", "neutral"])
assert result == "neutral"
Loading